Exemple #1
0
bool MemoryAgent::doCreateBinEditor(quint64 addr, unsigned flags,
                       const QList<MemoryMarkup> &ml, const QPoint &pos,
                       QString title, QWidget *parent)
{
    const bool readOnly = (flags & DebuggerEngine::MemoryReadOnly) != 0;
    if (title.isEmpty())
        title = tr("Memory at 0x%1").arg(addr, 0, 16);
    // Separate view?
    if (flags & DebuggerEngine::MemoryView) {
        // Ask BIN editor plugin for factory service and have it create a bin editor widget.
        QWidget *binEditor = 0;
        if (QObject *factory = ExtensionSystem::PluginManager::instance()->getObjectByClassName(QLatin1String("BINEditor::BinEditorWidgetFactory")))
            binEditor = ExtensionSystem::invoke<QWidget *>(factory, "createWidget", (QWidget *)0);
        if (!binEditor)
            return false;
        connectBinEditorWidget(binEditor);
        MemoryView::setBinEditorReadOnly(binEditor, readOnly);
        MemoryView::setBinEditorNewWindowRequestAllowed(binEditor, true);
        MemoryView *topLevel = 0;
        // Memory view tracking register value, providing its own updating mechanism.
        if (flags & DebuggerEngine::MemoryTrackRegister) {
            RegisterMemoryView *rmv = new RegisterMemoryView(binEditor, parent);
            rmv->init(m_engine->registerHandler(), int(addr));
            topLevel = rmv;
        } else {
            // Ordinary memory view
            MemoryView::setBinEditorMarkup(binEditor, ml);
            MemoryView::setBinEditorRange(binEditor, addr, MemoryAgent::DataRange, MemoryAgent::BinBlockSize);
            topLevel = new MemoryView(binEditor, parent);
            topLevel->setWindowTitle(title);
        }
        m_views << topLevel;
        topLevel->move(pos);
        topLevel->show();
        return true;
    }
    // Editor: Register tracking not supported.
    QTC_ASSERT(!(flags & DebuggerEngine::MemoryTrackRegister), return false);
    EditorManager *editorManager = EditorManager::instance();
    if (!title.endsWith(QLatin1Char('$')))
        title.append(QLatin1String(" $"));
    IEditor *editor = editorManager->openEditorWithContents(
                Core::Constants::K_DEFAULT_BINARY_EDITOR_ID, &title);
    if (!editor)
        return false;
    editor->setProperty(Constants::OPENED_BY_DEBUGGER, QVariant(true));
    editor->setProperty(Constants::OPENED_WITH_MEMORY, QVariant(true));
    QWidget *editorBinEditor = editor->widget();
    connectBinEditorWidget(editorBinEditor);
    MemoryView::setBinEditorReadOnly(editorBinEditor, readOnly);
    MemoryView::setBinEditorNewWindowRequestAllowed(editorBinEditor, true);
    MemoryView::setBinEditorRange(editorBinEditor, addr, MemoryAgent::DataRange, MemoryAgent::BinBlockSize);
    MemoryView::setBinEditorMarkup(editorBinEditor, ml);
    m_editors << editor;
    editorManager->activateEditor(editor);
    return true;
}