Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a899ba4c004fd4ef9abe7fd1f3a09bd3b124b5b (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
 * Copyright (c) 2014 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.tcf.internal.debug.ui.model;

import java.math.BigInteger;
import java.util.Map;

import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.tcf.core.ErrorReport;
import org.eclipse.tcf.internal.debug.model.TCFSymFileRef;
import org.eclipse.tcf.internal.debug.ui.ColorCache;
import org.eclipse.tcf.internal.debug.ui.ImageCache;
import org.eclipse.tcf.internal.debug.ui.model.TCFNodeExecContext.MemoryRegion;
import org.eclipse.tcf.protocol.JSON;
import org.eclipse.tcf.services.IMemoryMap;
import org.eclipse.tcf.util.TCFDataCache;

/**
 * A node representing a memory region (module).
 */
public class TCFNodeModule extends TCFNode implements IDetailsProvider {

    private final TCFData<MemoryRegion> region;

    protected TCFNodeModule(final TCFNodeExecContext parent, String id, final int index) {
        super(parent, id);
        region = new TCFData<MemoryRegion>(channel) {
            @Override
            protected boolean startDataRetrieval() {
                TCFDataCache<MemoryRegion[]> map_cache = parent.getMemoryMap();
                if (!map_cache.validate(this)) return false;
                Throwable error = map_cache.getError();
                MemoryRegion[] map_data = map_cache.getData();
                MemoryRegion region = null;
                if (map_data != null && index < map_data.length) region = map_data[index];
                set(null, error, region);
                return true;
            }
        };
    }

    public TCFDataCache<MemoryRegion> getRegion() {
        return region;
    }

    void onMemoryMapChanged() {
        region.reset();
    }

    @Override
    protected boolean getData(ILabelUpdate update, Runnable done) {
        if (!region.validate(done)) return false;
        MemoryRegion mr = region.getData();
        IMemoryMap.MemoryRegion r = mr != null ? mr.region : null;
        if (r == null) {
            update.setLabel("...", 0);
        }
        else {
            String[] col_ids = update.getColumnIds();
            if (col_ids == null) {
                update.setLabel(r.getFileName(), 0);
            }
            else {
                for (int i=0; i < col_ids.length; ++i) {
                    String col_id = col_ids[i];
                    if (TCFColumnPresentationModules.COL_NAME.equals(col_id)) {
                        update.setLabel(r.getFileName(), i);
                    }
                    else if (TCFColumnPresentationModules.COL_ADDRESS.equals(col_id)) {
                        update.setLabel(toHexString(r.getAddress()), i);
                    }
                    else if (TCFColumnPresentationModules.COL_SIZE.equals(col_id)) {
                        update.setLabel(toHexString(r.getSize()), i);
                    }
                    else if (TCFColumnPresentationModules.COL_FLAGS.equals(col_id)) {
                        update.setLabel(getFlagsLabel(r.getFlags()), i);
                    }
                    else if (TCFColumnPresentationModules.COL_OFFSET.equals(col_id)) {
                        update.setLabel(toHexString(r.getOffset()), i);
                    }
                    else if (TCFColumnPresentationModules.COL_SECTION.equals(col_id)) {
                        String sectionName = r.getSectionName();
                        update.setLabel(sectionName != null ? sectionName : "", i);
                    }
                }
            }
        }
        update.setImageDescriptor(ImageCache.getImageDescriptor(ImageCache.IMG_MEMORY_MAP), 0);
        return true;
    }

    @Override
    protected void getFontData(ILabelUpdate update, String view_id) {
        FontData fn = TCFModelFonts.getNormalFontData(view_id);
        String[] cols = update.getColumnIds();
        if (cols == null || cols.length == 0) {
            update.setFontData(fn, 0);
        }
        else {
            String[] ids = update.getColumnIds();
            for (int i = 0; i < cols.length; i++) {
                if (TCFColumnPresentationModules.COL_ADDRESS.equals(ids[i]) ||
                        TCFColumnPresentationModules.COL_OFFSET.equals(ids[i]) ||
                        TCFColumnPresentationModules.COL_SIZE.equals(ids[i])) {
                    update.setFontData(TCFModelFonts.getMonospacedFontData(view_id), i);
                }
                else {
                    update.setFontData(fn, i);
                }
            }
        }
    }

    public boolean getDetailText(StyledStringBuffer bf, Runnable done) {
        if (!region.validate(done)) return false;
        MemoryRegion mr = region.getData();
        IMemoryMap.MemoryRegion r = mr != null ? mr.region : null;
        if (r == null) return true;
        String file_name = r.getFileName();
        if (file_name != null) {
            bf.append("File name: ", SWT.BOLD).append(file_name).append('\n');
            TCFNodeExecContext exe = (TCFNodeExecContext)parent;
            TCFDataCache<TCFSymFileRef> sym_cache = exe.getSymFileInfo(JSON.toBigInteger(r.getAddress()));
            if (sym_cache != null) {
                if (!sym_cache.validate(done)) return false;
                TCFSymFileRef sym_data = sym_cache.getData();
                if (sym_data != null) {
                    if (sym_data.props != null) {
                        String sym_file_name = (String)sym_data.props.get("FileName");
                        if (sym_file_name != null) bf.append("Symbol file name: ", SWT.BOLD).append(sym_file_name).append('\n');
                        @SuppressWarnings("unchecked")
                        Map<String,Object> map = (Map<String,Object>)sym_data.props.get("FileError");
                        if (map != null) {
                            String msg = TCFModel.getErrorMessage(new ErrorReport("", map), false);
                            bf.append("Symbol file error: ", SWT.BOLD).append(msg, SWT.ITALIC, null, ColorCache.rgb_error).append('\n');
                        }
                    }
                    if (sym_data.error != null) bf.append("Symbol file error: ", SWT.BOLD).append(
                            TCFModel.getErrorMessage(sym_data.error, false),
                            SWT.ITALIC, null, ColorCache.rgb_error).append('\n');
                }
            }
            String section = r.getSectionName();
            if (section != null) bf.append("File section: ", SWT.BOLD).append(section).append('\n');
            else bf.append("File offset: ", SWT.BOLD).append(toHexString(r.getOffset()), StyledStringBuffer.MONOSPACED).append('\n');
        }
        bf.append("Address: ", SWT.BOLD).append(toHexString(r.getAddress()), StyledStringBuffer.MONOSPACED).append('\n');
        bf.append("Size: ", SWT.BOLD).append(toHexString(r.getSize()), StyledStringBuffer.MONOSPACED).append('\n');
        bf.append("Flags: ", SWT.BOLD).append(getFlagsLabel(r.getFlags())).append('\n');
        return true;
    }

    private String toHexString(Number address) {
        if (address == null) return "";
        BigInteger addr = JSON.toBigInteger(address);
        String s = addr.toString(16);
        int sz = s.length() <= 8 ? 8 : 16;
        int l = sz - s.length();
        if (l < 0) l = 0;
        if (l > 16) l = 16;
        return "0x0000000000000000".substring(0, 2 + l) + s;
    }

    private String getFlagsLabel(int flags) {
        StringBuilder flagsLabel = new StringBuilder(3);
        if ((flags & IMemoryMap.FLAG_READ) != 0) flagsLabel.append('r');
        else flagsLabel.append('-');
        if ((flags & IMemoryMap.FLAG_WRITE) != 0) flagsLabel.append('w');
        else flagsLabel.append('-');
        if ((flags & IMemoryMap.FLAG_EXECUTE) != 0) flagsLabel.append('x');
        else flagsLabel.append('-');
        return flagsLabel.toString();
    }
}

Back to the top