From 4ecb1283fe4ee463e9b550d4575eb33ad9944a17 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 22 Jun 2017 11:21:58 +0200 Subject: [PATCH] Debugger: Do not crash in (im)possible situations Task-number: QTCREATORBUG-18427 Change-Id: I800c2f8d4ea37b28022d789a2e519e4f5286f08a Reviewed-by: Nikolai Kosjar --- src/plugins/debugger/debuggerplugin.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 16825ffa0c7..4581f5ad5a3 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -2311,26 +2311,32 @@ void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget, } // Run to, jump to line below in stopped state. - if (currentEngine()->state() == InferiorStopOk && args.isValid()) { + DebuggerEngine *engine = currentEngine(); + QTC_ASSERT(engine, return); + if (engine->state() == InferiorStopOk && args.isValid()) { menu->addSeparator(); - if (currentEngine()->hasCapability(RunToLineCapability)) { + if (engine->hasCapability(RunToLineCapability)) { auto act = menu->addAction(args.address ? DebuggerEngine::tr("Run to Address 0x%1").arg(args.address, 0, 16) : DebuggerEngine::tr("Run to Line %1").arg(args.lineNumber)); connect(act, &QAction::triggered, [this, args] { - currentEngine()->executeRunToLine(args); + DebuggerEngine *engine = currentEngine(); + QTC_ASSERT(engine, return); + engine->executeRunToLine(args); }); } - if (currentEngine()->hasCapability(JumpToLineCapability)) { + if (engine->hasCapability(JumpToLineCapability)) { auto act = menu->addAction(args.address ? DebuggerEngine::tr("Jump to Address 0x%1").arg(args.address, 0, 16) : DebuggerEngine::tr("Jump to Line %1").arg(args.lineNumber)); connect(act, &QAction::triggered, [this, args] { - currentEngine()->executeJumpToLine(args); + DebuggerEngine *engine = currentEngine(); + QTC_ASSERT(engine, return); + engine->executeJumpToLine(args); }); } // Disassemble current function in stopped state. - if (currentEngine()->hasCapability(DisassemblerCapability)) { + if (engine->hasCapability(DisassemblerCapability)) { StackFrame frame; frame.function = cppFunctionAt(args.fileName, lineNumber, 1); frame.line = 42; // trick gdb into mixed mode. @@ -2339,7 +2345,9 @@ void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget, .arg(frame.function); auto act = new QAction(text, menu); connect(act, &QAction::triggered, [this, frame] { - currentEngine()->openDisassemblerView(Location(frame)); + DebuggerEngine *engine = currentEngine(); + QTC_ASSERT(engine, return); + engine->openDisassemblerView(Location(frame)); }); menu->addAction(act); }