diff --git a/share/qtcreator/gdbmacros/gdbmacros.cpp b/share/qtcreator/gdbmacros/gdbmacros.cpp index ae006133509..9784c8f657d 100644 --- a/share/qtcreator/gdbmacros/gdbmacros.cpp +++ b/share/qtcreator/gdbmacros/gdbmacros.cpp @@ -70,10 +70,6 @@ int qtGhVersion = QT_VERSION; #include #include -#ifdef Q_OS_WIN -# include -#endif - /*! \class QDumper \brief Helper class for producing "nice" output in Qt Creator's debugger. diff --git a/src/app/qtcreator.icns b/src/app/qtcreator.icns index 9d309e683e8..25241e22644 100644 Binary files a/src/app/qtcreator.icns and b/src/app/qtcreator.icns differ diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 01d4e13b4eb..491a9914ab9 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -176,7 +176,7 @@ QList LookupContext::resolve(Name *name, const QList &visible scopes.clear(); foreach (Symbol *candidate, candidates) { if (ScopedSymbol *scoped = candidate->asScopedSymbol()) { - expand(scoped->members(), visibleScopes, &scopes); + scopes.append(scoped->members()); } } } diff --git a/src/libs/cplusplus/Overview.cpp b/src/libs/cplusplus/Overview.cpp index 2494d11ec5e..0f973753d0b 100644 --- a/src/libs/cplusplus/Overview.cpp +++ b/src/libs/cplusplus/Overview.cpp @@ -68,6 +68,11 @@ bool Overview::showReturnTypes() const return _showReturnTypes; } +unsigned Overview::markArgument() const +{ + return _markArgument; +} + void Overview::setMarkArgument(unsigned position) { _markArgument = position; @@ -98,9 +103,5 @@ QString Overview::prettyType(const FullySpecifiedType &ty, const QString &name) const { TypePrettyPrinter pp(this); - pp.setMarkArgument(_markArgument); - pp.setShowArgumentNames(_showArgumentNames); - pp.setShowReturnTypes(_showReturnTypes); - pp.setShowFunctionSignatures(_showFunctionSignatures); return pp(ty, name); } diff --git a/src/libs/cplusplus/Overview.h b/src/libs/cplusplus/Overview.h index fa1f3cf919f..6918ee45ff8 100644 --- a/src/libs/cplusplus/Overview.h +++ b/src/libs/cplusplus/Overview.h @@ -57,7 +57,10 @@ public: bool showFunctionSignatures() const; void setShowFunctionSignatures(bool showFunctionSignatures); - void setMarkArgument(unsigned position); // 1-based + // 1-based + // ### rename + unsigned markArgument() const; + void setMarkArgument(unsigned position); QString operator()(Name *name) const { return prettyName(name); } diff --git a/src/libs/cplusplus/TypePrettyPrinter.cpp b/src/libs/cplusplus/TypePrettyPrinter.cpp index 6fd6a2cf245..6e46361b7f4 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.cpp +++ b/src/libs/cplusplus/TypePrettyPrinter.cpp @@ -42,37 +42,12 @@ using namespace CPlusPlus; TypePrettyPrinter::TypePrettyPrinter(const Overview *overview) : _overview(overview), - _name(0), - _markArgument(0), - _showArgumentNames(false), - _showReturnTypes(false), - _showFunctionSignatures(true) + _name(0) { } TypePrettyPrinter::~TypePrettyPrinter() { } -bool TypePrettyPrinter::showArgumentNames() const -{ return _showArgumentNames; } - -void TypePrettyPrinter::setShowArgumentNames(bool showArgumentNames) -{ _showArgumentNames = showArgumentNames; } - -bool TypePrettyPrinter::showReturnTypes() const -{ return _showReturnTypes; } - -void TypePrettyPrinter::setShowReturnTypes(bool showReturnTypes) -{ _showReturnTypes = showReturnTypes; } - -bool TypePrettyPrinter::showFunctionSignatures() const -{ return _showFunctionSignatures; } - -void TypePrettyPrinter::setShowFunctionSignatures(bool showFunctionSignatures) -{ _showFunctionSignatures = showFunctionSignatures; } - -void TypePrettyPrinter::setMarkArgument(unsigned position) -{ _markArgument = position; } - const Overview *TypePrettyPrinter::overview() const { return _overview; } @@ -102,15 +77,16 @@ QString TypePrettyPrinter::operator()(const FullySpecifiedType &type, const QStr void TypePrettyPrinter::acceptType(const FullySpecifiedType &ty) { - if (ty.isConst()) - _text += QLatin1String("const "); - if (ty.isVolatile()) - _text += QLatin1String("volatile "); if (ty.isSigned()) - _text += QLatin1String("signed "); - if (ty.isUnsigned()) - _text += QLatin1String("unsigned "); + out(QLatin1String("signed ")); + + else if (ty.isUnsigned()) + out(QLatin1String("unsigned ")); + + const FullySpecifiedType previousFullySpecifiedType = _fullySpecifiedType; + _fullySpecifiedType = ty; accept(ty.type()); + _fullySpecifiedType = previousFullySpecifiedType; } QString TypePrettyPrinter::switchName(const QString &name) @@ -127,9 +103,9 @@ QString TypePrettyPrinter::switchText(const QString &name) return previousName; } -QList TypePrettyPrinter::switchPtrOperators(const QList &ptrOperators) +QList TypePrettyPrinter::switchPtrOperators(const QList &ptrOperators) { - QList previousPtrOperators = _ptrOperators; + QList previousPtrOperators = _ptrOperators; _ptrOperators = ptrOperators; return previousPtrOperators; } @@ -137,31 +113,53 @@ QList TypePrettyPrinter::switchPtrOperators(const QList &ptrOper void TypePrettyPrinter::applyPtrOperators(bool wantSpace) { for (int i = _ptrOperators.size() - 1; i != -1; --i) { - Type *op = _ptrOperators.at(i); + const FullySpecifiedType op = _ptrOperators.at(i); if (i == 0 && wantSpace) - _text += QLatin1Char(' '); + space(); - if (PointerType *ptrTy = op->asPointerType()) { - _text += QLatin1Char('*'); - if (ptrTy->elementType().isConst()) - _text += " const"; - if (ptrTy->elementType().isVolatile()) - _text += " volatile"; + if (op->isPointerType()) { + out(QLatin1Char('*')); + outCV(op); } else if (op->isReferenceType()) { - _text += QLatin1Char('&'); - } else if (PointerToMemberType *memPtrTy = op->asPointerToMemberType()) { - _text += QLatin1Char(' '); - _text += _overview->prettyName(memPtrTy->memberName()); - _text += QLatin1Char('*'); + out(QLatin1Char('&')); + } else if (const PointerToMemberType *memPtrTy = op->asPointerToMemberType()) { + space(); + out(_overview->prettyName(memPtrTy->memberName())); + out(QLatin1Char('*')); + outCV(op); } } } void TypePrettyPrinter::visit(VoidType *) { - _text += QLatin1String("void"); + out(QLatin1String("void")); + applyPtrOperators(); +} +void TypePrettyPrinter::visit(NamedType *type) +{ + out(overview()->prettyName(type->name())); + applyPtrOperators(); +} + +void TypePrettyPrinter::visit(Namespace *type) +{ + _text += overview()->prettyName(type->name()); + applyPtrOperators(); +} + +void TypePrettyPrinter::visit(Class *type) +{ + _text += overview()->prettyName(type->name()); + applyPtrOperators(); +} + + +void TypePrettyPrinter::visit(Enum *type) +{ + _text += overview()->prettyName(type->name()); applyPtrOperators(); } @@ -169,25 +167,25 @@ void TypePrettyPrinter::visit(IntegerType *type) { switch (type->kind()) { case IntegerType::Char: - _text += QLatin1String("char"); + out(QLatin1String("char")); break; case IntegerType::WideChar: - _text += QLatin1String("wchar_t"); + out(QLatin1String("wchar_t")); break; case IntegerType::Bool: - _text += QLatin1String("bool"); + out(QLatin1String("bool")); break; case IntegerType::Short: - _text += QLatin1String("short"); + out(QLatin1String("short")); break; case IntegerType::Int: - _text += QLatin1String("int"); + out(QLatin1String("int")); break; case IntegerType::Long: - _text += QLatin1String("long"); + out(QLatin1String("long")); break; case IntegerType::LongLong: - _text += QLatin1String("long long"); + out(QLatin1String("long long")); break; } @@ -198,13 +196,13 @@ void TypePrettyPrinter::visit(FloatType *type) { switch (type->kind()) { case FloatType::Float: - _text += QLatin1String("float"); + out(QLatin1String("float")); break; case FloatType::Double: - _text += QLatin1String("double"); + out(QLatin1String("double")); break; case FloatType::LongDouble: - _text += QLatin1String("long double"); + out(QLatin1String("long double")); break; } @@ -213,99 +211,135 @@ void TypePrettyPrinter::visit(FloatType *type) void TypePrettyPrinter::visit(PointerToMemberType *type) { - _ptrOperators.append(type); + outCV(type->elementType()); + space(); + + _ptrOperators.append(_fullySpecifiedType); acceptType(type->elementType()); } void TypePrettyPrinter::visit(PointerType *type) { - _ptrOperators.append(type); + outCV(type->elementType()); + space(); + + _ptrOperators.append(_fullySpecifiedType); acceptType(type->elementType()); } void TypePrettyPrinter::visit(ReferenceType *type) { - _ptrOperators.append(type); + outCV(type->elementType()); + space(); + + _ptrOperators.append(_fullySpecifiedType); acceptType(type->elementType()); } void TypePrettyPrinter::visit(ArrayType *type) { - _text += overview()->prettyType(type->elementType()); + out(overview()->prettyType(type->elementType())); if (! _ptrOperators.isEmpty()) { - _text += QLatin1Char('('); + out(QLatin1Char('(')); applyPtrOperators(false); if (! _name.isEmpty()) { - _text += _name; + out(_name); _name.clear(); } - _text += QLatin1Char(')'); + out(QLatin1Char(')')); } - _text += QLatin1String("[]"); -} - -void TypePrettyPrinter::visit(NamedType *type) -{ - _text += overview()->prettyName(type->name()); - applyPtrOperators(); + out(QLatin1String("[]")); } void TypePrettyPrinter::visit(Function *type) { - if (_showReturnTypes) - _text += _overview->prettyType(type->returnType()); + if (_overview->showReturnTypes()) + out(_overview->prettyType(type->returnType())); if (! _ptrOperators.isEmpty()) { - _text += QLatin1Char('('); + out(QLatin1Char('(')); applyPtrOperators(false); if (! _name.isEmpty()) { _text += _name; _name.clear(); } - _text += QLatin1Char(')'); - } else if (! _name.isEmpty() && _showFunctionSignatures) { - _text += QLatin1Char(' '); // ### fixme - _text += _name; + out(QLatin1Char(')')); + } else if (! _name.isEmpty() && _overview->showFunctionSignatures()) { + space(); + out(_name); _name.clear(); } - if (_showFunctionSignatures) { + if (_overview->showFunctionSignatures()) { Overview argumentText; - _text += QLatin1Char('('); + argumentText.setShowReturnTypes(true); + argumentText.setShowArgumentNames(false); + argumentText.setShowFunctionSignatures(true); + + out(QLatin1Char('(')); + for (unsigned index = 0; index < type->argumentCount(); ++index) { if (index != 0) - _text += QLatin1String(", "); + out(QLatin1String(", ")); if (Argument *arg = type->argumentAt(index)->asArgument()) { - if (index + 1 == _markArgument) - _text += QLatin1String(""); + if (index + 1 == _overview->markArgument()) + out(QLatin1String("")); + Name *name = 0; - if (_showArgumentNames) + + if (_overview->showArgumentNames()) name = arg->name(); - _text += argumentText(arg->type(), name); - if (index + 1 == _markArgument) - _text += QLatin1String(""); + + out(argumentText(arg->type(), name)); + + if (index + 1 == _overview->markArgument()) + out(QLatin1String("")); } } if (type->isVariadic()) - _text += QLatin1String("..."); + out(QLatin1String("...")); - _text += QLatin1Char(')'); - - if (type->isConst()) - _text += QLatin1String(" const"); - - if (type->isVolatile()) - _text += QLatin1String(" volatile"); + out(QLatin1Char(')')); + if (type->isConst() && type->isVolatile()) { + space(); + out("const volatile"); + } else if (type->isConst()) { + space(); + out("const"); + } else if (type->isVolatile()) { + space(); + out("volatile"); + } } } -void TypePrettyPrinter::visit(Namespace *type) -{ _text += overview()->prettyName(type->name()); } +void TypePrettyPrinter::space() +{ + if (_text.isEmpty()) + return; -void TypePrettyPrinter::visit(Class *type) -{ _text += overview()->prettyName(type->name()); } + const QChar ch = _text.at(_text.length() - 1); -void TypePrettyPrinter::visit(Enum *type) -{ _text += overview()->prettyName(type->name()); } + if (ch.isLetterOrNumber() || ch == QLatin1Char('_') || ch == QLatin1Char(')')) + _text += QLatin1Char(' '); +} + +void TypePrettyPrinter::out(const QString &text) +{ _text += text; } + +void TypePrettyPrinter::out(const QChar &ch) +{ _text += ch; } + +void TypePrettyPrinter::outCV(const FullySpecifiedType &ty) +{ + if (ty.isConst() && ty.isVolatile()) + out(QLatin1String("const volatile")); + + else if (ty.isConst()) + out(QLatin1String("const")); + + else if (ty.isVolatile()) + out(QLatin1String("volatile")); +} diff --git a/src/libs/cplusplus/TypePrettyPrinter.h b/src/libs/cplusplus/TypePrettyPrinter.h index 790999dc824..6191cf01af0 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.h +++ b/src/libs/cplusplus/TypePrettyPrinter.h @@ -33,7 +33,8 @@ #ifndef TYPEPRETTYPRINTER_H #define TYPEPRETTYPRINTER_H -#include "TypeVisitor.h" +#include +#include #include #include @@ -50,23 +51,12 @@ public: const Overview *overview() const; - bool showArgumentNames() const; - void setShowArgumentNames(bool showArgumentNames); - - bool showReturnTypes() const; - void setShowReturnTypes(bool showReturnTypes); - - bool showFunctionSignatures() const; - void setShowFunctionSignatures(bool showFunctionSignatures); - - void setMarkArgument(unsigned position); // 1-based - QString operator()(const FullySpecifiedType &type); QString operator()(const FullySpecifiedType &type, const QString &name); protected: QString switchText(const QString &text = QString()); - QList switchPtrOperators(const QList &ptrOperators); + QList switchPtrOperators(const QList &ptrOperators); QString switchName(const QString &name); void applyPtrOperators(bool wantSpace = true); @@ -85,15 +75,17 @@ protected: virtual void visit(Class *type); virtual void visit(Enum *type); + void space(); + void out(const QString &text); + void out(const QChar &ch); + void outCV(const FullySpecifiedType &ty); + private: const Overview *_overview; QString _name; QString _text; - QList _ptrOperators; - unsigned _markArgument; - bool _showArgumentNames: 1; - bool _showReturnTypes: 1; - bool _showFunctionSignatures: 1; + FullySpecifiedType _fullySpecifiedType; + QList _ptrOperators; }; } // end of namespace CPlusPlus diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index 5a1c8a00e6a..2900f0437d3 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -39,7 +39,6 @@ #include "iplugin.h" #include -#include #include #include #include diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h index d8a61e6e802..3a8dda54aa7 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h @@ -71,14 +71,14 @@ class CMakeRunner { public: CMakeRunner(); - void run(QFutureInterface &fi); void setExecutable(const QString &executable); QString executable() const; QString version() const; bool supportsQtCreator() const; - void waitForUpToDate() const; private: + void run(QFutureInterface &fi); + void waitForUpToDate() const; QString m_executable; QString m_version; bool m_supportsQtCreator; diff --git a/src/plugins/coreplugin/editormanager/stackededitorgroup.cpp b/src/plugins/coreplugin/editormanager/stackededitorgroup.cpp index cc759c6c7ff..7ad5d056fe5 100644 --- a/src/plugins/coreplugin/editormanager/stackededitorgroup.cpp +++ b/src/plugins/coreplugin/editormanager/stackededitorgroup.cpp @@ -329,8 +329,8 @@ void StackedEditorGroup::updateToolBar(IEditor *editor) toolBar = m_defaultToolBar; if (m_activeToolBar == toolBar) return; - toolBar->setVisible(true); m_activeToolBar->setVisible(false); + toolBar->setVisible(true); m_activeToolBar = toolBar; } diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp index f0cda5147c2..82a8be37d72 100644 --- a/src/plugins/cpaster/cpasterplugin.cpp +++ b/src/plugins/cpaster/cpasterplugin.cpp @@ -185,7 +185,9 @@ void CodepasterPlugin::post() // Submit to codepaster - m_poster = new CustomPoster(serverUrl()); + m_poster = new CustomPoster(serverUrl(), + m_settingsPage->copyToClipBoard(), + m_settingsPage->displayOutput()); // Copied from cpaster. Otherwise lineendings will screw up if (!data.contains("\r\n")) { diff --git a/src/plugins/cpaster/settingspage.h b/src/plugins/cpaster/settingspage.h index a492030752c..98df299a5f6 100644 --- a/src/plugins/cpaster/settingspage.h +++ b/src/plugins/cpaster/settingspage.h @@ -65,8 +65,8 @@ public: QString username() const; QUrl serverUrl() const; - bool copyToClipBoard() const; - bool displayOutput() const; + inline bool copyToClipBoard() const { return m_copy; } + inline bool displayOutput() const { return m_output; } private: Ui_SettingsPage m_ui; diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index bca1d576e9f..233398026fe 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -78,7 +78,7 @@ class FunctionArgumentWidget : public QLabel { public: FunctionArgumentWidget(); - void showFunctionHint(Function *functionSymbol, const Snapshot &snapshot); + void showFunctionHint(Function *functionSymbol, const LookupContext &context); protected: bool eventFilter(QObject *obj, QEvent *e); @@ -95,7 +95,7 @@ private: QFrame *m_popupFrame; Function *m_item; - Snapshot m_snapshot; + LookupContext m_context; }; class ConvertToCompletionItem: protected NameVisitor @@ -187,10 +187,10 @@ using namespace CppTools::Internal; FunctionArgumentWidget::FunctionArgumentWidget() : m_item(0) { - QObject *editorObject = Core::ICore::instance()->editorManager()->currentEditor(); + QObject *editorObject = Core::EditorManager::instance()->currentEditor(); m_editor = qobject_cast(editorObject); - m_popupFrame = new QFrame(0, Qt::ToolTip|Qt::WindowStaysOnTopHint); + m_popupFrame = new QFrame(0, Qt::ToolTip | Qt::WindowStaysOnTopHint); m_popupFrame->setFocusPolicy(Qt::NoFocus); m_popupFrame->setAttribute(Qt::WA_DeleteOnClose); @@ -215,10 +215,12 @@ FunctionArgumentWidget::FunctionArgumentWidget() } void FunctionArgumentWidget::showFunctionHint(Function *functionSymbol, - const Snapshot &snapshot) + const LookupContext &context) { + m_popupFrame->hide(); + m_item = functionSymbol; - m_snapshot = snapshot; + m_context = context; m_startpos = m_editor->position(); // update the text @@ -230,7 +232,7 @@ void FunctionArgumentWidget::showFunctionHint(Function *functionSymbol, m_popupFrame->move(pos); m_popupFrame->show(); - QCoreApplication::instance()->installEventFilter(this); + qApp->installEventFilter(this); } void FunctionArgumentWidget::update() @@ -432,7 +434,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) return -1; m_editor = editor; - m_startPosition = findStartOfName(editor); + m_startPosition = findStartOfName(); m_completionOperator = T_EOF_SYMBOL; int endOfOperator = m_startPosition; @@ -518,9 +520,9 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) if (exprTy->isReferenceType()) exprTy = exprTy->asReferenceType()->elementType(); - if (m_completionOperator == T_LPAREN && completeFunction(exprTy, resolvedTypes, context)) { + if (m_completionOperator == T_LPAREN && completeConstructorOrFunction(exprTy, resolvedTypes)) { return m_startPosition; - } if ((m_completionOperator == T_DOT || m_completionOperator == T_ARROW) && + } else if ((m_completionOperator == T_DOT || m_completionOperator == T_ARROW) && completeMember(resolvedTypes, context)) { return m_startPosition; } else if (m_completionOperator == T_COLON_COLON && completeScope(resolvedTypes, context)) { @@ -531,15 +533,40 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) return m_startPosition; } } + + if (m_completionOperator == T_LPAREN) { + // Find the expression that precedes the current name + int index = endOfExpression; + while (m_editor->characterAt(index - 1).isSpace()) + --index; + index = findStartOfName(index); + + QTextCursor tc(edit->document()); + tc.setPosition(index); + QString baseExpression = expressionUnderCursor(tc); + + // Resolve the type of this expression + QList results = + typeOfExpression(baseExpression, thisDocument, symbol, TypeOfExpression::Preprocess); + + // If it's a class, add completions for the constructors + foreach (const TypeOfExpression::Result &result, results) { + if (result.first->isClass()) { + FullySpecifiedType exprTy = result.first; + if (completeConstructorOrFunction(exprTy, QList())) + return m_startPosition; + break; + } + } + } } // nothing to do. return -1; } -bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy, - const QList &resolvedTypes, - const LookupContext &) +bool CppCodeCompletion::completeConstructorOrFunction(FullySpecifiedType exprTy, + const QList &resolvedTypes) { ConvertToCompletionItem toCompletionItem(this); Overview o; @@ -580,6 +607,10 @@ bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy, } } + // If there is only one item, show the function argument widget immediately + if (m_completions.size() == 1) + complete(m_completions.takeFirst()); + return ! m_completions.isEmpty(); } @@ -790,33 +821,45 @@ void CppCodeCompletion::addKeywords() void CppCodeCompletion::addMacros(const LookupContext &context) { - // macro completion items. - QSet macroNames; QSet processed; - QList todo; - todo.append(context.thisDocument()->fileName()); - while (! todo.isEmpty()) { - QString fn = todo.last(); - todo.removeLast(); - if (processed.contains(fn)) - continue; - processed.insert(fn); - if (Document::Ptr doc = context.document(fn)) { - foreach (const Macro ¯o, doc->definedMacros()) { - macroNames.insert(macro.name()); - } - todo += doc->includedFiles(); - } - } + QSet definedMacros; - foreach (const QByteArray ¯oName, macroNames) { + addMacros_helper(context, context.thisDocument()->fileName(), + &processed, &definedMacros); + + foreach (const QString ¯oName, definedMacros) { TextEditor::CompletionItem item(this); - item.m_text = QString::fromUtf8(macroName.constData(), macroName.length()); + item.m_text = macroName; item.m_icon = m_icons.macroIcon(); m_completions.append(item); } } +void CppCodeCompletion::addMacros_helper(const LookupContext &context, + const QString &fileName, + QSet *processed, + QSet *definedMacros) +{ + Document::Ptr doc = context.document(fileName); + + if (! doc || processed->contains(doc->fileName())) + return; + + processed->insert(doc->fileName()); + + foreach (const Document::Include &i, doc->includes()) { + addMacros_helper(context, i.fileName(), processed, definedMacros); + } + + foreach (const Macro ¯o, doc->definedMacros()) { + const QString macroName = QString::fromUtf8(macro.name().constData(), macro.name().length()); + if (! macro.isHidden()) + definedMacros->insert(macroName); + else + definedMacros->remove(macroName); + } +} + void CppCodeCompletion::addCompletionItem(Symbol *symbol) { ConvertToCompletionItem toCompletionItem(this); @@ -1040,8 +1083,11 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) Function *function = symbol->type()->asFunction(); QTC_ASSERT(function, return); - m_functionArgumentWidget = new FunctionArgumentWidget(); - m_functionArgumentWidget->showFunctionHint(function, typeOfExpression.snapshot()); + // Recreate if necessary + if (!m_functionArgumentWidget) + m_functionArgumentWidget = new FunctionArgumentWidget; + + m_functionArgumentWidget->showFunctionHint(function, typeOfExpression.lookupContext()); } } else if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) { QString toInsert = item.m_text; @@ -1052,11 +1098,14 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) m_editor->replace(length, toInsert); } else { QString toInsert = item.m_text; + int extraLength = 0; //qDebug() << "current symbol:" << overview.prettyName(symbol->name()) //<< overview.prettyType(symbol->type()); if (m_autoInsertBraces && symbol) { + QString extraChars; + if (Function *function = symbol->type()->asFunction()) { // If the member is a function, automatically place the opening parenthesis, // except when it might take template parameters. @@ -1069,28 +1118,40 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) } else if (function->templateParameterCount() != 0) { // If there are no arguments, then we need the template specification if (function->argumentCount() == 0) { - toInsert.append(QLatin1Char('<')); + extraChars += QLatin1Char('<'); } } else { - toInsert.append(QLatin1Char('(')); + extraChars += QLatin1Char('('); // If the function takes no arguments, automatically place the closing parenthesis if (function->argumentCount() == 0 || (function->argumentCount() == 1 && function->argumentAt(0)->type()->isVoidType())) { - toInsert.append(QLatin1Char(')')); + extraChars += QLatin1Char(')'); // If the function doesn't return anything, automatically place the semicolon, // unless we're doing a scope completion (then it might be function definition). if (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON) { - toInsert.append(QLatin1Char(';')); + extraChars += QLatin1Char(';'); } } } } + + // Avoid inserting characters that are already there + for (int i = 0; i < extraChars.length(); ++i) { + const QChar a = extraChars.at(i); + const QChar b = m_editor->characterAt(m_editor->position() + i); + if (a == b) + ++extraLength; + else + break; + } + + toInsert += extraChars; } // Insert the remainder of the name - int length = m_editor->position() - m_startPosition; + int length = m_editor->position() - m_startPosition + extraLength; m_editor->setCurPos(m_startPosition); m_editor->replace(length, toInsert); } @@ -1135,14 +1196,15 @@ void CppCodeCompletion::cleanup() typeOfExpression.setSnapshot(Snapshot()); } -int CppCodeCompletion::findStartOfName(const TextEditor::ITextEditor *editor) +int CppCodeCompletion::findStartOfName(int pos) const { - int pos = editor->position(); + if (pos == -1) + pos = m_editor->position(); QChar chr; // Skip to the start of a name do { - chr = editor->characterAt(--pos); + chr = m_editor->characterAt(--pos); } while (chr.isLetterOrNumber() || chr == QLatin1Char('_')); return pos + 1; diff --git a/src/plugins/cpptools/cppcodecompletion.h b/src/plugins/cpptools/cppcodecompletion.h index 08a767ea6ce..3c1be57bd5d 100644 --- a/src/plugins/cpptools/cppcodecompletion.h +++ b/src/plugins/cpptools/cppcodecompletion.h @@ -84,11 +84,14 @@ public: private: void addKeywords(); void addMacros(const CPlusPlus::LookupContext &context); + void addMacros_helper(const CPlusPlus::LookupContext &context, + const QString &fileName, + QSet *processed, + QSet *definedMacros); void addCompletionItem(CPlusPlus::Symbol *symbol); - bool completeFunction(CPlusPlus::FullySpecifiedType exprTy, - const QList &, - const CPlusPlus::LookupContext &context); + bool completeConstructorOrFunction(CPlusPlus::FullySpecifiedType exprTy, + const QList &); bool completeMember(const QList &, const CPlusPlus::LookupContext &context); @@ -103,6 +106,8 @@ private: const CPlusPlus::LookupContext &context, bool staticLookup = true); + bool completeConstructors(CPlusPlus::Class *klass); + bool completeQtMethod(CPlusPlus::FullySpecifiedType exprTy, const QList &, const CPlusPlus::LookupContext &context, @@ -118,7 +123,7 @@ private: const CPlusPlus::LookupContext &context) { return completeQtMethod(exprTy, results, context, false); } - static int findStartOfName(const TextEditor::ITextEditor *editor); + int findStartOfName(int pos = -1) const; QList m_completions; diff --git a/src/plugins/debugger/debugger.pro b/src/plugins/debugger/debugger.pro index 469ea346011..0578a52720b 100644 --- a/src/plugins/debugger/debugger.pro +++ b/src/plugins/debugger/debugger.pro @@ -37,6 +37,7 @@ HEADERS += attachexternaldialog.h \ scriptengine.h \ stackhandler.h \ stackwindow.h \ + sourcefileswindow.h \ startexternaldialog.h \ threadswindow.h \ watchhandler.h \ @@ -64,6 +65,7 @@ SOURCES += attachexternaldialog.cpp \ scriptengine.cpp \ stackhandler.cpp \ stackwindow.cpp \ + sourcefileswindow.cpp \ startexternaldialog.cpp \ threadswindow.cpp \ watchhandler.cpp \ diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 423321fc7ba..0bc4b47c5c3 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -33,7 +33,6 @@ #include "debuggermanager.h" -#include "assert.h" #include "debuggerconstants.h" #include "idebuggerengine.h" @@ -43,6 +42,7 @@ #include "moduleswindow.h" #include "registerwindow.h" #include "stackwindow.h" +#include "sourcefileswindow.h" #include "threadswindow.h" #include "watchwindow.h" @@ -58,6 +58,8 @@ #include "startexternaldialog.h" #include "attachexternaldialog.h" +#include + #include #include #include @@ -151,7 +153,7 @@ void DebuggerManager::init() m_busy = false; m_attachedPID = 0; - m_startMode = startInternal; + m_startMode = StartInternal; m_disassemblerHandler = 0; m_modulesHandler = 0; @@ -164,6 +166,7 @@ void DebuggerManager::init() m_outputWindow = new DebuggerOutputWindow; m_registerWindow = new RegisterWindow; m_stackWindow = new StackWindow; + m_sourceFilesWindow = new SourceFilesWindow; m_threadsWindow = new ThreadsWindow; m_localsWindow = new WatchWindow(WatchWindow::LocalsType); m_watchersWindow = new WatchWindow(WatchWindow::WatchersType); @@ -226,6 +229,13 @@ void DebuggerManager::init() connect(modulesView, SIGNAL(loadAllSymbolsRequested()), this, SLOT(loadAllSymbols())); + // Source Files + //m_sourceFilesHandler = new SourceFilesHandler; + QAbstractItemView *sourceFilesView = + qobject_cast(m_sourceFilesWindow); + //sourceFileView->setModel(m_stackHandler->stackModel()); + connect(sourceFilesView, SIGNAL(reloadSourceFilesRequested()), + this, SLOT(reloadSourceFiles())); // Registers QAbstractItemView *registerView = @@ -402,6 +412,10 @@ void DebuggerManager::init() m_stackDock = createDockForWidget(m_stackWindow); + m_sourceFilesDock = createDockForWidget(m_sourceFilesWindow); + connect(m_sourceFilesDock->toggleViewAction(), SIGNAL(toggled(bool)), + this, SLOT(reloadSourceFiles()), Qt::QueuedConnection); + m_threadsDock = createDockForWidget(m_threadsWindow); setStatus(DebuggerProcessNotReady); @@ -451,10 +465,7 @@ QDockWidget *DebuggerManager::createDockForWidget(QWidget *widget) { QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), m_mainWindow); dockWidget->setObjectName(widget->windowTitle()); - //dockWidget->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::RightDockWidgetArea); - dockWidget->setAllowedAreas(Qt::AllDockWidgetAreas); // that space is needed. - //dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); - dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); + dockWidget->setFeatures(QDockWidget::DockWidgetClosable); dockWidget->setTitleBarWidget(new QWidget(dockWidget)); dockWidget->setWidget(widget); connect(dockWidget->toggleViewAction(), SIGNAL(toggled(bool)), @@ -479,9 +490,11 @@ void DebuggerManager::setSimpleDockWidgetArrangement() m_mainWindow->tabifyDockWidget(m_watchDock, m_outputDock); m_mainWindow->tabifyDockWidget(m_watchDock, m_registerDock); m_mainWindow->tabifyDockWidget(m_watchDock, m_threadsDock); + m_mainWindow->tabifyDockWidget(m_watchDock, m_sourceFilesDock); // They are rarely used even in ordinary debugging. Hiding them also saves // cycles since the corresponding information won't be retrieved. + m_sourceFilesDock->hide(); m_registerDock->hide(); m_disassemblerDock->hide(); m_modulesDock->hide(); @@ -491,7 +504,7 @@ void DebuggerManager::setSimpleDockWidgetArrangement() void DebuggerManager::setLocked(bool locked) { const QDockWidget::DockWidgetFeatures features = - (locked) ? QDockWidget::NoDockWidgetFeatures : + (locked) ? QDockWidget::DockWidgetClosable : QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable; foreach (QDockWidget *dockWidget, m_dockWidgets) { @@ -539,16 +552,10 @@ void DebuggerManager::showStatusMessage(const QString &msg, int timeout) } } -void DebuggerManager::notifyStartupFinished() +void DebuggerManager::notifyInferiorStopRequested() { - setStatus(DebuggerProcessReady); - showStatusMessage(tr("Startup finished. Debugger ready."), -1); - if (m_startMode == attachExternal) { - // we continue the execution - engine()->continueInferior(); - } else { - engine()->runInferior(); - } + setStatus(DebuggerInferiorStopRequested); + showStatusMessage(tr("Stop requested..."), 5000); } void DebuggerManager::notifyInferiorStopped() @@ -558,16 +565,10 @@ void DebuggerManager::notifyInferiorStopped() showStatusMessage(tr("Stopped."), 5000); } -void DebuggerManager::notifyInferiorUpdateFinished() -{ - setStatus(DebuggerInferiorReady); - showStatusMessage(tr("Stopped."), 5000); -} - void DebuggerManager::notifyInferiorRunningRequested() { setStatus(DebuggerInferiorRunningRequested); - showStatusMessage(tr("Running..."), 5000); + showStatusMessage(tr("Running requested..."), 5000); } void DebuggerManager::notifyInferiorRunning() @@ -578,7 +579,7 @@ void DebuggerManager::notifyInferiorRunning() void DebuggerManager::notifyInferiorExited() { - setStatus(DebuggerProcessReady); + setStatus(DebuggerProcessNotReady); showStatusMessage(tr("Stopped."), 5000); } @@ -597,7 +598,19 @@ void DebuggerManager::showApplicationOutput(const QString &str) void DebuggerManager::shutdown() { //qDebug() << "DEBUGGER_MANAGER SHUTDOWN START"; - engine()->shutdown(); + if (m_engine) { + //qDebug() << "SHUTTING DOWN ENGINE" << m_engine; + m_engine->shutdown(); + } + m_engine = 0; + + delete scriptEngine; + scriptEngine = 0; + delete gdbEngine; + gdbEngine = 0; + delete winEngine; + winEngine = 0; + // Delete these manually before deleting the manager // (who will delete the models for most views) delete m_breakWindow; @@ -651,41 +664,57 @@ void DebuggerManager::toggleBreakpoint() void DebuggerManager::toggleBreakpoint(const QString &fileName, int lineNumber) { + QTC_ASSERT(m_engine, return); + QTC_ASSERT(m_breakHandler, return); + if (status() != DebuggerInferiorRunning + && status() != DebuggerInferiorStopped + && status() != DebuggerProcessNotReady) { + showStatusMessage(tr("Changing breakpoint state requires either a " + "fully running or fully stopped application.")); + return; + } + int index = m_breakHandler->indexOf(fileName, lineNumber); if (index == -1) - breakHandler()->setBreakpoint(fileName, lineNumber); + m_breakHandler->setBreakpoint(fileName, lineNumber); else - breakHandler()->removeBreakpoint(index); - engine()->attemptBreakpointSynchronization(); + m_breakHandler->removeBreakpoint(index); + m_engine->attemptBreakpointSynchronization(); } void DebuggerManager::setToolTipExpression(const QPoint &pos, const QString &exp) { - engine()->setToolTipExpression(pos, exp); + QTC_ASSERT(m_engine, return); + m_engine->setToolTipExpression(pos, exp); } void DebuggerManager::updateWatchModel() { - engine()->updateWatchModel(); + QTC_ASSERT(m_engine, return); + m_engine->updateWatchModel(); } void DebuggerManager::expandChildren(const QModelIndex &idx) { - watchHandler()->expandChildren(idx); + QTC_ASSERT(m_watchHandler, return); + m_watchHandler->expandChildren(idx); } void DebuggerManager::collapseChildren(const QModelIndex &idx) { - watchHandler()->collapseChildren(idx); + QTC_ASSERT(m_watchHandler, return); + m_watchHandler->collapseChildren(idx); } void DebuggerManager::removeWatchExpression(const QString &exp) { - watchHandler()->removeWatchExpression(exp); + QTC_ASSERT(m_watchHandler, return); + m_watchHandler->removeWatchExpression(exp); } QVariant DebuggerManager::sessionValue(const QString &name) { + // this is answered by the plugin QVariant value; emit sessionValueRequested(name, &value); return value; @@ -693,16 +722,19 @@ QVariant DebuggerManager::sessionValue(const QString &name) void DebuggerManager::querySessionValue(const QString &name, QVariant *value) { + // this is answered by the plugin emit sessionValueRequested(name, value); } void DebuggerManager::setSessionValue(const QString &name, const QVariant &value) { + // this is answered by the plugin emit setSessionValueRequested(name, value); } QVariant DebuggerManager::configValue(const QString &name) { + // this is answered by the plugin QVariant value; emit configValueRequested(name, &value); return value; @@ -710,23 +742,25 @@ QVariant DebuggerManager::configValue(const QString &name) void DebuggerManager::queryConfigValue(const QString &name, QVariant *value) { + // this is answered by the plugin emit configValueRequested(name, value); } void DebuggerManager::setConfigValue(const QString &name, const QVariant &value) { + // this is answered by the plugin emit setConfigValueRequested(name, value); } void DebuggerManager::startExternalApplication() { - if (!startNewDebugger(startExternal)) + if (!startNewDebugger(StartExternal)) emit debuggingFinished(); } void DebuggerManager::attachExternalApplication() { - if (!startNewDebugger(attachExternal)) + if (!startNewDebugger(AttachExternal)) emit debuggingFinished(); } @@ -735,7 +769,7 @@ bool DebuggerManager::startNewDebugger(StartMode mode) m_startMode = mode; // FIXME: Clean up - if (startMode() == startExternal) { + if (startMode() == StartExternal) { StartExternalDialog dlg(mainWindow()); dlg.setExecutableFile( configValue(QLatin1String("LastExternalExecutableFile")).toString()); @@ -751,7 +785,7 @@ bool DebuggerManager::startNewDebugger(StartMode mode) m_processArgs = dlg.executableArguments().split(' '); m_workingDir = QString(); m_attachedPID = -1; - } else if (startMode() == attachExternal) { + } else if (startMode() == AttachExternal) { AttachExternalDialog dlg(mainWindow()); if (dlg.exec() != QDialog::Accepted) return false; @@ -764,7 +798,7 @@ bool DebuggerManager::startNewDebugger(StartMode mode) tr("Cannot attach to PID 0")); return false; } - } else if (startMode() == startInternal) { + } else if (startMode() == StartInternal) { if (m_executable.isEmpty()) { QString startDirectory = m_executable; if (m_executable.isEmpty()) { @@ -797,11 +831,13 @@ bool DebuggerManager::startNewDebugger(StartMode mode) else setDebuggerType(GdbDebugger); - if (!engine()->startDebugger()) + setStatus(DebuggerProcessStartingUp); + if (!m_engine->startDebugger()) { + setStatus(DebuggerProcessNotReady); return false; + } m_busy = false; - setStatus(DebuggerProcessStartingUp); return true; } @@ -818,7 +854,9 @@ void DebuggerManager::cleanupViews() void DebuggerManager::exitDebugger() { - engine()->exitDebugger(); + //qDebug() << "DebuggerManager::exitDebugger"; + if (m_engine) + m_engine->exitDebugger(); cleanupViews(); setStatus(DebuggerProcessNotReady); setBusyCursor(false); @@ -827,62 +865,73 @@ void DebuggerManager::exitDebugger() void DebuggerManager::assignValueInDebugger(const QString &expr, const QString &value) { - engine()->assignValueInDebugger(expr, value); + QTC_ASSERT(m_engine, return); + m_engine->assignValueInDebugger(expr, value); } void DebuggerManager::activateFrame(int index) { - engine()->activateFrame(index); + QTC_ASSERT(m_engine, return); + m_engine->activateFrame(index); } void DebuggerManager::selectThread(int index) { - engine()->selectThread(index); + QTC_ASSERT(m_engine, return); + m_engine->selectThread(index); } void DebuggerManager::loadAllSymbols() { - engine()->loadAllSymbols(); + QTC_ASSERT(m_engine, return); + m_engine->loadAllSymbols(); } void DebuggerManager::loadSymbols(const QString &module) { - engine()->loadSymbols(module); + QTC_ASSERT(m_engine, return); + m_engine->loadSymbols(module); } void DebuggerManager::stepExec() { + QTC_ASSERT(m_engine, return); resetLocation(); - engine()->stepExec(); + m_engine->stepExec(); } void DebuggerManager::stepOutExec() { + QTC_ASSERT(m_engine, return); resetLocation(); - engine()->stepOutExec(); + m_engine->stepOutExec(); } void DebuggerManager::nextExec() { + QTC_ASSERT(m_engine, return); resetLocation(); - engine()->nextExec(); + m_engine->nextExec(); } void DebuggerManager::stepIExec() { + QTC_ASSERT(m_engine, return); resetLocation(); - engine()->stepIExec(); + m_engine->stepIExec(); } void DebuggerManager::nextIExec() { + QTC_ASSERT(m_engine, return); resetLocation(); - engine()->nextIExec(); + m_engine->nextIExec(); } void DebuggerManager::executeDebuggerCommand(const QString &command) { - engine()->executeDebuggerCommand(command); + QTC_ASSERT(m_engine, return); + m_engine->executeDebuggerCommand(command); } void DebuggerManager::sessionLoaded() @@ -900,16 +949,18 @@ void DebuggerManager::aboutToSaveSession() void DebuggerManager::loadSessionData() { + QTC_ASSERT(m_engine, return); m_breakHandler->loadSessionData(); m_watchHandler->loadSessionData(); - engine()->loadSessionData(); + m_engine->loadSessionData(); } void DebuggerManager::saveSessionData() { + QTC_ASSERT(m_engine, return); m_breakHandler->saveSessionData(); m_watchHandler->saveSessionData(); - engine()->saveSessionData(); + m_engine->saveSessionData(); } void DebuggerManager::dumpLog() @@ -927,33 +978,6 @@ void DebuggerManager::dumpLog() ts << m_outputWindow->combinedContents(); } -#if 0 -// call after m_gdbProc exited. -void GdbEngine::procFinished() -{ - //qDebug() << "GDB PROCESS FINISHED"; - setStatus(DebuggerProcessNotReady); - showStatusMessage(tr("Done"), 5000); - q->m_breakHandler->procFinished(); - q->m_watchHandler->cleanup(); - m_stackHandler->m_stackFrames.clear(); - m_stackHandler->resetModel(); - m_threadsHandler->resetModel(); - if (q->m_modulesHandler) - q->m_modulesHandler->procFinished(); - q->resetLocation(); - setStatus(DebuggerProcessNotReady); - emit q->previousModeRequested(); - emit q->debuggingFinished(); - //exitDebugger(); - //showStatusMessage("Gdb killed"); - m_shortToFullName.clear(); - m_fullToShortName.clear(); - m_shared = 0; - q->m_busy = false; -} -#endif - void DebuggerManager::addToWatchWindow() { // requires a selection, but that's the only case we want... @@ -968,19 +992,24 @@ void DebuggerManager::addToWatchWindow() void DebuggerManager::watchExpression(const QString &expression) { - watchHandler()->watchExpression(expression); + QTC_ASSERT(m_watchHandler, return); + m_watchHandler->watchExpression(expression); } void DebuggerManager::setBreakpoint(const QString &fileName, int lineNumber) { - breakHandler()->setBreakpoint(fileName, lineNumber); - engine()->attemptBreakpointSynchronization(); + QTC_ASSERT(m_breakHandler, return); + QTC_ASSERT(m_engine, return); + m_breakHandler->setBreakpoint(fileName, lineNumber); + m_engine->attemptBreakpointSynchronization(); } void DebuggerManager::breakByFunction(const QString &functionName) { - breakHandler()->breakByFunction(functionName); - engine()->attemptBreakpointSynchronization(); + QTC_ASSERT(m_breakHandler, return); + QTC_ASSERT(m_engine, return); + m_breakHandler->breakByFunction(functionName); + m_engine->attemptBreakpointSynchronization(); } void DebuggerManager::breakByFunction() @@ -1011,16 +1040,11 @@ void DebuggerManager::setStatus(int status) const bool started = status == DebuggerInferiorRunning || status == DebuggerInferiorRunningRequested || status == DebuggerInferiorStopRequested - || status == DebuggerInferiorStopped - || status == DebuggerInferiorUpdating - || status == DebuggerInferiorUpdateFinishing - || status == DebuggerInferiorReady; + || status == DebuggerInferiorStopped; const bool starting = status == DebuggerProcessStartingUp; const bool running = status == DebuggerInferiorRunning; - const bool ready = status == DebuggerInferiorStopped - || status == DebuggerInferiorReady - || status == DebuggerProcessReady; + const bool ready = status == DebuggerInferiorStopped; m_startExternalAction->setEnabled(!started && !starting); m_attachExternalAction->setEnabled(!started && !starting); @@ -1088,26 +1112,18 @@ bool DebuggerManager::useCustomDumpers() const return m_settings.m_useCustomDumpers; } -bool DebuggerManager::useFastStart() const -{ - return 0; // && m_settings.m_useFastStart; -} - void DebuggerManager::setUseCustomDumpers(bool on) { + QTC_ASSERT(m_engine, return); m_settings.m_useCustomDumpers = on; - engine()->setUseCustomDumpers(on); -} - -void DebuggerManager::setUseFastStart(bool on) -{ - m_settings.m_useFastStart = on; + m_engine->setUseCustomDumpers(on); } void DebuggerManager::setDebugDumpers(bool on) { + QTC_ASSERT(m_engine, return); m_settings.m_debugDumpers = on; - engine()->setDebugDumpers(on); + m_engine->setDebugDumpers(on); } void DebuggerManager::setSkipKnownFrames(bool on) @@ -1123,29 +1139,31 @@ void DebuggerManager::queryCurrentTextEditor(QString *fileName, int *lineNumber, void DebuggerManager::continueExec() { - engine()->continueInferior(); + m_engine->continueInferior(); } void DebuggerManager::interruptDebuggingRequest() { + QTC_ASSERT(m_engine, return); //qDebug() << "INTERRUPTING AT" << status(); bool interruptIsExit = (status() != DebuggerInferiorRunning); if (interruptIsExit) exitDebugger(); else { setStatus(DebuggerInferiorStopRequested); - engine()->interruptInferior(); + m_engine->interruptInferior(); } } void DebuggerManager::runToLineExec() { + QTC_ASSERT(m_engine, return); QString fileName; int lineNumber = -1; emit currentTextEditorRequested(&fileName, &lineNumber, 0); if (!fileName.isEmpty()) - engine()->runToLineExec(fileName, lineNumber); + m_engine->runToLineExec(fileName, lineNumber); } void DebuggerManager::runToFunctionExec() @@ -1177,7 +1195,7 @@ void DebuggerManager::runToFunctionExec() } //qDebug() << "RUN TO FUNCTION " << functionName; if (!functionName.isEmpty()) - engine()->runToFunctionExec(functionName); + m_engine->runToFunctionExec(functionName); } void DebuggerManager::jumpToLineExec() @@ -1186,20 +1204,20 @@ void DebuggerManager::jumpToLineExec() int lineNumber = -1; emit currentTextEditorRequested(&fileName, &lineNumber, 0); if (!fileName.isEmpty()) - engine()->jumpToLineExec(fileName, lineNumber); + m_engine->jumpToLineExec(fileName, lineNumber); } void DebuggerManager::resetLocation() { - //m_watchHandler->removeMouseMoveCatcher(editor->widget()); + // connected to the plugin emit resetLocationRequested(); } void DebuggerManager::gotoLocation(const QString &fileName, int line, bool setMarker) { + // connected to the plugin emit gotoLocationRequested(fileName, line, setMarker); - //m_watchHandler->installMouseMoveCatcher(editor->widget()); } @@ -1211,9 +1229,10 @@ void DebuggerManager::gotoLocation(const QString &fileName, int line, void DebuggerManager::reloadDisassembler() { + QTC_ASSERT(m_engine, return); if (!m_disassemblerDock || !m_disassemblerDock->isVisible()) return; - engine()->reloadDisassembler(); + m_engine->reloadDisassembler(); } void DebuggerManager::disassemblerDockToggled(bool on) @@ -1223,6 +1242,26 @@ void DebuggerManager::disassemblerDockToggled(bool on) } +////////////////////////////////////////////////////////////////////// +// +// Sourec files specific stuff +// +////////////////////////////////////////////////////////////////////// + +void DebuggerManager::reloadSourceFiles() +{ + if (!m_sourceFilesDock || !m_sourceFilesDock->isVisible()) + return; + m_engine->reloadSourceFiles(); +} + +void DebuggerManager::sourceFilesDockToggled(bool on) +{ + if (on) + reloadSourceFiles(); +} + + ////////////////////////////////////////////////////////////////////// // // Modules specific stuff @@ -1233,7 +1272,7 @@ void DebuggerManager::reloadModules() { if (!m_modulesDock || !m_modulesDock->isVisible()) return; - engine()->reloadModules(); + m_engine->reloadModules(); } void DebuggerManager::modulesDockToggled(bool on) @@ -1251,11 +1290,13 @@ void DebuggerManager::modulesDockToggled(bool on) void DebuggerManager::showDebuggerOutput(const QString &prefix, const QString &msg) { + QTC_ASSERT(m_outputWindow, return); m_outputWindow->showOutput(prefix, msg); } void DebuggerManager::showDebuggerInput(const QString &prefix, const QString &msg) { + QTC_ASSERT(m_outputWindow, return); m_outputWindow->showInput(prefix, msg); } @@ -1276,7 +1317,7 @@ void DebuggerManager::reloadRegisters() { if (!m_registerDock || !m_registerDock->isVisible()) return; - engine()->reloadRegisters(); + m_engine->reloadRegisters(); } diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h index 1c12a731643..18d5475e728 100644 --- a/src/plugins/debugger/debuggermanager.h +++ b/src/plugins/debugger/debuggermanager.h @@ -66,6 +66,7 @@ class RegisterHandler; class StackHandler; class ThreadsHandler; class WatchHandler; +class SourceFilesWindow; class WatchData; class BreakpointData; @@ -76,23 +77,15 @@ class BreakpointData; // DebuggerProcessNotReady // | // DebuggerProcessStartingUp -// | -// DebuggerReady [R] [N] // | <-------------------------------------. // DebuggerInferiorRunningRequested | -// | | -// DebuggerInferiorRunning | -// | | +// | | +// DebuggerInferiorRunning | +// | | // DebuggerInferiorStopRequested | // | | // DebuggerInferiorStopped | // | | -// DebuggerInferiorUpdating | -// | | -// DebuggerInferiorUpdateFinishing | -// | | -// DebuggerInferiorReady [C] [N] | -// | | // `---------------------------------------' // // Allowed actions: @@ -106,17 +99,11 @@ enum DebuggerStatus { DebuggerProcessNotReady, // Debugger not started DebuggerProcessStartingUp, // Debugger starting up - DebuggerProcessReady, // Debugger started, Inferior not yet - // running or already finished DebuggerInferiorRunningRequested, // Debuggee requested to run DebuggerInferiorRunning, // Debuggee running DebuggerInferiorStopRequested, // Debuggee running, stop requested DebuggerInferiorStopped, // Debuggee stopped - - DebuggerInferiorUpdating, // Debuggee updating data views - DebuggerInferiorUpdateFinishing, // Debuggee updating data views aborting - DebuggerInferiorReady, }; @@ -150,9 +137,8 @@ private: friend class WinEngine; // called from the engines after successful startup - virtual void notifyStartupFinished() = 0; + virtual void notifyInferiorStopRequested() = 0; virtual void notifyInferiorStopped() = 0; - virtual void notifyInferiorUpdateFinished() = 0; virtual void notifyInferiorRunningRequested() = 0; virtual void notifyInferiorRunning() = 0; virtual void notifyInferiorExited() = 0; @@ -165,15 +151,21 @@ private: virtual StackHandler *stackHandler() = 0; virtual ThreadsHandler *threadsHandler() = 0; virtual WatchHandler *watchHandler() = 0; + virtual SourceFilesWindow *sourceFileWindow() = 0; virtual void showApplicationOutput(const QString &data) = 0; virtual bool skipKnownFrames() const = 0; virtual bool debugDumpers() const = 0; virtual bool useCustomDumpers() const = 0; - virtual bool useFastStart() const = 0; + + virtual bool wantsAllPluginBreakpoints() const = 0; + virtual bool wantsSelectedPluginBreakpoints() const = 0; + virtual bool wantsNoPluginBreakpoints() const = 0; + virtual QString selectedPluginBreakpointsPattern() const = 0; virtual void reloadDisassembler() = 0; virtual void reloadModules() = 0; + virtual void reloadSourceFiles() = 0; virtual void reloadRegisters() = 0; }; @@ -200,6 +192,11 @@ public: bool m_useToolTips; QString m_scriptFile; + + bool m_pluginAllBreakpoints; + bool m_pluginSelectedBreakpoints; + bool m_pluginNoBreakpoints; + QString m_pluginSelectedBreakpointsPattern; }; // @@ -220,7 +217,7 @@ public: QLabel *statusLabel() const { return m_statusLabel; } DebuggerSettings *settings() { return &m_settings; } - enum StartMode { startInternal, startExternal, attachExternal }; + enum StartMode { StartInternal, StartExternal, AttachExternal }; enum DebuggerType { GdbDebugger, ScriptDebugger, WinDebugger }; public slots: @@ -283,7 +280,6 @@ public slots: void setUseCustomDumpers(bool on); void setDebugDumpers(bool on); void setSkipKnownFrames(bool on); - void setUseFastStart(bool on); private slots: void showDebuggerOutput(const QString &prefix, const QString &msg); @@ -293,6 +289,9 @@ private slots: void reloadDisassembler(); void disassemblerDockToggled(bool on); + void reloadSourceFiles(); + void sourceFilesDockToggled(bool on); + void reloadModules(); void modulesDockToggled(bool on); void loadSymbols(const QString &moduleName); @@ -314,16 +313,23 @@ private: StackHandler *stackHandler() { return m_stackHandler; } ThreadsHandler *threadsHandler() { return m_threadsHandler; } WatchHandler *watchHandler() { return m_watchHandler; } + SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; } bool skipKnownFrames() const; bool debugDumpers() const; bool useCustomDumpers() const; - bool useFastStart() const; + bool wantsAllPluginBreakpoints() const + { return m_settings.m_pluginAllBreakpoints; } + bool wantsSelectedPluginBreakpoints() const + { return m_settings.m_pluginSelectedBreakpoints; } + bool wantsNoPluginBreakpoints() const + { return m_settings.m_pluginNoBreakpoints; } + QString selectedPluginBreakpointsPattern() const + { return m_settings.m_pluginSelectedBreakpointsPattern; } - void notifyStartupFinished(); void notifyInferiorStopped(); - void notifyInferiorUpdateFinished(); void notifyInferiorRunningRequested(); + void notifyInferiorStopRequested(); void notifyInferiorRunning(); void notifyInferiorExited(); void notifyInferiorPidChanged(int); @@ -399,6 +405,7 @@ private: QDockWidget *m_outputDock; QDockWidget *m_registerDock; QDockWidget *m_stackDock; + QDockWidget *m_sourceFilesDock; QDockWidget *m_threadsDock; QDockWidget *m_watchDock; QList m_dockWidgets; @@ -410,6 +417,7 @@ private: StackHandler *m_stackHandler; ThreadsHandler *m_threadsHandler; WatchHandler *m_watchHandler; + SourceFilesWindow *m_sourceFilesWindow; /// Actions friend class DebuggerPlugin; diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index b8bffaa14eb..89e8e59c69b 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -274,15 +274,26 @@ QWidget *GdbOptionPage::createPage(QWidget *parent) m_ui.scriptFileChooser->setPromptDialogTitle(tr("Choose Location of Startup Script File")); m_ui.scriptFileChooser->setPath(m_settings.m_scriptFile); m_ui.environmentEdit->setText(m_settings.m_gdbEnv); - m_ui.autoStartBox->setChecked(m_settings.m_autoRun); - m_ui.autoQuitBox->setChecked(m_settings.m_autoQuit); + + m_ui.radioButtonAllPluginBreakpoints-> + setChecked(m_settings.m_pluginAllBreakpoints); + m_ui.radioButtonSelectedPluginBreakpoints-> + setChecked(m_settings.m_pluginSelectedBreakpoints); + m_ui.radioButtonNoPluginBreakpoints-> + setChecked(m_settings.m_pluginNoBreakpoints); + m_ui.lineEditSelectedPluginBreakpointsPattern-> + setText(m_settings.m_pluginSelectedBreakpointsPattern); + m_ui.lineEditSelectedPluginBreakpointsPattern-> + setEnabled(m_settings.m_pluginSelectedBreakpoints); m_ui.checkBoxSkipKnownFrames->setChecked(m_settings.m_skipKnownFrames); m_ui.checkBoxDebugDumpers->setChecked(m_settings.m_debugDumpers); m_ui.checkBoxUseCustomDumpers->setChecked(m_settings.m_useCustomDumpers); - m_ui.checkBoxFastStart->setChecked(m_settings.m_useFastStart); m_ui.checkBoxUseToolTips->setChecked(m_settings.m_useToolTips); + connect(m_ui.radioButtonSelectedPluginBreakpoints, SIGNAL(toggled(bool)), + m_ui.lineEditSelectedPluginBreakpointsPattern, SLOT(setEnabled(bool))); + #ifndef QT_DEBUG #if 0 cmd = am->registerAction(m_manager->m_dumpLogAction, @@ -294,14 +305,9 @@ QWidget *GdbOptionPage::createPage(QWidget *parent) #endif // FIXME - m_ui.autoStartBox->hide(); - m_ui.autoQuitBox->hide(); m_ui.environmentEdit->hide(); m_ui.labelEnvironment->hide(); - m_ui.checkBoxFastStart->setChecked(false); - m_ui.checkBoxFastStart->hide(); - //m_dumpLogAction = new QAction(this); //m_dumpLogAction->setText(tr("Dump Log File for Debugging Purposes")); // @@ -315,16 +321,22 @@ void GdbOptionPage::apply() { m_settings.m_gdbCmd = m_ui.gdbLocationChooser->path(); m_settings.m_gdbEnv = m_ui.environmentEdit->text(); - m_settings.m_autoRun = m_ui.autoStartBox->isChecked(); - m_settings.m_autoQuit = m_ui.autoQuitBox->isChecked(); m_settings.m_scriptFile = m_ui.scriptFileChooser->path(); m_settings.m_skipKnownFrames = m_ui.checkBoxSkipKnownFrames->isChecked(); m_settings.m_debugDumpers = m_ui.checkBoxDebugDumpers->isChecked(); m_settings.m_useCustomDumpers = m_ui.checkBoxUseCustomDumpers->isChecked(); - m_settings.m_useFastStart = m_ui.checkBoxFastStart->isChecked(); m_settings.m_useToolTips = m_ui.checkBoxUseToolTips->isChecked(); + m_settings.m_pluginAllBreakpoints = + m_ui.radioButtonAllPluginBreakpoints->isChecked(); + m_settings.m_pluginSelectedBreakpoints = + m_ui.radioButtonSelectedPluginBreakpoints->isChecked(); + m_settings.m_pluginNoBreakpoints = + m_ui.radioButtonNoPluginBreakpoints->isChecked(); + m_settings.m_pluginSelectedBreakpointsPattern = + m_ui.lineEditSelectedPluginBreakpointsPattern->text(); + *m_plugin->m_manager->settings() = m_settings; m_plugin->writeSettings(); } @@ -441,7 +453,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *error_mes #endif cmd = am->registerAction(m_manager->m_continueAction, - ProjectExplorer::Constants::DEBUG, QList()<< m_gdbRunningContext); + ProjectExplorer::Constants::DEBUG, QList() << m_gdbRunningContext); cmd = am->registerAction(m_manager->m_stopAction, Constants::INTERRUPT, globalcontext); @@ -889,11 +901,16 @@ void DebuggerPlugin::writeSettings() const s->setValue("AutoRun", m->m_autoRun); s->setValue("AutoQuit", m->m_autoQuit); - s->setValue("UseFastStart", m->m_useFastStart); s->setValue("UseToolTips", m->m_useToolTips); s->setValue("UseCustomDumpers", m->m_useCustomDumpers); s->setValue("SkipKnowFrames", m->m_skipKnownFrames); s->setValue("DebugDumpers", m->m_debugDumpers); + + s->setValue("AllPluginBreakpoints", m->m_pluginAllBreakpoints); + s->setValue("SelectedPluginBreakpoints", m->m_pluginSelectedBreakpoints); + s->setValue("NoPluginBreakpoints", m->m_pluginNoBreakpoints); + s->setValue("SelectedPluginBreakpointsPattern", m->m_pluginSelectedBreakpointsPattern); + s->endGroup(); } @@ -911,6 +928,7 @@ void DebuggerPlugin::readSettings() QString defaultScript; s->beginGroup(QLatin1String("DebugMode")); + QByteArray ba = s->value("State", QByteArray()).toByteArray(); m_toggleLockedAction->setChecked(s->value("Locked", true).toBool()); m->m_gdbCmd = s->value("Location", defaultCommand).toString(); @@ -922,8 +940,17 @@ void DebuggerPlugin::readSettings() m->m_skipKnownFrames = s->value("SkipKnownFrames", false).toBool(); m->m_debugDumpers = s->value("DebugDumpers", false).toBool(); m->m_useCustomDumpers = s->value("UseCustomDumpers", true).toBool(); - m->m_useFastStart = s->value("UseFastStart", false).toBool(); m->m_useToolTips = s->value("UseToolTips", false).toBool(); + + m->m_pluginAllBreakpoints = + s->value("AllPluginBreakpoints", true).toBool(); + m->m_pluginSelectedBreakpoints = + s->value("SelectedPluginBreakpoints", false).toBool(); + m->m_pluginNoBreakpoints = + s->value("NoPluginBreakpoints", false).toBool(); + m->m_pluginSelectedBreakpointsPattern = + s->value("SelectedPluginBreakpointsPattern").toString(); + s->endGroup(); m_manager->mainWindow()->restoreState(ba); diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index 7f3e42f47fa..149b137727e 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -107,11 +107,16 @@ DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager, : RunControl(runConfiguration), m_manager(manager), m_running(false) { connect(m_manager, SIGNAL(debuggingFinished()), - this, SLOT(debuggingFinished())); + this, SLOT(debuggingFinished()), + Qt::QueuedConnection); connect(m_manager, SIGNAL(applicationOutputAvailable(QString)), - this, SLOT(slotAddToOutputWindowInline(QString))); + this, SLOT(slotAddToOutputWindowInline(QString)), + Qt::QueuedConnection); connect(m_manager, SIGNAL(inferiorPidChanged(qint64)), - this, SLOT(bringApplicationToForeground(qint64))); + this, SLOT(bringApplicationToForeground(qint64)), + Qt::QueuedConnection); + connect(this, SIGNAL(stopRequested()), + m_manager, SLOT(exitDebugger())); } void DebuggerRunControl::start() @@ -132,7 +137,7 @@ void DebuggerRunControl::start() // andre: + "\qtc-gdbmacros\" //emit addToOutputWindow(this, tr("Debugging %1").arg(m_executable)); - if (m_manager->startNewDebugger(DebuggerManager::startInternal)) + if (m_manager->startNewDebugger(DebuggerManager::StartInternal)) emit started(); else debuggingFinished(); @@ -145,17 +150,21 @@ void DebuggerRunControl::slotAddToOutputWindowInline(const QString &data) void DebuggerRunControl::stop() { - m_manager->exitDebugger(); + //qDebug() << "DebuggerRunControl::stop"; + m_running = false; + emit stopRequested(); } void DebuggerRunControl::debuggingFinished() { m_running = false; + //qDebug() << "DebuggerRunControl::finished"; //emit addToOutputWindow(this, tr("Debugging %1 finished").arg(m_executable)); emit finished(); } bool DebuggerRunControl::isRunning() const { + //qDebug() << "DebuggerRunControl::isRunning" << m_running; return m_running; } diff --git a/src/plugins/debugger/debuggerrunner.h b/src/plugins/debugger/debuggerrunner.h index 0c6d979c010..7b73178d103 100644 --- a/src/plugins/debugger/debuggerrunner.h +++ b/src/plugins/debugger/debuggerrunner.h @@ -82,6 +82,9 @@ public: virtual void stop(); virtual bool isRunning() const; +signals: + void stopRequested(); + private slots: void debuggingFinished(); void slotAddToOutputWindowInline(const QString &output); diff --git a/src/plugins/debugger/disassemblerhandler.cpp b/src/plugins/debugger/disassemblerhandler.cpp index ff935dabfdf..59ca259e80e 100644 --- a/src/plugins/debugger/disassemblerhandler.cpp +++ b/src/plugins/debugger/disassemblerhandler.cpp @@ -33,7 +33,7 @@ #include "disassemblerhandler.h" -#include "assert.h" +#include #include #include diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp index f6413db72f9..37f35929edc 100644 --- a/src/plugins/debugger/gdbengine.cpp +++ b/src/plugins/debugger/gdbengine.cpp @@ -44,6 +44,7 @@ #include "registerhandler.h" #include "stackhandler.h" #include "watchhandler.h" +#include "sourcefileswindow.h" #include "startexternaldialog.h" #include "attachexternaldialog.h" @@ -99,6 +100,7 @@ enum GdbCommandType GdbQueryPwd, GdbQuerySources, GdbAsyncOutput2, + GdbStart, GdbExecRun, GdbExecRunToFunction, GdbExecStep, @@ -111,8 +113,10 @@ enum GdbCommandType GdbExecInterrupt, GdbInfoShared, GdbInfoProc, + GdbInfoThreads, GdbQueryDataDumper1, GdbQueryDataDumper2, + GdbTemporaryContinue, BreakCondition = 200, BreakEnablePending, @@ -229,6 +233,15 @@ static bool isLeavableFunction(const QString &funcName, const QString &fileName) return false; } +static QString startSymbolName() +{ +#ifdef Q_OS_WIN + return "WinMainCRTStartup"; +#else + return "_start"; +#endif +} + /////////////////////////////////////////////////////////////////////// // @@ -240,23 +253,18 @@ GdbEngine::GdbEngine(DebuggerManager *parent) { q = parent; qq = parent->engineInterface(); - init(); + initializeVariables(); + initializeConnections(); } GdbEngine::~GdbEngine() { + // prevent sending error messages afterwards + m_gdbProc.disconnect(this); } -void GdbEngine::init() +void GdbEngine::initializeConnections() { - m_pendingRequests = 0; - m_gdbVersion = 100; - m_shared = 0; - m_outputCodec = QTextCodec::codecForLocale(); - m_dataDumperState = DataDumperUninitialized; - - m_oldestAcceptableToken = -1; - // Gdb Process interaction connect(&m_gdbProc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(gdbProcError(QProcess::ProcessError))); @@ -284,6 +292,24 @@ void GdbEngine::init() Qt::QueuedConnection); } +void GdbEngine::initializeVariables() +{ + m_dataDumperState = DataDumperUninitialized; + m_gdbVersion = 100; + + m_fullToShortName.clear(); + m_shortToFullName.clear(); + m_varToType.clear(); + + m_modulesListOutdated = true; + m_oldestAcceptableToken = -1; + m_outputCodec = QTextCodec::codecForLocale(); + m_pendingRequests = 0; + m_waitingForBreakpointSynchronizationToContinue = false; + m_waitingForFirstBreakpointToBeHit = false; + m_commandsToRunOnTemporaryBreak.clear(); +} + void GdbEngine::gdbProcError(QProcess::ProcessError error) { QString msg; @@ -365,6 +391,11 @@ void GdbEngine::readDebugeeOutput(const QByteArray &data) data.constData(), data.length(), &m_outputCodecState)); } +void GdbEngine::debugMessage(const QString &msg) +{ + emit gdbOutputAvailable("debug:", msg); +} + // called asyncronously as response to Gdb stdout output in // gdbResponseAvailable() void GdbEngine::handleResponse() @@ -458,13 +489,28 @@ void GdbEngine::handleResponse() break; } - case '~': - case '@': + case '~': { + QString data = GdbMi::parseCString(from, to); + m_pendingConsoleStreamOutput += data; + m_inbuffer = QByteArray(from, to - from); + break; + } + + case '@': { + QString data = GdbMi::parseCString(from, to); + m_pendingTargetStreamOutput += data; + m_inbuffer = QByteArray(from, to - from); + break; + } + case '&': { QString data = GdbMi::parseCString(from, to); - handleStreamOutput(data, c); - //dump(oldfrom, from, record.toString()); + m_pendingLogStreamOutput += data; m_inbuffer = QByteArray(from, to - from); + // On Windows, the contents seem to depend on the debugger + // version and/or OS version used. + if (data.startsWith("warning:")) + qq->showApplicationOutput(data); break; } @@ -607,22 +653,29 @@ void GdbEngine::readGdbStandardOutput() void GdbEngine::interruptInferior() { - if (m_gdbProc.state() == QProcess::NotRunning) + qq->notifyInferiorStopRequested(); + if (m_gdbProc.state() == QProcess::NotRunning) { + debugMessage("TRYING TO INTERRUPT INFERIOR WITHOUT RUNNING GDB"); + qq->notifyInferiorExited(); return; + } if (q->m_attachedPID > 0) { - if (interruptProcess(q->m_attachedPID)) - qq->notifyInferiorStopped(); + if (!interruptProcess(q->m_attachedPID)) + // qq->notifyInferiorStopped(); + //else + debugMessage(QString("CANNOT INTERRUPT %1").arg(q->m_attachedPID)); return; } #ifdef Q_OS_MAC sendCommand("-exec-interrupt", GdbExecInterrupt); - qq->notifyInferiorStopped(); + //qq->notifyInferiorStopped(); #else - qDebug() << "CANNOT STOP INFERIOR" << m_gdbProc.pid(); - if (interruptChildProcess(m_gdbProc.pid())) - qq->notifyInferiorStopped(); + if (!interruptChildProcess(m_gdbProc.pid())) + // qq->notifyInferiorStopped(); + //else + debugMessage(QString("CANNOT STOP INFERIOR")); #endif } @@ -630,37 +683,30 @@ void GdbEngine::maybeHandleInferiorPidChanged(const QString &pid0) { int pid = pid0.toInt(); if (pid == 0) { - qDebug() << "Cannot parse PID from " << pid0; + debugMessage(QString("Cannot parse PID from %1").arg(pid0)); return; } if (pid == q->m_attachedPID) return; + debugMessage(QString("FOUND PID %1").arg(pid)); q->m_attachedPID = pid; qq->notifyInferiorPidChanged(pid); } void GdbEngine::sendSynchronizedCommand(const QString & command, - int type, const QVariant &cookie, bool needStop) + int type, const QVariant &cookie, StopNeeded needStop) { - sendCommand(command, type, cookie, needStop, true); + sendCommand(command, type, cookie, needStop, Synchronized); } void GdbEngine::sendCommand(const QString &command, int type, - const QVariant &cookie, bool needStop, bool synchronized) + const QVariant &cookie, StopNeeded needStop, Synchronization synchronized) { if (m_gdbProc.state() == QProcess::NotRunning) { - //qDebug() << "NO GDB PROCESS RUNNING, CMD IGNORED:" << command; + debugMessage("NO GDB PROCESS RUNNING, CMD IGNORED: " + command); return; } - bool temporarilyStopped = false; - if (needStop && q->status() == DebuggerInferiorRunning) { - q->showStatusMessage(tr("Temporarily stopped")); - interruptInferior(); - temporarilyStopped = true; - } - - ++currentToken(); if (synchronized) { ++m_pendingRequests; PENDING_DEBUG(" TYPE " << type << " INCREMENTS PENDING TO: " @@ -673,28 +719,30 @@ void GdbEngine::sendCommand(const QString &command, int type, GdbCookie cmd; cmd.synchronized = synchronized; cmd.command = command; - cmd.command = QString::number(currentToken()) + cmd.command; - if (cmd.command.contains("%1")) - cmd.command = cmd.command.arg(currentToken()); cmd.type = type; cmd.cookie = cookie; - m_cookieForToken[currentToken()] = cmd; + if (needStop && q->status() != DebuggerInferiorStopped + && q->status() != DebuggerProcessStartingUp) { + // queue the commands that we cannot send at once + QTC_ASSERT(q->status() == DebuggerInferiorRunning, + qDebug() << "STATUS: " << q->status()); + q->showStatusMessage(tr("Stopping temporarily.")); + debugMessage("QUEUING COMMAND " + cmd.command); + m_commandsToRunOnTemporaryBreak.append(cmd); + interruptInferior(); + } else if (!command.isEmpty()) { + ++currentToken(); + m_cookieForToken[currentToken()] = cmd; + cmd.command = QString::number(currentToken()) + cmd.command; + if (cmd.command.contains("%1")) + cmd.command = cmd.command.arg(currentToken()); - //qDebug() << ""; - if (!command.isEmpty()) { - //qDebug() << qPrintable(currentTime()) << "RUNNING" << cmd.command; m_gdbProc.write(cmd.command.toLatin1() + "\r\n"); //emit gdbInputAvailable(QString(), " " + currentTime()); - emit gdbInputAvailable(QString(), "[" + currentTime() + "] " + cmd.command); - //emit gdbInputAvailable(QString(), cmd.command); + //emit gdbInputAvailable(QString(), "[" + currentTime() + "] " + cmd.command); + emit gdbInputAvailable(QString(), cmd.command); } - - if (temporarilyStopped) - sendCommand("-exec-continue"); - - // slows down - //qApp->processEvents(); } void GdbEngine::handleResultRecord(const GdbResultRecord &record) @@ -734,8 +782,10 @@ void GdbEngine::handleResultRecord(const GdbResultRecord &record) --m_pendingRequests; PENDING_DEBUG(" TYPE " << cmd.type << " DECREMENTS PENDING TO: " << m_pendingRequests << cmd.command); - if (m_pendingRequests <= 0) + if (m_pendingRequests <= 0) { + PENDING_DEBUG(" .... AND TRIGGERS MODEL UPDATE"); updateWatchModel2(); + } } else { PENDING_DEBUG(" UNKNOWN TYPE " << cmd.type << " LEAVES PENDING AT: " << m_pendingRequests << cmd.command); @@ -753,12 +803,18 @@ void GdbEngine::handleResult(const GdbResultRecord & record, int type, case GdbExecContinue: case GdbExecFinish: // evil code sharing - case GdbExecRun: handleExecRun(record); break; + + case GdbStart: + handleStart(record); + break; case GdbInfoProc: handleInfoProc(record); break; + case GdbInfoThreads: + handleInfoThreads(record); + break; case GdbShowVersion: handleShowVersion(record); @@ -772,6 +828,7 @@ void GdbEngine::handleResult(const GdbResultRecord & record, int type, //handleExecRunToFunction(record); break; case GdbExecInterrupt: + qq->notifyInferiorStopped(); break; case GdbExecJumpToLine: handleExecJumpToLine(record); @@ -794,6 +851,10 @@ void GdbEngine::handleResult(const GdbResultRecord & record, int type, case GdbQueryDataDumper2: handleQueryDataDumper2(record); break; + case GdbTemporaryContinue: + continueInferior(); + q->showStatusMessage(tr("Continuing after temporary stop.")); + break; case BreakList: handleBreakList(record); @@ -875,8 +936,8 @@ void GdbEngine::handleResult(const GdbResultRecord & record, int type, break; default: - qDebug() << "FIXME: GdbEngine::handleResult: " - "should not happen" << type; + debugMessage(QString("FIXME: GdbEngine::handleResult: " + "should not happen %1").arg(type)); break; } } @@ -885,7 +946,7 @@ void GdbEngine::executeDebuggerCommand(const QString &command) { //createGdbProcessIfNeeded(); if (m_gdbProc.state() == QProcess::NotRunning) { - qDebug() << "NO GDB PROCESS RUNNING, PLAIN CMD IGNORED: " << command; + debugMessage("NO GDB PROCESS RUNNING, PLAIN CMD IGNORED: " + command); return; } @@ -893,11 +954,6 @@ void GdbEngine::executeDebuggerCommand(const QString &command) cmd.command = command; cmd.type = -1; - //m_cookieForToken[currentToken()] = cmd; - //++currentToken(); - - //qDebug() << ""; - //qDebug() << currentTime() << "Running command: " << cmd.command; emit gdbInputAvailable(QString(), cmd.command); m_gdbProc.write(cmd.command.toLatin1() + "\r\n"); } @@ -924,13 +980,14 @@ void GdbEngine::handleQueryPwd(const GdbResultRecord &record) m_pwd = record.data.findChild("consolestreamoutput").data(); m_pwd = m_pwd.trimmed(); #endif - //qDebug() << "PWD RESULT:" << m_pwd; + debugMessage("PWD RESULT: " + m_pwd); } } void GdbEngine::handleQuerySources(const GdbResultRecord &record) { if (record.resultClass == GdbResultDone) { + QMap oldShortToFull = m_shortToFullName; m_shortToFullName.clear(); m_fullToShortName.clear(); // "^done,files=[{file="../../../../bin/gdbmacros/gdbmacros.cpp", @@ -949,6 +1006,21 @@ void GdbEngine::handleQuerySources(const GdbResultRecord &record) m_fullToShortName[full] = fileName; } } + if (m_shortToFullName != oldShortToFull) + qq->sourceFileWindow()->setSourceFiles(m_shortToFullName); + } +} + +void GdbEngine::handleInfoThreads(const GdbResultRecord &record) +{ + if (record.resultClass == GdbResultDone) { + // FIXME: use something more robust + // WIN: * 3 Thread 2312.0x4d0 0x7c91120f in ?? () + // LINUX: * 1 Thread 0x7f466273c6f0 (LWP 21455) 0x0000000000404542 in ... + QRegExp re(QLatin1String("Thread (\\d+)\\.0x.* in")); + QString data = record.data.findChild("consolestreamoutput").data(); + if (re.indexIn(data) != -1) + maybeHandleInferiorPidChanged(re.cap(1)); } } @@ -975,18 +1047,6 @@ void GdbEngine::handleInfoShared(const GdbResultRecord &record) if (record.resultClass == GdbResultDone) { // let the modules handler do the parsing handleModulesList(record); - QList modules = qq->modulesHandler()->modules(); - bool reloadNeeded = false; - foreach (const Module &module, modules) { - // FIXME: read this from some list - if (!module.symbolsRead && !module.moduleName.contains("Q")) { - reloadNeeded = true; - sendCommand("sharedlibrary " + dotEscape(module.moduleName)); - } - } - if (reloadNeeded) - reloadModules(); - continueInferior(); } } @@ -1028,84 +1088,6 @@ void GdbEngine::handleExecRunToFunction(const GdbResultRecord &record) q->gotoLocation(file, line, true); } -void GdbEngine::handleStreamOutput(const QString &data, char code) -{ - // Linux - if (data.contains("[New Thread")) { - QRegExp re("\\[New Thread 0x([0-9a-f]*) \\(LWP ([0-9]*)\\)\\]"); - if (re.indexIn(data) != -1) - maybeHandleInferiorPidChanged(re.cap(2)); - } - - // Mac - if (data.contains("[Switching to process ")) { - QRegExp re("\\[Switching to process ([0-9]*) local thread 0x([0-9a-f]*)\\]"); - if (re.indexIn(data) != -1) - maybeHandleInferiorPidChanged(re.cap(1)); - } - - // present it twice: now and together with the next 'real' result - switch (code) { - case '~': - m_pendingConsoleStreamOutput += data; - break; - case '@': - m_pendingTargetStreamOutput += data; - break; - case '&': - m_pendingLogStreamOutput += data; - // On Windows, the contents seem to depend on the debugger - // version and/or OS version used. - if (data.startsWith("warning:")) - qq->showApplicationOutput(data); - break; - } - -#ifdef Q_OS_LINUX - if (data.startsWith("Pending break") && data.contains("\" resolved")) { - qDebug() << "SCHEDULING -break-list"; - //m_breakListOnStopNeeded = true; - } -#endif - -#if 0 - if (m_slurpingPTypeOutput) - qDebug() << "SLURP: " << output.data; - - // "No symbol \"__dlopen\" in current context." - // "No symbol \"dlopen\" in current context." - if (output.data.startsWith("No symbol ") - && output.data.contains("dlopen")) { - m_dlopened = true; - return; - } - - // output of 'ptype ' - if (output.data.startsWith("type = ")) { - if (output.data.endsWith("{") || output.data.endsWith("{\\n")) { - // multi-line output started here... - m_slurpingPTypeOutput = true; - m_slurpedPTypeOutput = output.data; - } else { - // Happens for simple types. Process it immediately - m_watchHandler->handleTypeContents(output.data); - } - return; - } - if (m_slurpingPTypeOutput) { - m_slurpedPTypeOutput += '\n'; - m_slurpedPTypeOutput += output.data; - if (output.data.startsWith("}")) { - // this is the last line... - m_slurpingPTypeOutput = false; - m_watchHandler->handleTypeContents(m_slurpedPTypeOutput); - m_slurpedPTypeOutput.clear(); - } - return; - } -#endif -} - static bool isExitedReason(const QString &reason) { return reason == QLatin1String("exited-normally") // inferior exited normally @@ -1133,36 +1115,6 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) { const QString reason = data.findChild("reason").data(); - QString console = data.findChild("consolestreamoutput").data(); - if (console.contains("Stopped due to shared library event") || reason.isEmpty()) { - ++m_shared; - //if (m_shared == 2) - // tryLoadCustomDumpers(); - //qDebug() << "SHARED LIBRARY EVENT " << data.toString() << m_shared; - if (qq->useFastStart()) { - if (1 || m_shared <= 16) { // libpthread? - sendCommand("info shared", GdbInfoShared); - //sendCommand("sharedlibrary gdbdebugger "); - //continueInferior(); - } else { - // auto-load from now on - sendCommand("info shared"); - sendCommand("set auto-solib-add on"); - sendCommand("-file-list-exec-source-files", GdbQuerySources); - sendCommand("-break-list", BreakList); - //sendCommand("bt"); - //QVariant var = QVariant::fromValue(data); - //sendCommand("p 1", GdbAsyncOutput2, var); // dummy - continueInferior(); - } - } else { - // slow start requested. - q->showStatusMessage(tr("Loading %1...").arg(QString(data.toString()))); - continueInferior(); - } - return; - } - if (isExitedReason(reason)) { qq->notifyInferiorExited(); QString msg = "Program exited normally"; @@ -1177,10 +1129,102 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) + data.findChild("signal-name").toString(); } q->showStatusMessage(msg); + // FIXME: shouldn't this use a statis change? + debugMessage("CALLING PARENT EXITDEBUGGER"); q->exitDebugger(); return; } + + //MAC: bool isFirstStop = data.findChild("bkptno").data() == "1"; + //!MAC: startSymbolName == data.findChild("frame").findChild("func") + if (m_waitingForFirstBreakpointToBeHit) { + // If the executable dies already that early we might get something + // like stdout:49*stopped,reason="exited",exit-code="0177" + // This is handled now above. + + qq->notifyInferiorStopped(); + m_waitingForFirstBreakpointToBeHit = false; + // + // that's the "early stop" + // + #if defined(Q_OS_WIN) + sendCommand("info thread", GdbInfoThreads); + #endif + #if defined(Q_OS_LINUX) + sendCommand("info proc", GdbInfoProc); + #endif + #if defined(Q_OS_MAC) + sendCommand("info pid", GdbInfoProc); + #endif + reloadSourceFiles(); + tryLoadCustomDumpers(); + + // intentionally after tryLoadCustomDumpers(), + // otherwise we'd interupt solib loading. + if (qq->wantsAllPluginBreakpoints()) { + sendCommand("set auto-solib-add on"); + sendCommand("set stop-on-solib-events 0"); + sendCommand("sharedlibrary .*"); + } else if (qq->wantsSelectedPluginBreakpoints()) { + sendCommand("set auto-solib-add on"); + sendCommand("set stop-on-solib-events 1"); + sendCommand("sharedlibrary "+qq->selectedPluginBreakpointsPattern()); + } else if (qq->wantsNoPluginBreakpoints()) { + // should be like that already + sendCommand("set auto-solib-add off"); + sendCommand("set stop-on-solib-events 0"); + } + // nicer to see a bit of the world we live in + reloadModules(); + // this will "continue" if done + m_waitingForBreakpointSynchronizationToContinue = true; + QTimer::singleShot(0, this, SLOT(attemptBreakpointSynchronization())); + return; + } + + if (!m_commandsToRunOnTemporaryBreak.isEmpty()) { + QTC_ASSERT(q->status() == DebuggerInferiorStopRequested, + qDebug() << "STATUS: " << q->status()) + qq->notifyInferiorStopped(); + q->showStatusMessage(tr("Temporarily stopped.")); + // FIXME: racy + foreach (const GdbCookie &cmd, m_commandsToRunOnTemporaryBreak) { + debugMessage(QString("RUNNING QUEUED COMMAND %1 %2") + .arg(cmd.command).arg(cmd.type)); + sendCommand(cmd.command, cmd.type, cmd.cookie); + } + sendCommand("p temporaryStop", GdbTemporaryContinue); + m_commandsToRunOnTemporaryBreak.clear(); + q->showStatusMessage(tr("Handling queued commands.")); + return; + } + + QString msg = data.findChild("consolestreamoutput").data(); + if (msg.contains("Stopped due to shared library event") || reason.isEmpty()) { + if (qq->wantsSelectedPluginBreakpoints()) { + debugMessage("SHARED LIBRARY EVENT: " + data.toString()); + debugMessage("PATTERN: " + qq->selectedPluginBreakpointsPattern()); + sendCommand("sharedlibrary " + qq->selectedPluginBreakpointsPattern()); + continueInferior(); + q->showStatusMessage(tr("Loading %1...").arg(QString(data.toString()))); + return; + } + m_modulesListOutdated = true; + // fall through + } + + // seen on XP after removing a breakpoint while running + // stdout:945*stopped,reason="signal-received",signal-name="SIGTRAP", + // signal-meaning="Trace/breakpoint trap",thread-id="2", + // frame={addr="0x7c91120f",func="ntdll!DbgUiConnectToDbg", + // args=[],from="C:\\WINDOWS\\system32\\ntdll.dll"} + if (reason == "signal-received" + && data.findChild("signal-name").toString() == "SIGTRAP") { + continueInferior(); + return; + } + //tryLoadCustomDumpers(); // jump over well-known frames @@ -1188,21 +1232,21 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) if (qq->skipKnownFrames()) { if (reason == "end-stepping-range" || reason == "function-finished") { GdbMi frame = data.findChild("frame"); - //qDebug() << frame.toString(); + //debugMessage(frame.toString()); m_currentFrame = frame.findChild("addr").data() + '%' + frame.findChild("func").data() + '%'; QString funcName = frame.findChild("func").data(); QString fileName = frame.findChild("file").data(); if (isLeavableFunction(funcName, fileName)) { - //qDebug() << "LEAVING" << funcName; + //debugMessage("LEAVING" + funcName); ++stepCounter; q->stepOutExec(); //stepExec(); return; } if (isSkippableFunction(funcName, fileName)) { - //qDebug() << "SKIPPING" << funcName; + //debugMessage("SKIPPING" + funcName); ++stepCounter; q->stepExec(); return; @@ -1214,16 +1258,20 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) } if (isStoppedReason(reason) || reason.isEmpty()) { + if (m_modulesListOutdated) { + reloadModules(); + m_modulesListOutdated = false; + } // Need another round trip if (reason == "breakpoint-hit") { q->showStatusMessage(tr("Stopped at breakpoint")); GdbMi frame = data.findChild("frame"); - //qDebug() << frame.toString(); + //debugMessage("HIT BREAKPOINT: " + frame.toString()); m_currentFrame = frame.findChild("addr").data() + '%' + frame.findChild("func").data() + '%'; QApplication::alert(q->mainWindow(), 3000); - sendCommand("-file-list-exec-source-files", GdbQuerySources); + reloadSourceFiles(); sendCommand("-break-list", BreakList); QVariant var = QVariant::fromValue(data); sendCommand("p 0", GdbAsyncOutput2, var); // dummy @@ -1234,7 +1282,7 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) return; } - qDebug() << "STOPPED FOR UNKNOWN REASON" << data.toString(); + debugMessage("STOPPED FOR UNKNOWN REASON: " + data.toString()); // Ignore it. Will be handled with full response later in the // JumpToLine or RunToFunction handlers #if 1 @@ -1265,30 +1313,6 @@ void GdbEngine::handleAsyncOutput2(const GdbMi &data) { qq->notifyInferiorStopped(); - // - // Breakpoints - // - //qDebug() << "BREAK ASYNC: " << output.toString(); - //sendListBreakpoints(); - //attemptBreakpointSynchronization(); - //if (m_breakListOnStopNeeded) - // sendListBreakpoints(); - - // something reasonably 'invariant' - // Linux: - //"79*stopped,reason="end-stepping-range",reason="breakpoint-hit",bkptno="1", - //thread-id="1",frame={addr="0x0000000000405d8f",func="run1", - //args=[{name="argc",value="1"},{name="argv",value="0x7fffb7c23058"}], - //file="test1.cpp",fullname="/home/apoenitz/dev/work/test1/test1.cpp" - //,line="261"}" - // Mac: (but only sometimes) - // "82*stopped,bkpt={number="0",type="step - // resume",disp="keep",enabled="y",addr="0x43127171",at="",thread="1",shlib="/Users/epreuss/dev/ide/main/bin/ - // workbench.app/Contents/PlugIns/Trolltech/libFind.1.0.0.dylib", - // frame="0xbfffd800",thread="1",times="1"}, - // // Stack // @@ -1325,7 +1349,7 @@ void GdbEngine::handleShowVersion(const GdbResultRecord &response) QString msg = response.data.findChild("consolestreamoutput").data(); QRegExp supported("GNU gdb(.*) (\\d+)\\.(\\d+)(\\.(\\d+))?"); if (supported.indexIn(msg) == -1) { - qDebug() << "UNSUPPORTED GDB VERSION " << msg; + debugMessage("UNSUPPORTED GDB VERSION " + msg); QStringList list = msg.split("\n"); while (list.size() > 2) list.removeLast(); @@ -1346,7 +1370,7 @@ void GdbEngine::handleShowVersion(const GdbResultRecord &response) m_gdbVersion = 10000 * supported.cap(2).toInt() + 100 * supported.cap(3).toInt() + 1 * supported.cap(5).toInt(); - //qDebug() << "GDB VERSION " << m_gdbVersion; + //debugMessage(QString("GDB VERSION: %1").arg(m_gdbVersion)); } } } @@ -1370,7 +1394,6 @@ void GdbEngine::handleExecRun(const GdbResultRecord &response) if (response.resultClass == GdbResultRunning) { qq->notifyInferiorRunning(); q->showStatusMessage(tr("Running...")); - //reloadModules(); } else if (response.resultClass == GdbResultError) { QString msg = response.data.findChild("msg").data(); if (msg == "Cannot find bounds of current function") { @@ -1403,7 +1426,7 @@ QString GdbEngine::fullName(const QString &fileName) if (fileName.isEmpty()) return QString(); QString full = m_shortToFullName.value(fileName, QString()); - //qDebug() << "RESOLVING: " << fileName << full; + //debugMessage("RESOLVING: " + fileName + " " + full); if (!full.isEmpty()) return full; QFileInfo fi(fileName); @@ -1413,7 +1436,7 @@ QString GdbEngine::fullName(const QString &fileName) #ifdef Q_OS_WIN full = QDir::cleanPath(full); #endif - //qDebug() << "STORING: " << fileName << full; + //debugMessage("STORING: " + fileName + " " + full); m_shortToFullName[fileName] = full; m_fullToShortName[full] = fileName; return full; @@ -1441,29 +1464,32 @@ void GdbEngine::shutdown() void GdbEngine::exitDebugger() { - //qDebug() << "EXITING: " << m_gdbProc.state(); - if (m_gdbProc.state() == QProcess::Starting) + debugMessage(QString("GDBENGINE EXITDEBUFFER: %1").arg(m_gdbProc.state())); + if (m_gdbProc.state() == QProcess::Starting) { + debugMessage(QString("WAITING FOR GDB STARTUP TO SHUTDOWN: %1") + .arg(m_gdbProc.state())); m_gdbProc.waitForStarted(); + } if (m_gdbProc.state() == QProcess::Running) { + debugMessage(QString("WAITING FOR RUNNING GDB TO SHUTDOWN: %1") + .arg(m_gdbProc.state())); interruptInferior(); sendCommand("kill"); sendCommand("-gdb-exit"); // 20s can easily happen when loading webkit debug information m_gdbProc.waitForFinished(20000); if (m_gdbProc.state() != QProcess::Running) { + debugMessage(QString("FORCING TERMINATION: %1") + .arg(m_gdbProc.state())); m_gdbProc.terminate(); m_gdbProc.waitForFinished(20000); } } if (m_gdbProc.state() != QProcess::NotRunning) - qDebug() << "PROBLEM STOPPING DEBUGGER"; + debugMessage("PROBLEM STOPPING DEBUGGER"); - m_shortToFullName.clear(); - m_fullToShortName.clear(); - m_varToType.clear(); - m_dataDumperState = DataDumperUninitialized; - m_shared = 0; m_outputCollector.shutdown(); + initializeVariables(); //q->settings()->m_debugDumpers = false; } @@ -1482,7 +1508,7 @@ bool GdbEngine::startDebugger() QString fileName = '"' + fi.absoluteFilePath() + '"'; if (m_gdbProc.state() != QProcess::NotRunning) { - qDebug() << "GDB IS ALREADY RUNNING!"; + debugMessage("GDB IS ALREADY RUNNING!"); return false; } @@ -1530,12 +1556,7 @@ bool GdbEngine::startDebugger() q->showStatusMessage(tr("Gdb Running")); sendCommand("show version", GdbShowVersion); - if (qq->useFastStart()) { - sendCommand("set auto-solib-add off"); - sendCommand("set stop-on-solib-events 1"); - } //sendCommand("-enable-timings"); - //sendCommand("set stop-on-solib-events 1"); sendCommand("set print static-members off"); // Seemingly doesn't work. //sendCommand("define hook-stop\n-thread-list-ids\n-stack-list-frames\nend"); //sendCommand("define hook-stop\nprint 4\nend"); @@ -1550,6 +1571,7 @@ bool GdbEngine::startDebugger() //sendCommand("set pagination off"); sendCommand("set breakpoint pending on", BreakEnablePending); sendCommand("set print elements 10000"); + sendCommand("-data-list-register-names", RegisterListNames); // one of the following is needed to prevent crashes in gdb on code like: // template T foo() { return T(0); } @@ -1575,6 +1597,8 @@ bool GdbEngine::startDebugger() sendCommand("set unwindonsignal on"); sendCommand("pwd", GdbQueryPwd); + sendCommand("set width 0"); + sendCommand("set height 0"); #ifdef Q_OS_MAC sendCommand("-gdb-set inferior-auto-start-cfm off"); @@ -1604,29 +1628,29 @@ bool GdbEngine::startDebugger() } } - if (q->startMode() == q->attachExternal) { + if (q->startMode() == DebuggerManager::AttachExternal) { sendCommand("attach " + QString::number(q->m_attachedPID)); - } - - if (q->startMode() == q->startInternal || q->startMode() == q->startExternal) { + } else { + // StartInternal or StartExternal + emit gdbInputAvailable(QString(), QString()); sendCommand("-file-exec-and-symbols " + fileName, GdbFileExecAndSymbols); + //sendCommand("file " + fileName, GdbFileExecAndSymbols); #ifdef Q_OS_MAC sendCommand("sharedlibrary apply-load-rules all"); #endif - sendCommand("-file-list-exec-source-files", GdbQuerySources); - //sendCommand("-gdb-set stop-on-solib-events 1"); + setTokenBarrier(); + if (!q->m_processArgs.isEmpty()) + sendCommand("-exec-arguments " + q->m_processArgs.join(" ")); + sendCommand("set auto-solib-add off"); + sendCommand("x/2i " + startSymbolName(), GdbStart); } - sendCommand("-data-list-register-names", RegisterListNames); - // set all to "pending" - if (q->startMode() == q->attachExternal) + if (q->startMode() == DebuggerManager::AttachExternal) qq->breakHandler()->removeAllBreakpoints(); else qq->breakHandler()->setAllPending(); - QTimer::singleShot(0, this, SLOT(attemptBreakpointSynchronization())); - return true; } @@ -1634,37 +1658,38 @@ void GdbEngine::continueInferior() { q->resetLocation(); setTokenBarrier(); - qq->notifyInferiorRunningRequested(); emit gdbInputAvailable(QString(), QString()); + qq->notifyInferiorRunningRequested(); sendCommand("-exec-continue", GdbExecContinue); } -void GdbEngine::runInferior() +void GdbEngine::handleStart(const GdbResultRecord &response) { - q->resetLocation(); - // FIXME: this ignores important startup messages - setTokenBarrier(); - if (!q->m_processArgs.isEmpty()) - sendCommand("-exec-arguments " + q->m_processArgs.join(" ")); - qq->notifyInferiorRunningRequested(); - emit gdbInputAvailable(QString(), QString()); - sendCommand("-exec-run", GdbExecRun); -#if defined(Q_OS_WIN) - sendCommand("info proc", GdbInfoProc); -#endif -#if defined(Q_OS_LINUX) - sendCommand("info proc", GdbInfoProc); -#endif -#if defined(Q_OS_MAC) - sendCommand("info pid", GdbInfoProc, QVariant(), true); -#endif + if (response.resultClass == GdbResultDone) { + // stdout:&"x/2i _start\n" + // stdout:~"0x404540 <_start>:\txor %ebp,%ebp\n" + // stdout:~"0x404542 <_start+2>:\tmov %rdx,%r9\n" + QString msg = response.data.findChild("consolestreamoutput").data(); + QRegExp needle("0x([0-9a-f]+) <" + startSymbolName() + "\\+.*>:"); + if (needle.indexIn(msg) != -1) { + //debugMessage("STREAM: " + msg + " " + needle.cap(1)); + sendCommand("tbreak *0x" + needle.cap(1)); + m_waitingForFirstBreakpointToBeHit = true; + qq->notifyInferiorRunningRequested(); + sendCommand("-exec-run"); + } else { + debugMessage("PARSING START ADDRESS FAILED: " + msg); + } + } else if (response.resultClass == GdbResultError) { + debugMessage("PARSING START ADDRESS FAILED: " + response.toString()); + } } void GdbEngine::stepExec() { setTokenBarrier(); - qq->notifyInferiorRunningRequested(); emit gdbInputAvailable(QString(), QString()); + qq->notifyInferiorRunningRequested(); sendCommand("-exec-step", GdbExecStep); } @@ -1685,8 +1710,8 @@ void GdbEngine::stepOutExec() void GdbEngine::nextExec() { setTokenBarrier(); - qq->notifyInferiorRunningRequested(); emit gdbInputAvailable(QString(), QString()); + qq->notifyInferiorRunningRequested(); sendCommand("-exec-next", GdbExecNext); } @@ -1751,12 +1776,12 @@ void GdbEngine::setTokenBarrier() void GdbEngine::setDebugDumpers(bool on) { if (on) { - qDebug() << "SWITCHING ON DUMPER DEBUGGING"; + debugMessage("SWITCHING ON DUMPER DEBUGGING"); sendCommand("set unwindonsignal off"); q->breakByFunction("qDumpObjectData440"); //updateLocals(); } else { - qDebug() << "SWITCHING OFF DUMPER DEBUGGING"; + debugMessage("SWITCHING OFF DUMPER DEBUGGING"); sendCommand("set unwindonsignal on"); } } @@ -1879,8 +1904,8 @@ void GdbEngine::sendInsertBreakpoint(int index) // cmd += "-c " + data->condition + " "; cmd += where; #endif - sendCommand(cmd, BreakInsert, index, true); - //processQueueAndContinue(); + debugMessage(QString("Current state: %1").arg(q->status())); + sendCommand(cmd, BreakInsert, index, NeedsStop); } void GdbEngine::handleBreakList(const GdbResultRecord &record) @@ -2108,16 +2133,20 @@ void GdbEngine::handleBreakInsert1(const GdbResultRecord &record, int index) void GdbEngine::attemptBreakpointSynchronization() { + // Non-lethal check for nested calls + static bool inBreakpointSychronization = false; + QTC_ASSERT(!inBreakpointSychronization, /**/); + inBreakpointSychronization = true; + BreakHandler *handler = qq->breakHandler(); - //qDebug() << "BREAKPOINT SYNCHRONIZATION "; foreach (BreakpointData *data, handler->takeRemovedBreakpoints()) { - //qDebug() << " SYNCHRONIZATION REMOVING" << data; QString bpNumber = data->bpNumber; + debugMessage(QString("DELETING BP %1 IN %2").arg(bpNumber) + .arg(data->markerFileName)); if (!bpNumber.trimmed().isEmpty()) - sendCommand("-break-delete " + bpNumber, BreakDelete, 0, true); - //else - // qDebug() << "BP HAS NO NUMBER: " << data->markerFileName; + sendCommand("-break-delete " + bpNumber, BreakDelete, QVariant(), + NeedsStop); delete data; } @@ -2178,13 +2207,13 @@ void GdbEngine::attemptBreakpointSynchronization() } } - if (updateNeeded) { - //interruptAndContinue(); - //sendListBreakpoints(); + if (!updateNeeded && m_waitingForBreakpointSynchronizationToContinue) { + m_waitingForBreakpointSynchronizationToContinue = false; + // we continue the execution + continueInferior(); } - if (!updateNeeded && q->status() == DebuggerProcessStartingUp) - qq->notifyStartupFinished(); + inBreakpointSychronization = false; } @@ -2297,6 +2326,18 @@ void GdbEngine::handleModulesList(const GdbResultRecord &record) } +////////////////////////////////////////////////////////////////////// +// +// Source files specific stuff +// +////////////////////////////////////////////////////////////////////// + +void GdbEngine::reloadSourceFiles() +{ + sendCommand("-file-list-exec-source-files", GdbQuerySources); +} + + ////////////////////////////////////////////////////////////////////// // // Stack specific stuff @@ -2526,7 +2567,7 @@ bool GdbEngine::supportsThreads() const static WatchData m_toolTip; static QString m_toolTipExpression; static QPoint m_toolTipPos; -static QHash m_toolTipCache; +static QMap m_toolTipCache; static bool hasLetterOrNumber(const QString &exp) { @@ -3472,8 +3513,6 @@ void GdbEngine::handleDumpCustomValue1(const GdbResultRecord &record, && msg.startsWith("The program being debugged stopped while") && msg.contains("qDumpObjectData440")) { // Fake full stop - sendCommand("-file-list-exec-source-files", GdbQuerySources); - sendCommand("-break-list", BreakList); sendCommand("p 0", GdbAsyncOutput2); // dummy return; } @@ -3603,7 +3642,7 @@ void GdbEngine::updateLocals() // '2' is 'list with type and value' sendSynchronizedCommand("-stack-list-locals 2", StackListLocals); // stage 2/2 - tryLoadCustomDumpers(); + //tryLoadCustomDumpers(); } void GdbEngine::handleStackListArguments(const GdbResultRecord &record) @@ -3654,7 +3693,7 @@ void GdbEngine::handleStackListLocals(const GdbResultRecord &record) void GdbEngine::setLocals(const QList &locals) { //qDebug() << m_varToType; - QHash seen; + QMap seen; foreach (const GdbMi &item, locals) { // Local variables of inlined code are reported as @@ -3949,74 +3988,66 @@ void GdbEngine::assignValueInDebugger(const QString &expression, const QString & sendCommand("-var-assign assign " + value, WatchVarAssign); } - void GdbEngine::tryLoadCustomDumpers() { if (m_dataDumperState != DataDumperUninitialized) return; PENDING_DEBUG("TRY LOAD CUSTOM DUMPERS"); - m_dataDumperState = DataDumperLoadTried; + m_dataDumperState = DataDumperUnavailable; #if defined(Q_OS_LINUX) QString lib = q->m_buildDir + "/qtc-gdbmacros/libgdbmacros.so"; - if (QFileInfo(lib).isExecutable()) { + if (QFileInfo(lib).exists()) { + m_dataDumperState = DataDumperLoadTried; //sendCommand("p dlopen"); - //if (qq->useFastStart()) - // sendCommand("set stop-on-solib-events 0"); QString flag = QString::number(RTLD_NOW); - sendSynchronizedCommand("call (void)dlopen(\"" + lib + "\", " + flag + ")", + sendCommand("sharedlibrary libc"); // for malloc + sendCommand("sharedlibrary libdl"); // for dlopen + sendCommand("call (void)dlopen(\"" + lib + "\", " + flag + ")", WatchDumpCustomSetup); // some older systems like CentOS 4.6 prefer this: - sendSynchronizedCommand("call (void)__dlopen(\"" + lib + "\", " + flag + ")", + sendCommand("call (void)__dlopen(\"" + lib + "\", " + flag + ")", WatchDumpCustomSetup); - sendSynchronizedCommand("sharedlibrary " + dotEscape(lib)); - //if (qq->useFastStart()) - // sendCommand("set stop-on-solib-events 1"); - } else { - qDebug() << "DEBUG HELPER LIBRARY IS NOT USABLE: " - << lib << QFileInfo(lib).isExecutable(); + sendCommand("sharedlibrary " + dotEscape(lib)); } #endif #if defined(Q_OS_MAC) QString lib = q->m_buildDir + "/qtc-gdbmacros/libgdbmacros.dylib"; - if (QFileInfo(lib).isExecutable()) { - //sendCommand("p dlopen"); // FIXME: remove me - //if (qq->useFastStart()) - // sendCommand("set stop-on-solib-events 0"); + if (QFileInfo(lib).exists()) { + m_dataDumperState = DataDumperLoadTried; + sendCommand("sharedlibrary libc"); // for malloc + sendCommand("sharedlibrary libdl"); // for dlopen QString flag = QString::number(RTLD_NOW); - sendSynchronizedCommand("call (void)dlopen(\"" + lib + "\", " + flag + ")", + sendCommand("call (void)dlopen(\"" + lib + "\", " + flag + ")", WatchDumpCustomSetup); - sendSynchronizedCommand("sharedlibrary " + dotEscape(lib)); - //if (qq->useFastStart()) - // sendCommand("set stop-on-solib-events 1"); - } else { - qDebug() << "DEBUG HELPER LIBRARY IS NOT USABLE: " - << lib << QFileInfo(lib).isExecutable(); + sendCommand("sharedlibrary " + dotEscape(lib)); } #endif #if defined(Q_OS_WIN) QString lib = q->m_buildDir + "/qtc-gdbmacros/debug/gdbmacros.dll"; if (QFileInfo(lib).exists()) { - //if (qq->useFastStart()) - // sendCommand("set stop-on-solib-events 0"); + m_dataDumperState = DataDumperLoadTried; + sendCommand("sharedlibrary .*"); // for LoadLibraryA //sendCommand("handle SIGSEGV pass stop print"); //sendCommand("set unwindonsignal off"); - sendSynchronizedCommand("call LoadLibraryA(\"" + lib + "\")", + sendCommand("call LoadLibraryA(\"" + lib + "\")", WatchDumpCustomSetup); - sendSynchronizedCommand("sharedlibrary " + dotEscape(lib)); - //if (qq->useFastStart()) - // sendCommand("set stop-on-solib-events 1"); - } else { - qDebug() << "DEBUG HELPER LIBRARY IS NOT USABLE: " - << lib << QFileInfo(lib).isExecutable(); + sendCommand("sharedlibrary " + dotEscape(lib)); } #endif - // retreive list of dumpable classes - sendSynchronizedCommand("call qDumpObjectData440(1,%1+1,0,0,0,0,0,0)", - GdbQueryDataDumper1); - sendSynchronizedCommand("p (char*)qDumpOutBuffer", GdbQueryDataDumper2); + if (m_dataDumperState == DataDumperLoadTried) { + // retreive list of dumpable classes + sendCommand("call qDumpObjectData440(1,%1+1,0,0,0,0,0,0)", + GdbQueryDataDumper1); + sendCommand("p (char*)qDumpOutBuffer", GdbQueryDataDumper2); + } else { + gdbOutputAvailable("", QString("DEBUG HELPER LIBRARY IS NOT USABLE: " + " %1 EXISTS: %2, EXECUTABLE: %3").arg(lib) + .arg(QFileInfo(lib).exists()) + .arg(QFileInfo(lib).isExecutable())); + } } diff --git a/src/plugins/debugger/gdbengine.h b/src/plugins/debugger/gdbengine.h index a603aee375d..43b87b873c8 100644 --- a/src/plugins/debugger/gdbengine.h +++ b/src/plugins/debugger/gdbengine.h @@ -113,7 +113,6 @@ private: void exitDebugger(); void continueInferior(); - void runInferior(); void interruptInferior(); void runToLineExec(const QString &fileName, int lineNumber); @@ -145,7 +144,8 @@ private: bool supportsThreads() const; - void init(); // called by destructor + void initializeConnections(); + void initializeVariables(); void queryFullName(const QString &fileName, QString *fullName); QString fullName(const QString &fileName); QString shortName(const QString &fullName); @@ -158,12 +158,15 @@ private: // queue". resultNeeded == true increments m_pendingResults on // send and decrements on receipt, effectively preventing // watch model updates before everything is finished. - void sendCommand(const QString & command, + enum StopNeeded { DoesNotNeedStop, NeedsStop }; + enum Synchronization { NotSynchronized, Synchronized }; + void sendCommand(const QString &command, int type = 0, const QVariant &cookie = QVariant(), - bool needStop = false, bool synchronized = false); + StopNeeded needStop = DoesNotNeedStop, + Synchronization synchronized = NotSynchronized); void sendSynchronizedCommand(const QString & command, int type = 0, const QVariant &cookie = QVariant(), - bool needStop = false); + StopNeeded needStop = DoesNotNeedStop); void setTokenBarrier(); @@ -179,7 +182,7 @@ private slots: private: int terminationIndex(const QByteArray &buffer, int &length); - void handleStreamOutput(const QString &output, char code); + void handleStart(const GdbResultRecord &response); void handleAsyncOutput2(const GdbMi &data); void handleAsyncOutput(const GdbMi &data); void handleResultRecord(const GdbResultRecord &response); @@ -189,9 +192,11 @@ private: void handleExecRunToFunction(const GdbResultRecord &response); void handleInfoShared(const GdbResultRecord &response); void handleInfoProc(const GdbResultRecord &response); + void handleInfoThreads(const GdbResultRecord &response); void handleShowVersion(const GdbResultRecord &response); void handleQueryPwd(const GdbResultRecord &response); void handleQuerySources(const GdbResultRecord &response); + void debugMessage(const QString &msg); OutputCollector m_outputCollector; QTextCodec *m_outputCodec; @@ -215,11 +220,10 @@ private: int m_oldestAcceptableToken; int m_gdbVersion; // 6.8.0 is 680 - int m_shared; // awful hack to keep track of used files - QHash m_shortToFullName; - QHash m_fullToShortName; + QMap m_shortToFullName; + QMap m_fullToShortName; // // Breakpoint specific stuff @@ -259,6 +263,10 @@ private: void handleRegisterListNames(const GdbResultRecord &record); void handleRegisterListValues(const GdbResultRecord &record); + // + // Source file specific stuff + // + void reloadSourceFiles(); // // Stack specific stuff @@ -330,6 +338,12 @@ private: QString m_currentFrame; QMap m_varToType; + bool m_waitingForBreakpointSynchronizationToContinue; + bool m_waitingForFirstBreakpointToBeHit; + bool m_modulesListOutdated; + + QList m_commandsToRunOnTemporaryBreak; + DebuggerManager *q; IDebuggerManagerAccessForEngines *qq; }; diff --git a/src/plugins/debugger/gdboptionpage.ui b/src/plugins/debugger/gdboptionpage.ui index ef485ccbf83..884080c1a30 100644 --- a/src/plugins/debugger/gdboptionpage.ui +++ b/src/plugins/debugger/gdboptionpage.ui @@ -6,26 +6,20 @@ 0 0 - 465 - 372 + 398 + 385 Form - - - 6 - - - 9 - - - + + + Locations - + 9 @@ -74,7 +68,70 @@ - + + + + Behaviour of breakpoint setting in plugins + + + + + + This is the slowest but safest option. + + + Try to set breakpoints in plugins always automatically. + + + + + + + Try to set breakpoints in selected plugins + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 10 + 10 + + + + + + + + Matching regular expression: + + + + + + + + + + + + Never set breakpoints in plugins automatically + + + + + + + Checking this will make the debugger try to use code to format certain data (QObject, QString, std::string etc.) nicely. @@ -84,17 +141,7 @@ - - - - Checking this will make the debugger start fast by loading only very few debug symbols on start up. This might lead to situations where breakpoints can not be set properly. So uncheck this option if you experience breakpoint related problems. - - - Fast debugger start - - - - + When this option is checked, 'Step Into' compresses several steps into one in certain situations, leading to 'less noisy' debugging. So will, e.g., the atomic @@ -105,7 +152,7 @@ - + Checking this will make enable tooltips for variable values during debugging. Since this can slow down debugging and does not provide reliable information as it does not use scope information, it is switched off by default. @@ -115,7 +162,7 @@ - + This is an internal tool to make debugging the Custom Data Dumper code easier. Using this action is in general not needed unless you want do debug Qt Creator itself. @@ -125,29 +172,15 @@ - - - - Auto run executable on debugger startup - - - - - - - Quit debugger when the executable exits - - - - - + + Qt::Vertical - 415 - 41 + 10 + 1 diff --git a/src/plugins/debugger/idebuggerengine.h b/src/plugins/debugger/idebuggerengine.h index 1558d140ee6..6da7ecb15ed 100644 --- a/src/plugins/debugger/idebuggerengine.h +++ b/src/plugins/debugger/idebuggerengine.h @@ -62,7 +62,6 @@ public: virtual void nextIExec() = 0; virtual void continueInferior() = 0; - virtual void runInferior() = 0; virtual void interruptInferior() = 0; virtual void runToLineExec(const QString &fileName, int lineNumber) = 0; @@ -88,6 +87,8 @@ public: virtual void reloadRegisters() = 0; virtual void setDebugDumpers(bool on) = 0; virtual void setUseCustomDumpers(bool on) = 0; + + virtual void reloadSourceFiles() = 0; }; } // namespace Internal diff --git a/src/plugins/debugger/moduleshandler.cpp b/src/plugins/debugger/moduleshandler.cpp index e87c92a73d2..a49e87495ec 100644 --- a/src/plugins/debugger/moduleshandler.cpp +++ b/src/plugins/debugger/moduleshandler.cpp @@ -33,7 +33,7 @@ #include "moduleshandler.h" -#include "assert.h" +#include #include #include diff --git a/src/plugins/debugger/outputcollector.cpp b/src/plugins/debugger/outputcollector.cpp index f091ca92084..d97f28ff0d9 100644 --- a/src/plugins/debugger/outputcollector.cpp +++ b/src/plugins/debugger/outputcollector.cpp @@ -80,7 +80,7 @@ bool OutputCollector::listen() return m_server->isListening(); m_server = new QLocalServer(this); connect(m_server, SIGNAL(newConnection()), SLOT(newConnectionAvailable())); - return m_server->listen(QLatin1String("creator-") + QCoreApplication::applicationPid()); // XXX how to make that secure? + return m_server->listen(QString::fromLatin1("creator-%1").arg(QCoreApplication::applicationPid())); // XXX how to make that secure? #else if (!m_serverPath.isEmpty()) return true; diff --git a/src/plugins/debugger/registerhandler.cpp b/src/plugins/debugger/registerhandler.cpp index e594326009a..9300e5a4df7 100644 --- a/src/plugins/debugger/registerhandler.cpp +++ b/src/plugins/debugger/registerhandler.cpp @@ -33,9 +33,10 @@ #include "registerhandler.h" -#include "assert.h" #include "debuggerconstants.h" +#include + #include #include diff --git a/src/plugins/debugger/scriptengine.cpp b/src/plugins/debugger/scriptengine.cpp index b868dcd99ad..0af40332273 100644 --- a/src/plugins/debugger/scriptengine.cpp +++ b/src/plugins/debugger/scriptengine.cpp @@ -216,7 +216,6 @@ bool ScriptEngine::startDebugger() m_scriptContents = stream.readAll(); scriptFile.close(); attemptBreakpointSynchronization(); - QTimer::singleShot(0, q, SLOT(notifyStartupFinished())); return true; } diff --git a/src/plugins/debugger/scriptengine.h b/src/plugins/debugger/scriptengine.h index b7f37f2cc67..8368d367e82 100644 --- a/src/plugins/debugger/scriptengine.h +++ b/src/plugins/debugger/scriptengine.h @@ -112,6 +112,7 @@ private: void reloadDisassembler(); void reloadModules(); void reloadRegisters() {} + void reloadSourceFiles() {} bool supportsThreads() const { return true; } void maybeBreakNow(bool byFunction); diff --git a/src/plugins/debugger/sourcefileswindow.cpp b/src/plugins/debugger/sourcefileswindow.cpp new file mode 100644 index 00000000000..17b68a1c775 --- /dev/null +++ b/src/plugins/debugger/sourcefileswindow.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.3, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#include "sourcefileswindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using Debugger::Internal::SourceFilesWindow; +using Debugger::Internal::SourceFilesModel; + +////////////////////////////////////////////////////////////////// +// +// SourceFilesModel +// +////////////////////////////////////////////////////////////////// + +class Debugger::Internal::SourceFilesModel : public QAbstractItemModel +{ +public: + SourceFilesModel(QObject *parent = 0) : QAbstractItemModel(parent) {} + + // QAbstractItemModel + int columnCount(const QModelIndex &parent) const + { return parent.isValid() ? 0 : 2; } + int rowCount(const QModelIndex &parent) const + { return parent.isValid() ? 0 : m_shortNames.size(); } + QModelIndex parent(const QModelIndex &) const { return QModelIndex(); } + QModelIndex index(int row, int column, const QModelIndex &) const + { return createIndex(row, column); } + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); + Qt::ItemFlags flags(const QModelIndex &index) const; + + void clearModel(); + void update() { reset(); } + void setSourceFiles(const QMap &sourceFiles); + +public: + QStringList m_shortNames; + QStringList m_fullNames; +}; + +void SourceFilesModel::clearModel() +{ + if (m_shortNames.isEmpty()) + return; + m_shortNames.clear(); + m_fullNames.clear(); + reset(); +} + +QVariant SourceFilesModel::headerData(int section, + Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + static QString headers[] = { + tr("Internal name") + " ", + tr("Full name") + " ", + }; + return headers[section]; + } + return QVariant(); +} + +Qt::ItemFlags SourceFilesModel::flags(const QModelIndex &index) const +{ + if (index.row() >= m_fullNames.size()) + return 0; + QFileInfo fi(m_fullNames.at(index.row())); + return fi.isReadable() ? QAbstractItemModel::flags(index) : Qt::ItemFlags(0); +} + +QVariant SourceFilesModel::data(const QModelIndex &index, int role) const +{ + //static const QIcon icon(":/gdbdebugger/images/breakpoint.svg"); + //static const QIcon icon2(":/gdbdebugger/images/breakpoint_pending.svg"); + + int row = index.row(); + if (row < 0 || row >= m_shortNames.size()) + return QVariant(); + + switch (index.column()) { + case 0: + if (role == Qt::DisplayRole) + return m_shortNames.at(row); + // FIXME: add icons + //if (role == Qt::DecorationRole) + // return module.symbolsRead ? icon2 : icon; + break; + case 1: + if (role == Qt::DisplayRole) + return m_fullNames.at(row); + //if (role == Qt::DecorationRole) + // return module.symbolsRead ? icon2 : icon; + break; + } + return QVariant(); +} + +bool SourceFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + return QAbstractItemModel::setData(index, value, role); +} + +void SourceFilesModel::setSourceFiles(const QMap &sourceFiles) +{ + m_shortNames.clear(); + m_fullNames.clear(); + QMap::ConstIterator it = sourceFiles.begin(); + QMap::ConstIterator et = sourceFiles.end(); + for (; it != et; ++it) { + m_shortNames.append(it.key()); + m_fullNames.append(it.value()); + } + reset(); +} + +////////////////////////////////////////////////////////////////// +// +// SourceFilesWindow +// +////////////////////////////////////////////////////////////////// + +SourceFilesWindow::SourceFilesWindow(QWidget *parent) + : QTreeView(parent) +{ + m_model = new SourceFilesModel(this); + + QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); + proxyModel->setSourceModel(m_model); + setModel(proxyModel); + + setWindowTitle(tr("Source Files")); + setSortingEnabled(true); + setAlternatingRowColors(true); + setRootIsDecorated(false); + setIconSize(QSize(10, 10)); + //header()->setDefaultAlignment(Qt::AlignLeft); + + connect(this, SIGNAL(activated(QModelIndex)), + this, SLOT(sourceFileActivated(QModelIndex))); +} + +SourceFilesWindow::~SourceFilesWindow() +{ +} + +void SourceFilesWindow::sourceFileActivated(const QModelIndex &index) +{ + qDebug() << "ACTIVATED: " << index.row() << index.column(); +} + +void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu menu; + QAction *act1 = new QAction(tr("Reload data"), &menu); + //act1->setCheckable(true); + + menu.addAction(act1); + + QAction *act = menu.exec(ev->globalPos()); + + if (act == act1) { + emit reloadSourceFilesRequested(); + } +} + +void SourceFilesWindow::setSourceFiles(const QMap &sourceFiles) +{ + m_model->setSourceFiles(sourceFiles); + header()->setResizeMode(0, QHeaderView::ResizeToContents); +} diff --git a/src/plugins/debugger/sourcefileswindow.h b/src/plugins/debugger/sourcefileswindow.h new file mode 100644 index 00000000000..4d17d0cb1e9 --- /dev/null +++ b/src/plugins/debugger/sourcefileswindow.h @@ -0,0 +1,76 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.3, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#ifndef DEBUGGER_SOURCEFILEWINDOW_H +#define DEBUGGER_SOURCEFILEWINDOW_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QComboBox; +class QModelIndex; +class QStandardItemModel; +QT_END_NAMESPACE + +namespace Debugger { +namespace Internal { + +class SourceFilesModel; + +class SourceFilesWindow : public QTreeView +{ + Q_OBJECT + +public: + SourceFilesWindow(QWidget *parent = 0); + ~SourceFilesWindow(); + + void setSourceFiles(const QMap &sourceFiles); + +signals: + void reloadSourceFilesRequested(); + +private slots: + void sourceFileActivated(const QModelIndex &index); + +private: + void contextMenuEvent(QContextMenuEvent *ev); + SourceFilesModel *m_model; +}; + +} // namespace Internal +} // namespace Debugger + +#endif // DEBUGGER_SOURCEFILEWINDOW_H + diff --git a/src/plugins/debugger/stackwindow.cpp b/src/plugins/debugger/stackwindow.cpp index d40f8a3c5ff..8b33b08ae7c 100644 --- a/src/plugins/debugger/stackwindow.cpp +++ b/src/plugins/debugger/stackwindow.cpp @@ -33,9 +33,10 @@ #include "stackwindow.h" -#include "assert.h" #include "stackhandler.h" +#include + #include #include #include diff --git a/src/plugins/debugger/threadswindow.cpp b/src/plugins/debugger/threadswindow.cpp index bf418cd0fc5..5d49e5dc798 100644 --- a/src/plugins/debugger/threadswindow.cpp +++ b/src/plugins/debugger/threadswindow.cpp @@ -33,9 +33,10 @@ #include "threadswindow.h" -#include "assert.h" #include "stackhandler.h" +#include + #include #include #include diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index a00b7fad7ce..0068d364a86 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -790,9 +790,9 @@ void WatchHandler::collapseChildren(const QModelIndex &idx) return; } QTC_ASSERT(checkIndex(idx.internalId()), return); -#if 0 QString iname0 = m_displaySet.at(idx.internalId()).iname; MODEL_DEBUG("COLLAPSE NODE" << iname0); +#if 0 QString iname1 = iname0 + '.'; for (int i = m_completeSet.size(); --i >= 0; ) { QString iname = m_completeSet.at(i).iname; @@ -803,10 +803,10 @@ void WatchHandler::collapseChildren(const QModelIndex &idx) m_expandedINames.remove(iname); } } +#endif m_expandedINames.remove(iname0); //MODEL_DEBUG(toString()); //rebuildModel(); -#endif } void WatchHandler::expandChildren(const QModelIndex &idx) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index fe2394c019d..08bdac4ee60 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -207,20 +207,20 @@ void GitClient::diff(const QString &workingDirectory, QStringList arguments; arguments << QLatin1String("diff") << diffArgs; m_plugin->outputWindow()->append(formatCommand(binary, arguments)); - command->addJob(arguments); + command->addJob(arguments, m_settings.timeout); } else { // Files diff. if (!unstagedFileNames.empty()) { QStringList arguments; arguments << QLatin1String("diff") << diffArgs << QLatin1String("--") << unstagedFileNames; m_plugin->outputWindow()->append(formatCommand(binary, arguments)); - command->addJob(arguments); + command->addJob(arguments, m_settings.timeout); } if (!stagedFileNames.empty()) { QStringList arguments; arguments << QLatin1String("diff") << QLatin1String("--cached") << diffArgs << QLatin1String("--") << stagedFileNames; m_plugin->outputWindow()->append(formatCommand(binary, arguments)); - command->addJob(arguments); + command->addJob(arguments, m_settings.timeout); } } command->execute(); @@ -503,7 +503,7 @@ void GitClient::executeGit(const QString &workingDirectory, { m_plugin->outputWindow()->append(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments)); GitCommand *command = createCommand(workingDirectory, editor, outputToWindow); - command->addJob(arguments); + command->addJob(arguments, m_settings.timeout); command->execute(); } diff --git a/src/plugins/git/gitcommand.cpp b/src/plugins/git/gitcommand.cpp index fa62401b011..8362926cecc 100644 --- a/src/plugins/git/gitcommand.cpp +++ b/src/plugins/git/gitcommand.cpp @@ -55,8 +55,9 @@ static inline QStringList environmentToList(const ProjectExplorer::Environment & return ProjectExplorer::Environment::systemEnvironment().toStringList(); } -GitCommand::Job::Job(const QStringList &a) : - arguments(a) +GitCommand::Job::Job(const QStringList &a, int t) : + arguments(a), + timeout(t) { } @@ -67,9 +68,9 @@ GitCommand::GitCommand(const QString &workingDirectory, { } -void GitCommand::addJob(const QStringList &arguments) +void GitCommand::addJob(const QStringList &arguments, int timeout) { - m_jobs.push_back(Job(arguments)); + m_jobs.push_back(Job(arguments, timeout)); } void GitCommand::execute() @@ -109,7 +110,7 @@ void GitCommand::run() qDebug() << "GitCommand::run" << j << '/' << count << m_jobs.at(j).arguments; process.start(QLatin1String(Constants::GIT_BINARY), m_jobs.at(j).arguments); - if (!process.waitForFinished()) { + if (!process.waitForFinished(m_jobs.at(j).timeout * 1000)) { ok = false; error += QLatin1String("Error: Git timed out"); break; diff --git a/src/plugins/git/gitcommand.h b/src/plugins/git/gitcommand.h index a587b748761..32b76bf3485 100644 --- a/src/plugins/git/gitcommand.h +++ b/src/plugins/git/gitcommand.h @@ -49,7 +49,7 @@ public: ProjectExplorer::Environment &environment); - void addJob(const QStringList &arguments); + void addJob(const QStringList &arguments, int timeout); void execute(); private: @@ -61,9 +61,10 @@ Q_SIGNALS: private: struct Job { - explicit Job(const QStringList &a); + explicit Job(const QStringList &a, int t); QStringList arguments; + int timeout; }; QStringList environment() const; diff --git a/src/plugins/git/gitsettings.cpp b/src/plugins/git/gitsettings.cpp index 2b528a72d2a..02a1acc1d9e 100644 --- a/src/plugins/git/gitsettings.cpp +++ b/src/plugins/git/gitsettings.cpp @@ -40,15 +40,17 @@ static const char *groupC = "Git"; static const char *sysEnvKeyC = "SysEnv"; static const char *pathKeyC = "Path"; static const char *logCountKeyC = "LogCount"; +static const char *timeoutKeyC = "TimeOut"; -enum { defaultLogCount = 10 }; +enum { defaultLogCount = 10 , defaultTimeOut = 30}; namespace Git { namespace Internal { GitSettings::GitSettings() : adoptPath(false), - logCount(defaultLogCount) + logCount(defaultLogCount), + timeout(defaultTimeOut) { } @@ -58,6 +60,7 @@ void GitSettings::fromSettings(QSettings *settings) adoptPath = settings->value(QLatin1String(sysEnvKeyC), false).toBool(); path = settings->value(QLatin1String(pathKeyC), QString()).toString(); logCount = settings->value(QLatin1String(logCountKeyC), defaultLogCount).toInt(); + timeout = settings->value(QLatin1String(timeoutKeyC), defaultTimeOut).toInt(); settings->endGroup(); } @@ -67,12 +70,13 @@ void GitSettings::toSettings(QSettings *settings) const settings->setValue(QLatin1String(sysEnvKeyC), adoptPath); settings->setValue(QLatin1String(pathKeyC), path); settings->setValue(QLatin1String(logCountKeyC), logCount); + settings->setValue(QLatin1String(timeoutKeyC), timeout); settings->endGroup(); } bool GitSettings::equals(const GitSettings &s) const { - return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount; + return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount && timeout == s.timeout; } } diff --git a/src/plugins/git/gitsettings.h b/src/plugins/git/gitsettings.h index 59169922605..c2463eb326d 100644 --- a/src/plugins/git/gitsettings.h +++ b/src/plugins/git/gitsettings.h @@ -56,6 +56,7 @@ struct GitSettings bool adoptPath; QString path; int logCount; + int timeout; }; inline bool operator==(const GitSettings &p1, const GitSettings &p2) diff --git a/src/plugins/git/settingspage.cpp b/src/plugins/git/settingspage.cpp index a3b82194cec..121c7cd889b 100644 --- a/src/plugins/git/settingspage.cpp +++ b/src/plugins/git/settingspage.cpp @@ -52,6 +52,7 @@ GitSettings SettingsPageWidget::settings() const rc.path = m_ui.pathLineEdit->text(); rc.adoptPath = m_ui.environmentGroupBox->isChecked() && !rc.path.isEmpty(); rc.logCount = m_ui.logCountSpinBox->value(); + rc.timeout = m_ui.timeoutSpinBox->value(); return rc; } @@ -60,6 +61,7 @@ void SettingsPageWidget::setSettings(const GitSettings &s) m_ui.environmentGroupBox->setChecked(s.adoptPath); m_ui.pathLineEdit->setText(s.path); m_ui.logCountSpinBox->setValue(s.logCount); + m_ui.timeoutSpinBox->setValue(s.timeout); } void SettingsPageWidget::setSystemPath() diff --git a/src/plugins/git/settingspage.ui b/src/plugins/git/settingspage.ui index 94c04493aab..1a594bf4313 100644 --- a/src/plugins/git/settingspage.ui +++ b/src/plugins/git/settingspage.ui @@ -7,7 +7,7 @@ 0 0 403 - 183 + 251 @@ -69,10 +69,14 @@ - - - QFormLayout::ExpandingFieldsGrow - + + + + + Log commit display count: + + + @@ -83,10 +87,23 @@ - - + + - Log commit display count: + Timeout (seconds): + + + + + + + 10 + + + 300 + + + 30 diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 7d126c4bb94..b4685419c08 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -221,7 +221,6 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess m_coreListener = new CoreListener(this); addObject(m_coreListener); - //register actions Core::ActionManager *am = Core::ICore::instance()->actionManager(); @@ -682,6 +681,8 @@ void PerforcePlugin::updateActions() bool PerforcePlugin::managesDirectory(const QString &directory) const { + if (!checkP4Command()) + return false; const QString p4Path = directory + QLatin1String("/..."); QStringList args; args << QLatin1String("fstat") << QLatin1String("-m1") << p4Path; @@ -758,7 +759,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args, tempfile.setAutoRemove(true); const QChar newLine = QLatin1Char('\n'); const QChar blank = QLatin1Char(' '); - QStringList actualArgs = basicP4Args(); + QStringList actualArgs = m_settings.basicP4Args(); if (!extraArgs.isEmpty()) { if (tempfile.open()) { QTextStream stream(&tempfile); @@ -773,7 +774,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args, actualArgs << args; if (logFlags & CommandToWindow) { - QString command = m_settings.p4Command; + QString command = m_settings.p4Command(); command += blank; command += actualArgs.join(QString(blank)); const QString timeStamp = QTime::currentTime().toString(QLatin1String("HH:mm")); @@ -799,7 +800,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args, connect(&process, SIGNAL(stdOutBuffered(QString,bool)), m_perforceOutputWindow, SLOT(append(QString,bool))); } - const Core::Utils::SynchronousProcessResponse sp_resp = process.run(m_settings.p4Command, actualArgs); + const Core::Utils::SynchronousProcessResponse sp_resp = process.run(m_settings.p4Command(), actualArgs); if (Perforce::Constants::debug) qDebug() << sp_resp; @@ -817,7 +818,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args, response.message = tr("The process terminated abnormally."); break; case Core::Utils::SynchronousProcessResponse::StartFailed: - response.message = tr("Could not start perforce '%1'. Please check your settings in the preferences.").arg(m_settings.p4Command); + response.message = tr("Could not start perforce '%1'. Please check your settings in the preferences.").arg(m_settings.p4Command()); break; case Core::Utils::SynchronousProcessResponse::Hang: response.message = tr("Perforce did not respond within timeout limit (%1 ms).").arg(p4Timeout ); @@ -969,8 +970,8 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor) proc.setEnvironment(environment()); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - proc.start(m_settings.p4Command, - basicP4Args() << QLatin1String("submit") << QLatin1String("-i")); + proc.start(m_settings.p4Command(), + m_settings.basicP4Args() << QLatin1String("submit") << QLatin1String("-i")); if (!proc.waitForStarted(p4Timeout)) { showOutput(tr("Cannot execute p4 submit."), true); QApplication::restoreOverrideCursor(); @@ -1018,8 +1019,8 @@ QString PerforcePlugin::clientFilePath(const QString &serverFilePath) QApplication::setOverrideCursor(Qt::WaitCursor); QProcess proc; proc.setEnvironment(environment()); - proc.start(m_settings.p4Command, - basicP4Args() << QLatin1String("fstat") << serverFilePath); + proc.start(m_settings.p4Command(), + m_settings.basicP4Args() << QLatin1String("fstat") << serverFilePath); QString path; if (proc.waitForFinished(3000)) { @@ -1047,22 +1048,9 @@ QString PerforcePlugin::currentFileName() return fileName; } -QStringList PerforcePlugin::basicP4Args() const -{ - QStringList lst; - if (!m_settings.defaultEnv) { - lst << QLatin1String("-c") << m_settings.p4Client; - lst << QLatin1String("-p") << m_settings.p4Port; - lst << QLatin1String("-u") << m_settings.p4User; - } - return lst; -} - bool PerforcePlugin::checkP4Command() const { - if (m_settings.p4Command.isEmpty()) - return false; - return true; + return m_settings.isValid(); } QString PerforcePlugin::pendingChangesData() @@ -1074,8 +1062,8 @@ QString PerforcePlugin::pendingChangesData() QString user; QProcess proc; proc.setEnvironment(environment()); - proc.start(m_settings.p4Command, - basicP4Args() << QLatin1String("info")); + proc.start(m_settings.p4Command(), + m_settings.basicP4Args() << QLatin1String("info")); if (proc.waitForFinished(3000)) { QString output = QString::fromUtf8(proc.readAllStandardOutput()); if (!output.isEmpty()) { @@ -1087,8 +1075,8 @@ QString PerforcePlugin::pendingChangesData() } if (user.isEmpty()) return data; - proc.start(m_settings.p4Command, - basicP4Args() << QLatin1String("changes") << QLatin1String("-s") << QLatin1String("pending") << QLatin1String("-u") << user); + proc.start(m_settings.p4Command(), + m_settings.basicP4Args() << QLatin1String("changes") << QLatin1String("-s") << QLatin1String("pending") << QLatin1String("-u") << user); if (proc.waitForFinished(3000)) data = QString::fromUtf8(proc.readAllStandardOutput()); return data; @@ -1139,17 +1127,24 @@ PerforcePlugin::~PerforcePlugin() } } -PerforceSettings PerforcePlugin::settings() const +const PerforceSettings& PerforcePlugin::settings() const { return m_settings; } -void PerforcePlugin::setSettings(const PerforceSettings &s) +void PerforcePlugin::setSettings(const QString &p4Command, const QString &p4Port, const QString &p4Client, const QString p4User, bool defaultEnv) { - if (s != m_settings) { - m_settings = s; - if (QSettings *settings = Core::ICore::instance()->settings()) - m_settings.toSettings(settings); + + if (m_settings.p4Command() == p4Command + && m_settings.p4Port() == p4Port + && m_settings.p4Client() == p4Client + && m_settings.p4User() == p4User + && m_settings.defaultEnv() == defaultEnv) + { + // Nothing to do + } else { + m_settings.setSettings(p4Command, p4Port, p4Client, p4User, defaultEnv); + m_settings.toSettings(Core::ICore::instance()->settings()); } } @@ -1162,9 +1157,9 @@ QString PerforcePlugin::fileNameFromPerforceName(const QString& perforceName, return perforceName; // "where" remaps the file to client file tree QProcess proc; - QStringList args(basicP4Args()); + QStringList args(m_settings.basicP4Args()); args << QLatin1String("where") << perforceName; - proc.start(m_settings.p4Command, args); + proc.start(m_settings.p4Command(), args); if (!proc.waitForFinished()) { *errorMessage = tr("Timeout waiting for \"where\" (%1).").arg(perforceName); return QString(); diff --git a/src/plugins/perforce/perforceplugin.h b/src/plugins/perforce/perforceplugin.h index e5985a28ab5..d856685bba9 100644 --- a/src/plugins/perforce/perforceplugin.h +++ b/src/plugins/perforce/perforceplugin.h @@ -93,7 +93,6 @@ public: PerforcePlugin(); ~PerforcePlugin(); - QStringList basicP4Args() const; SettingsPage *settingsPage() const { return m_settingsPage; } bool initialize(const QStringList &arguments, QString *error_message); @@ -113,8 +112,8 @@ public: static PerforcePlugin *perforcePluginInstance(); - PerforceSettings settings() const; - void setSettings(const PerforceSettings &s); + const PerforceSettings& settings() const; + void setSettings(const QString &p4Command, const QString &p4Port, const QString &p4Client, const QString p4User, bool defaultEnv); // Map a perforce name "//xx" to its real name in the file system QString fileNameFromPerforceName(const QString& perforceName, QString *errorMessage) const; diff --git a/src/plugins/perforce/perforcesettings.cpp b/src/plugins/perforce/perforcesettings.cpp index 7ba51b78e00..b30d12a4145 100644 --- a/src/plugins/perforce/perforcesettings.cpp +++ b/src/plugins/perforce/perforcesettings.cpp @@ -33,7 +33,11 @@ #include "perforcesettings.h" +#include +#include #include +#include +#include static const char *groupC = "Perforce"; static const char *commandKeyC = "Command"; @@ -55,41 +59,134 @@ static QString defaultCommand() namespace Perforce { namespace Internal { -PerforceSettings::PerforceSettings() : - p4Command(defaultCommand()), - defaultEnv(true) +PerforceSettings::PerforceSettings() + : m_valid(false) { + // We do all the initialization in fromSettings +} + +PerforceSettings::~PerforceSettings() +{ + // ensure that we are not still running + m_future.waitForFinished(); +} + +bool PerforceSettings::isValid() const +{ + m_future.waitForFinished(); + m_mutex.lock(); + bool valid = m_valid; + m_mutex.unlock(); + return valid; +} + +void PerforceSettings::run(QFutureInterface &fi) +{ + m_mutex.lock(); + QString executable = m_p4Command; + QStringList arguments = basicP4Args(); + m_mutex.unlock(); + + // TODO actually check + bool valid = true; + + QProcess p4; + p4.start(m_p4Command, QStringList() << "client"<<"-o"); + p4.waitForFinished(2000); + if (p4.state() != QProcess::NotRunning) { + p4.kill(); + p4.waitForFinished(); + valid = false; + } else { + QString response = p4.readAllStandardOutput(); + if (!response.contains("View:")) + valid = false; + } + + m_mutex.lock(); + if (executable == m_p4Command && arguments == basicP4Args()) // Check that those settings weren't changed in between + m_valid = valid; + m_mutex.unlock(); + fi.reportFinished(); } void PerforceSettings::fromSettings(QSettings *settings) { + m_mutex.lock(); settings->beginGroup(QLatin1String(groupC)); - p4Command = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString(); - defaultEnv = settings->value(QLatin1String(defaultKeyC), true).toBool(); - p4Port = settings->value(QLatin1String(portKeyC), QString()).toString(); - p4Client = settings->value(QLatin1String(clientKeyC), QString()).toString(); - p4User = settings->value(QLatin1String(userKeyC), QString()).toString(); + m_p4Command = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString(); + m_defaultEnv = settings->value(QLatin1String(defaultKeyC), true).toBool(); + m_p4Port = settings->value(QLatin1String(portKeyC), QString()).toString(); + m_p4Client = settings->value(QLatin1String(clientKeyC), QString()).toString(); + m_p4User = settings->value(QLatin1String(userKeyC), QString()).toString(); settings->endGroup(); + m_mutex.unlock(); + m_future = QtConcurrent::run(&PerforceSettings::run, this); } void PerforceSettings::toSettings(QSettings *settings) const { + m_mutex.lock(); settings->beginGroup(QLatin1String(groupC)); - settings->setValue(commandKeyC, p4Command); - settings->setValue(defaultKeyC, defaultEnv); - settings->setValue(portKeyC, p4Port); - settings->setValue(clientKeyC, p4Client); - settings->setValue(userKeyC, p4User); + settings->setValue(commandKeyC, m_p4Command); + settings->setValue(defaultKeyC, m_defaultEnv); + settings->setValue(portKeyC, m_p4Port); + settings->setValue(clientKeyC, m_p4Client); + settings->setValue(userKeyC, m_p4User); settings->endGroup(); + m_mutex.unlock(); } -bool PerforceSettings::equals(const PerforceSettings &s) const +void PerforceSettings::setSettings(const QString &p4Command, const QString &p4Port, const QString &p4Client, const QString p4User, bool defaultEnv) { - return p4Command == s.p4Command && p4Port == s.p4Port - && p4Client == s.p4Client && p4User == s.p4User - && defaultEnv == s.defaultEnv; + m_mutex.lock(); + m_p4Command = p4Command; + m_p4Port = p4Port; + m_p4Client = p4Client; + m_p4User = p4User; + m_defaultEnv = defaultEnv; + m_valid = false; + m_mutex.unlock(); + m_future = QtConcurrent::run(&PerforceSettings::run, this); } +QString PerforceSettings::p4Command() const +{ + return m_p4Command; +} + +QString PerforceSettings::p4Port() const +{ + return m_p4Port; +} + +QString PerforceSettings::p4Client() const +{ + return m_p4Client; +} + +QString PerforceSettings::p4User() const +{ + return m_p4User; +} + +bool PerforceSettings::defaultEnv() const +{ + return m_defaultEnv; +} + +QStringList PerforceSettings::basicP4Args() const +{ + QStringList lst; + if (!m_defaultEnv) { + lst << QLatin1String("-c") << m_p4Client; + lst << QLatin1String("-p") << m_p4Port; + lst << QLatin1String("-u") << m_p4User; + } + return lst; +} + + } // Internal } // Perforce diff --git a/src/plugins/perforce/perforcesettings.h b/src/plugins/perforce/perforcesettings.h index 4451d4ad617..0ca1147f4f3 100644 --- a/src/plugins/perforce/perforcesettings.h +++ b/src/plugins/perforce/perforcesettings.h @@ -35,6 +35,7 @@ #define PERFOCESETTINGS_H #include +#include QT_BEGIN_NAMESPACE class QSettings; @@ -43,24 +44,35 @@ QT_END_NAMESPACE namespace Perforce { namespace Internal { -struct PerforceSettings { +class PerforceSettings { +public: PerforceSettings(); - void fromSettings(QSettings *); + ~PerforceSettings(); + void fromSettings(QSettings *settings); void toSettings(QSettings *) const; - bool equals(const PerforceSettings &s) const; + void setSettings(const QString &p4Command, const QString &p4Port, const QString &p4Client, const QString p4User, bool defaultEnv); + bool isValid() const; - QString p4Command; - QString p4Port; - QString p4Client; - QString p4User; - bool defaultEnv; + QString p4Command() const; + QString p4Port() const; + QString p4Client() const; + QString p4User() const; + bool defaultEnv() const; + QStringList basicP4Args() const; +private: + void run(QFutureInterface &fi); + mutable QFuture m_future; + mutable QMutex m_mutex; + + QString m_p4Command; + QString m_p4Port; + QString m_p4Client; + QString m_p4User; + bool m_defaultEnv; + bool m_valid; + Q_DISABLE_COPY(PerforceSettings); }; -inline bool operator==(const PerforceSettings &p1, const PerforceSettings &p2) - { return p1.equals(p2); } -inline bool operator!=(const PerforceSettings &p1, const PerforceSettings &p2) - { return !p1.equals(p2); } - } // Internal } // Perforce diff --git a/src/plugins/perforce/settingspage.cpp b/src/plugins/perforce/settingspage.cpp index 70ef649b0e6..53d32714ff2 100644 --- a/src/plugins/perforce/settingspage.cpp +++ b/src/plugins/perforce/settingspage.cpp @@ -49,24 +49,38 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) : m_ui.pathChooser->setExpectedKind(PathChooser::Command); } -PerforceSettings SettingsPageWidget::settings() const +QString SettingsPageWidget::p4Command() const { - PerforceSettings rc; - rc.p4Command = m_ui.pathChooser->path(); - rc.defaultEnv = m_ui.defaultCheckBox->isChecked(); - rc.p4Port = m_ui.portLineEdit->text(); - rc.p4Client = m_ui.clientLineEdit->text(); - rc.p4User = m_ui.userLineEdit->text(); - return rc; + return m_ui.pathChooser->path(); +} + +bool SettingsPageWidget::defaultEnv() const +{ + return m_ui.defaultCheckBox->isChecked(); +} + +QString SettingsPageWidget::p4Port() const +{ + return m_ui.portLineEdit->text(); +} + +QString SettingsPageWidget::p4User() const +{ + return m_ui.userLineEdit->text(); +} + +QString SettingsPageWidget::p4Client() const +{ + return m_ui.clientLineEdit->text(); } void SettingsPageWidget::setSettings(const PerforceSettings &s) { - m_ui.pathChooser->setPath(s.p4Command); - m_ui.defaultCheckBox->setChecked(s.defaultEnv); - m_ui.portLineEdit->setText(s.p4Port); - m_ui.clientLineEdit->setText(s.p4Client); - m_ui.userLineEdit->setText(s.p4User); + m_ui.pathChooser->setPath(s.p4Command()); + m_ui.defaultCheckBox->setChecked(s.defaultEnv()); + m_ui.portLineEdit->setText(s.p4Port()); + m_ui.clientLineEdit->setText(s.p4Client()); + m_ui.userLineEdit->setText(s.p4User()); } SettingsPage::SettingsPage() @@ -101,5 +115,5 @@ void SettingsPage::apply() if (!m_widget) return; - PerforcePlugin::perforcePluginInstance()->setSettings(m_widget->settings()); + PerforcePlugin::perforcePluginInstance()->setSettings(m_widget->p4Command(), m_widget->p4Port(), m_widget->p4Client(), m_widget->p4User(), m_widget->defaultEnv()); } diff --git a/src/plugins/perforce/settingspage.h b/src/plugins/perforce/settingspage.h index f5c43599fad..10a3a0c93b7 100644 --- a/src/plugins/perforce/settingspage.h +++ b/src/plugins/perforce/settingspage.h @@ -51,7 +51,12 @@ class SettingsPageWidget : public QWidget { public: explicit SettingsPageWidget(QWidget *parent); - PerforceSettings settings() const; + QString p4Command() const; + bool defaultEnv() const; + QString p4Port() const; + QString p4User() const; + QString p4Client() const; + void setSettings(const PerforceSettings &); private: diff --git a/src/plugins/projectexplorer/outputwindow.cpp b/src/plugins/projectexplorer/outputwindow.cpp index 6dc95b2bf05..5ac6f7e2df2 100644 --- a/src/plugins/projectexplorer/outputwindow.cpp +++ b/src/plugins/projectexplorer/outputwindow.cpp @@ -110,9 +110,12 @@ OutputPane::OutputPane() connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); m_mainWidget->setLayout(layout); + + connect(Core::ICore::instance(), SIGNAL(coreAboutToClose()), + this, SLOT(coreAboutToClose())); } -OutputPane::~OutputPane() +void OutputPane::coreAboutToClose() { while (m_tabWidget->count()) { RunControl *rc = runControlForTab(0); @@ -120,6 +123,10 @@ OutputPane::~OutputPane() rc->stop(); closeTab(0); } +} + +OutputPane::~OutputPane() +{ delete m_mainWidget; } diff --git a/src/plugins/projectexplorer/outputwindow.h b/src/plugins/projectexplorer/outputwindow.h index edc39ac2fb2..ceafb0a36a0 100644 --- a/src/plugins/projectexplorer/outputwindow.h +++ b/src/plugins/projectexplorer/outputwindow.h @@ -84,6 +84,7 @@ public: public slots: void projectRemoved(); + void coreAboutToClose(); private slots: void insertLine(); diff --git a/src/plugins/qt4projectmanager/gdbmacrosbuildstep.cpp b/src/plugins/qt4projectmanager/gdbmacrosbuildstep.cpp index 507c059239e..6e2ccbc2506 100644 --- a/src/plugins/qt4projectmanager/gdbmacrosbuildstep.cpp +++ b/src/plugins/qt4projectmanager/gdbmacrosbuildstep.cpp @@ -124,7 +124,15 @@ void GdbMacrosBuildStep::run(QFutureInterface & fi) qmake.start(m_qmake, QStringList()<<"-spec"<qtVersion(m_buildConfiguration)->makeCommand(), makeArguments); + QString makeCmd = qt4Project->qtVersion(m_buildConfiguration)->makeCommand(); + if (!value(m_buildConfiguration, "makeCmd").toString().isEmpty()) + makeCmd = value(m_buildConfiguration, "makeCmd").toString(); + if (!QFileInfo(makeCmd).isAbsolute()) { + // Try to detect command in environment + QString tmp = qt4Project->environment(m_buildConfiguration).searchInPath(makeCmd); + makeCmd = tmp; + } + qmake.start(makeCmd, makeArguments); qmake.waitForFinished(); fi.reportResult(true); diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp index f79cc4b5964..e39dc8bf57e 100644 --- a/src/plugins/qt4projectmanager/qtversionmanager.cpp +++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp @@ -296,12 +296,13 @@ void QtVersionManager::updateSystemVersion() foreach (QtVersion *version, m_versions) { if (version->isSystemVersion()) { version->setPath(findSystemQt()); + version->setName(tr("Auto-detected Qt")); haveSystemVersion = true; } } if (haveSystemVersion) return; - QtVersion *version = new QtVersion(tr("System Qt"), + QtVersion *version = new QtVersion(tr("Auto-detected Qt"), findSystemQt(), getUniqueId(), true); diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 88e145a0e58..1d0d910a4c8 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -2504,14 +2504,13 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e) } } - if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) { if (e->button() == Qt::LeftButton) { if (d->m_codeFoldingVisible && TextBlockUserData::canCollapse(cursor.block()) && !TextBlockUserData::hasClosingCollapseInside(cursor.block().next()) && collapseBox(cursor.block()).contains(e->pos())) { - setTextCursor(cursor); toggleBlockVisible(cursor.block()); + d->moveCursorVisible(false); } else if (d->m_marksVisible && e->pos().x() > markWidth) { QTextCursor selection = cursor; selection.setVisualNavigation(true); @@ -3392,15 +3391,16 @@ void BaseTextEditor::setIfdefedOutBlocks(const QList } -void BaseTextEditorPrivate::moveCursorVisible() +void BaseTextEditorPrivate::moveCursorVisible(bool ensureVisible) { QTextCursor cursor = q->textCursor(); if (!cursor.block().isVisible()) { cursor.setVisualNavigation(true); - cursor.movePosition(QTextCursor::PreviousBlock); + cursor.movePosition(QTextCursor::Up); q->setTextCursor(cursor); } - q->ensureCursorVisible(); + if (ensureVisible) + q->ensureCursorVisible(); } void BaseTextEditor::collapse() @@ -3463,12 +3463,12 @@ void BaseTextEditor::unCollapseAll() if (TextBlockUserData::canCollapse(block)) TextBlockUserData::doCollapse(block, makeVisible); block = block.next(); - } d->moveCursorVisible(); documentLayout->requestUpdate(); documentLayout->emitDocumentSizeChanged(); + centerCursor(); } void BaseTextEditor::setTextCodec(QTextCodec *codec) diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 270b7444f42..9da5b27248c 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -218,7 +218,7 @@ public: QTextCursor m_findScope; QTextCursor m_selectBlockAnchor; - void moveCursorVisible(); + void moveCursorVisible(bool ensureVisible = true); }; } // namespace Internal diff --git a/src/shared/cplusplus/CheckSpecifier.cpp b/src/shared/cplusplus/CheckSpecifier.cpp index eeb59eebcc0..a001947ff50 100644 --- a/src/shared/cplusplus/CheckSpecifier.cpp +++ b/src/shared/cplusplus/CheckSpecifier.cpp @@ -384,8 +384,9 @@ bool CheckSpecifier::visit(TypeofSpecifierAST *ast) return false; } -bool CheckSpecifier::visit(AttributeSpecifierAST *) +bool CheckSpecifier::visit(AttributeSpecifierAST *ast) { + accept(ast->next); return false; } diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index c54b75a1e2d..8795b97d5b7 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -768,11 +768,15 @@ bool ProFileEvaluator::Private::visitProValue(ProValue *value) case ProVariable::RemoveOperator: // -= if (!m_cumulative) { if (!m_skipLevel) { - removeEach(&m_valuemap, varName, v); - removeEach(&m_filevaluemap[currentProFile()], varName, v); + // the insertUnique is a hack for the moment to fix the + // CONFIG -= app_bundle problem on Mac (add it to a variable -CONFIG as was done before) + if (removeEach(&m_valuemap, varName, v) == 0) + insertUnique(&m_valuemap, QString("-%1").arg(varName), v); + if (removeEach(&m_filevaluemap[currentProFile()], varName, v) == 0) + insertUnique(&m_filevaluemap[currentProFile()], QString("-%1").arg(varName), v); } } else if (!m_skipLevel) { - // this is a hack for the moment to fix the + // the insertUnique is a hack for the moment to fix the // CONFIG -= app_bundle problem on Mac (add it to a variable -CONFIG as was done before) insertUnique(&m_valuemap, QString("-%1").arg(varName), v); insertUnique(&m_filevaluemap[currentProFile()], QString("-%1").arg(varName), v); diff --git a/src/shared/proparser/proparserutils.h b/src/shared/proparser/proparserutils.h index 7c751c9c273..41c62c88191 100644 --- a/src/shared/proparser/proparserutils.h +++ b/src/shared/proparser/proparserutils.h @@ -140,12 +140,14 @@ static void insertUnique(QHash *map, sl.append(str); } -static void removeEach(QHash *map, +static int removeEach(QHash *map, const QString &key, const QStringList &value) { + int count = 0; QStringList &sl = (*map)[key]; foreach (const QString &str, value) - sl.removeAll(str); + count += sl.removeAll(str); + return count; } /*