This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 177442
Collapse All | Expand All

(-)a/cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/GdbDebugger.java (-17 / +41 lines)
Lines 47-52 Link Here
47
import java.beans.PropertyChangeSupport;
47
import java.beans.PropertyChangeSupport;
48
import java.io.File;
48
import java.io.File;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.nio.charset.Charset;
50
import java.util.ArrayList;
51
import java.util.ArrayList;
51
import java.util.Collection;
52
import java.util.Collection;
52
import java.util.Collections;
53
import java.util.Collections;
Lines 718-724 Link Here
718
                    // See IZ 147931 (On Mac sometimes response is in wrong format)
719
                    // See IZ 147931 (On Mac sometimes response is in wrong format)
719
                    if (results.startsWith("threadno")) { // NOI18N
720
                    if (results.startsWith("threadno")) { // NOI18N
720
                        for (String line : results.split("threadn")) { //NOI18N
721
                        for (String line : results.split("threadn")) { //NOI18N
721
                            Map<String, String> map = GdbUtils.createMapFromString(line);
722
                            Map<String, String> map = createMapFromString(line);
722
                            if (!map.isEmpty()) {
723
                            if (!map.isEmpty()) {
723
                                list.add(map.get("o") + " " + map.get("target_tid")); // NOI18N
724
                                list.add(map.get("o") + " " + map.get("target_tid")); // NOI18N
724
                            }
725
                            }
Lines 930-936 Link Here
930
931
931
        while ((line = info.substring(start, next > 0 ? next : info.length())) != null) {
932
        while ((line = info.substring(start, next > 0 ? next : info.length())) != null) {
932
            if (line.contains(path)) {
933
            if (line.contains(path)) {
933
                return parseMacDylibAddress(line);
934
                return parseMacDylibAddress(line, getCharSetEncoding());
934
            }
935
            }
935
            start = next + 12;
936
            start = next + 12;
936
            next = info.indexOf(",shlib-info=", start); // NOI18N
937
            next = info.indexOf(",shlib-info=", start); // NOI18N
Lines 939-948 Link Here
939
940
940
    }
941
    }
941
942
942
    private static String parseMacDylibAddress(String line) {
943
    private static String parseMacDylibAddress(String line, String encoding) {
943
        int pos1 = GdbUtils.findMatchingCurly(line, 0);
944
        int pos1 = GdbUtils.findMatchingCurly(line, 0);
944
        if (pos1 != -1) {
945
        if (pos1 != -1) {
945
            Map<String, String> map = GdbUtils.createMapFromString(line.substring(1, pos1));
946
            Map<String, String> map = GdbUtils.createMapFromString(line.substring(1, pos1), encoding);
946
            if (map.containsKey("loaded_addr")) { // NOI18N
947
            if (map.containsKey("loaded_addr")) { // NOI18N
947
                return map.get("loaded_addr"); // NOI18N
948
                return map.get("loaded_addr"); // NOI18N
948
            }
949
            }
Lines 1075-1085 Link Here
1075
        if (msg.startsWith(DONE_PREFIX)) {
1076
        if (msg.startsWith(DONE_PREFIX)) {
1076
            if (msg.startsWith("^done,bkpt=")) { // NOI18N (-break-insert)
1077
            if (msg.startsWith("^done,bkpt=")) { // NOI18N (-break-insert)
1077
                msg = msg.substring(12, msg.length() - 1);
1078
                msg = msg.substring(12, msg.length() - 1);
1078
                Map<String, String> map = GdbUtils.createMapFromString(msg);
1079
                Map<String, String> map = createMapFromString(msg);
1079
                validateBreakpoint(token, map);
1080
                validateBreakpoint(token, map);
1080
            } else if (msg.startsWith("^done,stack=")) { // NOI18N (-stack-list-frames)
1081
            } else if (msg.startsWith("^done,stack=")) { // NOI18N (-stack-list-frames)
1081
                if (state == State.STOPPED) { // Ignore data if we've resumed running
1082
                if (state == State.STOPPED) { // Ignore data if we've resumed running
1082
                    stackUpdate(GdbUtils.createListFromString((msg.substring(13, msg.length() - 1))));
1083
                    stackUpdate(createListFromString((msg.substring(13, msg.length() - 1))));
1083
                }
1084
                }
1084
            } else if (msg.startsWith("^done,locals=")) { // NOI18N (-stack-list-locals)
1085
            } else if (msg.startsWith("^done,locals=")) { // NOI18N (-stack-list-locals)
1085
                if (state == State.STOPPED) { // Ignore data if we've resumed running
1086
                if (state == State.STOPPED) { // Ignore data if we've resumed running
Lines 1222-1228 Link Here
1222
        if (msg.startsWith("*stopped")) { // NOI18N
1223
        if (msg.startsWith("*stopped")) { // NOI18N
1223
            Map<String, String> map;
1224
            Map<String, String> map;
1224
            if (msg.length() > 9) {
1225
            if (msg.length() > 9) {
1225
                map = GdbUtils.createMapFromString(msg.substring(9));
1226
                map = createMapFromString(msg.substring(9));
1226
            } else {
1227
            } else {
1227
                map = new HashMap<String, String>();
1228
                map = new HashMap<String, String>();
1228
            }
1229
            }
Lines 1361-1370 Link Here
1361
    }
1362
    }
1362
1363
1363
    private void addArgsToLocalVariables(String info) {
1364
    private void addArgsToLocalVariables(String info) {
1364
        List<String> frames = GdbUtils.createListFromString(info);
1365
        List<String> frames = createListFromString(info);
1365
        GdbCallStackFrame curFrame = getCurrentCallStackFrame();
1366
        GdbCallStackFrame curFrame = getCurrentCallStackFrame();
1366
        for (String frame : frames) {
1367
        for (String frame : frames) {
1367
            Map<String, String> frameMap = GdbUtils.createMapFromString(frame);
1368
            Map<String, String> frameMap = createMapFromString(frame);
1368
            int level;
1369
            int level;
1369
            try {
1370
            try {
1370
                level = Integer.parseInt(frameMap.get("level")); // NOI18N
1371
                level = Integer.parseInt(frameMap.get("level")); // NOI18N
Lines 1679-1685 Link Here
1679
        if (state == State.STARTING) {
1680
        if (state == State.STARTING) {
1680
            String frame = map.get("frame"); // NOI18N
1681
            String frame = map.get("frame"); // NOI18N
1681
            if (frame != null) {
1682
            if (frame != null) {
1682
                map = GdbUtils.createMapFromString(frame);
1683
                map = createMapFromString(frame);
1683
                updateLastStop(map);
1684
                updateLastStop(map);
1684
            }
1685
            }
1685
            setLoading();
1686
            setLoading();
Lines 1760-1766 Link Here
1760
                }
1761
                }
1761
                String frame = map.get("frame"); // NOI18N
1762
                String frame = map.get("frame"); // NOI18N
1762
                if (frame != null) {
1763
                if (frame != null) {
1763
                    map = GdbUtils.createMapFromString(frame);
1764
                    map = createMapFromString(frame);
1764
                    updateLastStop(map);
1765
                    updateLastStop(map);
1765
                }
1766
                }
1766
                GdbTimer.getTimer("Startup").stop("Startup1"); // NOI18N
1767
                GdbTimer.getTimer("Startup").stop("Startup1"); // NOI18N
Lines 1773-1779 Link Here
1773
                setStopped();
1774
                setStopped();
1774
                String frame = map.get("frame"); // NOI18N
1775
                String frame = map.get("frame"); // NOI18N
1775
                if (frame != null) {
1776
                if (frame != null) {
1776
                    map = GdbUtils.createMapFromString(frame);
1777
                    map = createMapFromString(frame);
1777
                    updateLastStop(map);
1778
                    updateLastStop(map);
1778
                }
1779
                }
1779
                if (GdbTimer.getTimer("Step").getSkipCount() == 0) { // NOI18N
1780
                if (GdbTimer.getTimer("Step").getSkipCount() == 0) { // NOI18N
Lines 1880-1886 Link Here
1880
            int next;
1881
            int next;
1881
1882
1882
            while ((next = info.indexOf("shlib-info=", start + 1)) > 0) { // NOI18N
1883
            while ((next = info.indexOf("shlib-info=", start + 1)) > 0) { // NOI18N
1883
                map = GdbUtils.createMapFromString(info.substring(start + 12, next - 2));
1884
                map = createMapFromString(info.substring(start + 12, next - 2));
1884
                path = map.get("path"); // NOI18N
1885
                path = map.get("path"); // NOI18N
1885
                addr = map.get("dyld-addr"); // NOI18N
1886
                addr = map.get("dyld-addr"); // NOI18N
1886
                if (path != null && addr != null) {
1887
                if (path != null && addr != null) {
Lines 1888-1894 Link Here
1888
                }
1889
                }
1889
                start = next;
1890
                start = next;
1890
            }
1891
            }
1891
            map = GdbUtils.createMapFromString(info.substring(start + 12, info.length() - 1));
1892
            map = createMapFromString(info.substring(start + 12, info.length() - 1));
1892
            path = map.get("path"); // NOI18N
1893
            path = map.get("path"); // NOI18N
1893
            addr = map.get("dyld-addr"); // NOI18N
1894
            addr = map.get("dyld-addr"); // NOI18N
1894
            if (path != null && addr != null) {
1895
            if (path != null && addr != null) {
Lines 1967-1974 Link Here
1967
        boolean valid = true;
1968
        boolean valid = true;
1968
        boolean checkNextFrame = false;
1969
        boolean checkNextFrame = false;
1969
1970
1970
        for (String frame : GdbUtils.createListFromString(msg)) {
1971
        for (String frame : createListFromString(msg)) {
1971
            Map<String, String> map = GdbUtils.createMapFromString(frame);
1972
            Map<String, String> map = createMapFromString(frame);
1972
            String func = map.get("func"); // NOI18N
1973
            String func = map.get("func"); // NOI18N
1973
            if (func != null && func.equals("dlopen") && !checkNextFrame) { // NOI18N
1974
            if (func != null && func.equals("dlopen") && !checkNextFrame) { // NOI18N
1974
                if (platform == PlatformTypes.PLATFORM_MACOSX) {
1975
                if (platform == PlatformTypes.PLATFORM_MACOSX) {
Lines 2249-2255 Link Here
2249
2250
2250
            for (int i = 0; i < stack.size(); i++) {
2251
            for (int i = 0; i < stack.size(); i++) {
2251
                String line = stack.get(i);
2252
                String line = stack.get(i);
2252
                Map<String, String> map = GdbUtils.createMapFromString(line);
2253
                Map<String, String> map = createMapFromString(line);
2253
2254
2254
                String func = map.get("func"); // NOI18N
2255
                String func = map.get("func"); // NOI18N
2255
                String file = map.get("file"); // NOI18N
2256
                String file = map.get("file"); // NOI18N
Lines 2793-2796 Link Here
2793
            System.out.println("    " + msg); // NOI18N
2794
            System.out.println("    " + msg); // NOI18N
2794
        }
2795
        }
2795
    }
2796
    }
2797
2798
    private final static String remoteCharSet = System.getProperty("cnd.remote.charset", "UTF-8"); // NOI18N
2799
    public String getCharSetEncoding() {
2800
        return getCharSetEncoding(this.execEnv);
2801
    }
2802
2803
    public static String getCharSetEncoding(ExecutionEnvironment execEnv) {
2804
        String encoding;
2805
        if (execEnv.isRemote()) {
2806
            encoding = remoteCharSet;
2807
        } else {
2808
            encoding = Charset.defaultCharset().name();
2809
        }
2810
        return encoding;
2811
    }
2812
2813
    public Map<String, String> createMapFromString(String info) {
2814
        return GdbUtils.createMapFromString(info, getCharSetEncoding());
2815
    }
2816
2817
    public List<String> createListFromString(String info) {
2818
        return GdbUtils.createListFromString(info, getCharSetEncoding());
2819
    }
2796
}
2820
}
(-)a/cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/proxy/GdbProxyEngine.java (-4 / +26 lines)
Lines 49-54 Link Here
49
import java.io.InputStream;
49
import java.io.InputStream;
50
import java.io.OutputStream;
50
import java.io.OutputStream;
51
import java.io.PrintStream;
51
import java.io.PrintStream;
52
import java.io.UnsupportedEncodingException;
52
import java.util.Arrays;
53
import java.util.Arrays;
53
import java.util.List;
54
import java.util.List;
54
import java.util.logging.Level;
55
import java.util.logging.Level;
Lines 160-166 Link Here
160
161
161
        final NativeProcess proc = npb.call();
162
        final NativeProcess proc = npb.call();
162
        debuggerPid = proc.getPID();
163
        debuggerPid = proc.getPID();
163
        toGdb = gdbReader(proc.getInputStream(), proc.getOutputStream());
164
        // for remote execution we need to convert encoding
165
        toGdb = toGdbWriter(proc.getInputStream(), proc.getOutputStream(), GdbDebugger.getCharSetEncoding(execEnv));
164
166
165
        new RequestProcessor("GdbReaperThread").post(new Runnable() { // NOI18N
167
        new RequestProcessor("GdbReaperThread").post(new Runnable() { // NOI18N
166
            public void run() {
168
            public void run() {
Lines 205-214 Link Here
205
        DialogDisplayer.getDefault().notify(nd);
207
        DialogDisplayer.getDefault().notify(nd);
206
        debugger.finish(false);
208
        debugger.finish(false);
207
    }
209
    }
210
211
    private BufferedReader getReader(final InputStream is, String charSet) {
212
        // set charset
213
        try {
214
            return new BufferedReader(new InputStreamReader(is, charSet));
215
        } catch (UnsupportedEncodingException ex) {
216
            // this is possible situation
217
        }
218
        return new BufferedReader(new InputStreamReader(is));
219
    }
208
    
220
    
209
    private PrintStream gdbReader(InputStream is, OutputStream os) {
221
    private PrintStream getPrintStream(final OutputStream os, String charSet) {
210
        final BufferedReader fromGdb = new BufferedReader(new InputStreamReader(is));
222
        // set charset
211
        PrintStream togdb = new PrintStream(os, true);
223
        try {
224
            return new PrintStream(os, true, charSet);
225
        } catch (UnsupportedEncodingException ex) {
226
            // this is possible situation
227
        }
228
        return new PrintStream(os, true);
229
    }
230
231
    private PrintStream toGdbWriter(InputStream is, OutputStream os, String encoding) {
232
        PrintStream togdb = getPrintStream(os, encoding);
233
        final BufferedReader fromGdb = getReader(is, encoding);
212
234
213
        gdbReader = new RequestProcessor("GdbReaderRP").post(new Runnable() { // NOI18N
235
        gdbReader = new RequestProcessor("GdbReaderRP").post(new Runnable() { // NOI18N
214
            public void run() {
236
            public void run() {
(-)a/cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/ui/MemoryViewTopComponent.java (-2 / +2 lines)
Lines 202-208 Link Here
202
                    taResult.setText(cb.getError());
202
                    taResult.setText(cb.getError());
203
                } else if (cb.isOK()) {
203
                } else if (cb.isOK()) {
204
                    // parse output
204
                    // parse output
205
                    Map<String,String> res = GdbUtils.createMapFromString(cb.getResponse());
205
                    Map<String,String> res = GdbUtils.createMapFromString(cb.getResponse(), debugger.getCharSetEncoding());
206
                    String mem = res.get("memory"); // NOI18N
206
                    String mem = res.get("memory"); // NOI18N
207
                    List<String> lines = GdbUtils.createListOfValues(mem);
207
                    List<String> lines = GdbUtils.createListOfValues(mem);
208
                    StringBuilder text = new StringBuilder();
208
                    StringBuilder text = new StringBuilder();
Lines 210-216 Link Here
210
                        if (text.length() > 0) {
210
                        if (text.length() > 0) {
211
                            text.append("\n"); // NOI18N
211
                            text.append("\n"); // NOI18N
212
                        }
212
                        }
213
                        Map<String,String> fields = GdbUtils.createMapFromString(line);
213
                        Map<String,String> fields = GdbUtils.createMapFromString(line, debugger.getCharSetEncoding());
214
                        text.append(fields.get("addr")); // NOI18N
214
                        text.append(fields.get("addr")); // NOI18N
215
                        text.append("  "); // NOI18N
215
                        text.append("  "); // NOI18N
216
                        text.append(prepareHex(fields.get("data"))); // NOI18N
216
                        text.append(prepareHex(fields.get("data"))); // NOI18N
(-)a/cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/utils/GdbUtils.java (-8 / +8 lines)
Lines 229-235 Link Here
229
    //  args=[{name="argc",value="1"},{name="argv",value="0x6f19a8"}],
229
    //  args=[{name="argc",value="1"},{name="argv",value="0x6f19a8"}],
230
    //  file="quote.cc",fullname="g:/tmp/nik/Quote1/quote.cc",
230
    //  file="quote.cc",fullname="g:/tmp/nik/Quote1/quote.cc",
231
    //  line="131"},gdb-result-var="$1",return-value="-1"
231
    //  line="131"},gdb-result-var="$1",return-value="-1"
232
    private static void processString(String info, PairProcessor processor) {
232
    private static void processString(String info, PairProcessor processor, final String encoding) {
233
        int len = info.length();
233
        int len = info.length();
234
        int i = 0;
234
        int i = 0;
235
        
235
        
Lines 269-275 Link Here
269
            // put the value in the map and prepare for the next property
269
            // put the value in the map and prepare for the next property
270
            String value = info.substring(i, tend);
270
            String value = info.substring(i, tend);
271
            if (key.equals("fullname") || key.equals("file")) { // NOI18N
271
            if (key.equals("fullname") || key.equals("file")) { // NOI18N
272
                value = gdbToUserEncoding(value); // possibly convert multi-byte fields
272
                value = gdbToUserEncoding(value, encoding); // possibly convert multi-byte fields
273
            }
273
            }
274
            processor.onPair(key, value);
274
            processor.onPair(key, value);
275
            i = tend + 2;
275
            i = tend + 2;
Lines 283-300 Link Here
283
     *  @param info A string of key/value pairs
283
     *  @param info A string of key/value pairs
284
     *  @return A HashMap containing each key/value
284
     *  @return A HashMap containing each key/value
285
     */
285
     */
286
    public static Map<String, String> createMapFromString(String info) {
286
    public static Map<String, String> createMapFromString(String info, final String encoding) {
287
        final HashMap<String, String> map = new HashMap<String, String>();
287
        final HashMap<String, String> map = new HashMap<String, String>();
288
        processString(info, new PairProcessor() {
288
        processString(info, new PairProcessor() {
289
            @Override
289
            @Override
290
            public void onPair(String key, String value) {
290
            public void onPair(String key, String value) {
291
                map.put(key, value);
291
                map.put(key, value);
292
            }
292
            }
293
        });
293
        }, encoding);
294
        return map;
294
        return map;
295
    }
295
    }
296
    
296
    
297
    public static String gdbToUserEncoding(String string) {
297
    private static String gdbToUserEncoding(String string, final String encoding) {
298
        // The first part transforms string to byte array
298
        // The first part transforms string to byte array
299
        char[] chars = string.toCharArray();
299
        char[] chars = string.toCharArray();
300
        char last = 0, next;
300
        char last = 0, next;
Lines 316-322 Link Here
316
316
317
        // The second part performs encoding to current coding system
317
        // The second part performs encoding to current coding system
318
        try {
318
        try {
319
            string = new String(bytes, System.getProperty("sun.jnu.encoding"));
319
            string = new String(bytes, encoding);
320
        } catch (UnsupportedEncodingException e) {
320
        } catch (UnsupportedEncodingException e) {
321
        }
321
        }
322
        return string;
322
        return string;
Lines 356-369 Link Here
356
     *  @param info A string of key/value pairs
356
     *  @param info A string of key/value pairs
357
     *  @return An ArrayList with each entry as a value (keys are thrown away, use createMapFromString if you need them)
357
     *  @return An ArrayList with each entry as a value (keys are thrown away, use createMapFromString if you need them)
358
     */
358
     */
359
    public static List<String> createListFromString(String info) {
359
    public static List<String> createListFromString(String info, String encoding) {
360
        final List<String> list = new ArrayList<String>();
360
        final List<String> list = new ArrayList<String>();
361
        processString(info, new PairProcessor() {
361
        processString(info, new PairProcessor() {
362
            @Override
362
            @Override
363
            public void onPair(String key, String value) {
363
            public void onPair(String key, String value) {
364
                list.add(value);
364
                list.add(value);
365
            }
365
            }
366
        });
366
        }, encoding);
367
        return list;
367
        return list;
368
    }
368
    }
369
369
(-)a/cnd.debugger.gdb/test/unit/src/org/netbeans/modules/cnd/debugger/gdb/StringProcessingTestCase.java (-2 / +3 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.cnd.debugger.gdb;
40
package org.netbeans.modules.cnd.debugger.gdb;
41
41
42
import java.nio.charset.Charset;
42
import java.util.List;
43
import java.util.List;
43
import java.util.Map;
44
import java.util.Map;
44
import junit.framework.TestCase;
45
import junit.framework.TestCase;
Lines 108-114 Link Here
108
109
109
    @Test
110
    @Test
110
    public void testCreateMapFromString1() {
111
    public void testCreateMapFromString1() {
111
        Map<String, String> map = GdbUtils.createMapFromString("a=\"1\",b={x},c=[\"xyz\"]");
112
        Map<String, String> map = GdbUtils.createMapFromString("a=\"1\",b={x},c=[\"xyz\"]", Charset.defaultCharset().name());
112
        assertEquals("1", map.get("a"));
113
        assertEquals("1", map.get("a"));
113
        assertEquals("x", map.get("b"));
114
        assertEquals("x", map.get("b"));
114
        assertEquals("\"xyz\"", map.get("c"));
115
        assertEquals("\"xyz\"", map.get("c"));
Lines 116-122 Link Here
116
117
117
    @Test
118
    @Test
118
    public void testCreateListFromString1() {
119
    public void testCreateListFromString1() {
119
        List<String> list = GdbUtils.createListFromString("a=\"1\",b={x},c=[\"xyz\"]");
120
        List<String> list = GdbUtils.createListFromString("a=\"1\",b={x},c=[\"xyz\"]", Charset.defaultCharset().name());
120
        assertEquals("1", list.get(0));
121
        assertEquals("1", list.get(0));
121
        assertEquals("x", list.get(1));
122
        assertEquals("x", list.get(1));
122
        assertEquals("\"xyz\"", list.get(2));
123
        assertEquals("\"xyz\"", list.get(2));

Return to bug 177442