Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aa189e831a2d34ea31501783852cc3413da833b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tm.internal.tcf.debug.ui.commands;

import java.util.ArrayList;

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.tm.internal.tcf.debug.ui.Activator;
import org.eclipse.tm.internal.tcf.debug.ui.model.TCFNode;
import org.eclipse.tm.internal.tcf.debug.ui.model.TCFNodeExpression;
import org.eclipse.tm.internal.tcf.debug.ui.model.TCFNumberFormat;
import org.eclipse.tm.tcf.services.IExpressions;
import org.eclipse.tm.tcf.util.TCFDataCache;
import org.eclipse.tm.tcf.util.TCFTask;
import org.eclipse.ui.IWorkbenchPage;

public class ViewMemoryCommand extends AbstractActionDelegate {

    private static class Block {
        long addr;
        long size;
    }

    @Override
    protected void run() {
        try {
            IWorkbenchPage page = getWindow().getActivePage();
            page.showView(IDebugUIConstants.ID_MEMORY_VIEW, null, IWorkbenchPage.VIEW_ACTIVATE);
            final ArrayList<IMemoryBlock> list = new ArrayList<IMemoryBlock>();
            for (final TCFNode node : getSelectedNodes()) {
                final IMemoryBlockRetrievalExtension mem_retrieval = (IMemoryBlockRetrievalExtension)
                        node.getAdapter(IMemoryBlockRetrievalExtension.class);
                if (mem_retrieval == null) continue;
                Block b = new TCFTask<Block>(node.getChannel()) {
                    public void run() {
                        try {
                            Number addr = null;
                            long size = -1;
                            if (node instanceof TCFNodeExpression) {
                                TCFDataCache<IExpressions.Value> val_cache = ((TCFNodeExpression)node).getValue();
                                if (!val_cache.validate(this)) return;
                                IExpressions.Value val_data = val_cache.getData();
                                if (val_data != null) {
                                    addr = val_data.getAddress();
                                    if (addr != null) {
                                        byte[] bytes = val_data.getValue();
                                        if (bytes != null) size = bytes.length;
                                    }
                                    else if (val_data.getRegisterID() != null) {
                                        byte[] bytes = val_data.getValue();
                                        if (bytes != null) {
                                            addr = TCFNumberFormat.toBigInteger(bytes, 0, bytes.length,
                                                    val_data.isBigEndian(), false);
                                        }
                                    }
                                }
                            }
                            Block b = null;
                            if (addr != null) {
                                b = new Block();
                                b.addr = addr.longValue();
                                b.size = size;
                            }
                            done(b);
                        }
                        catch (Exception x) {
                            error(x);
                        }
                    }
                }.get();
                if (b != null) list.add(mem_retrieval.getMemoryBlock(b.addr, b.size));
            }
            DebugPlugin.getDefault().getMemoryBlockManager().addMemoryBlocks(list.toArray(new IMemoryBlock[list.size()]));
        }
        catch (Exception x) {
            Activator.log("Cannot open memory view", x);
        }
    }

    @Override
    protected void selectionChanged() {
        getAction().setEnabled(getSelectedNodes().length > 0);
    }
}

Back to the top