comparison graal/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLMessage.java @ 21568:3b8bbf51d320

Truffle/Debugging: add the Truffle DebugEngine and supporting code, as well as add a crude command-line debugging tool used mainly to test the DebugEngine. Migrate the small tols out of project com.oracle.truffle.api into the new project com.oracle.truffle.tools.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 26 May 2015 16:38:13 -0700
parents
children
comparison
equal deleted inserted replaced
21470:1bbef57f9a38 21568:3b8bbf51d320
1 /*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.tools.debug.shell;
26
27 import java.io.*;
28 import java.util.*;
29 import java.util.Map.Entry;
30
31 /**
32 * A message for communication between a Read-Eval-Print-Loop server associated with a language
33 * implementation and a possibly remote client.
34 *
35 * @see REPLClient
36 * @see REPLServer
37 */
38 public final class REPLMessage {
39
40 // Some standard keys and values
41 public static final String AST = "ast";
42 public static final String AST_DEPTH = "show-max-depth";
43 public static final String BACKTRACE = "backtrace";
44 public static final String BREAK_AT_LINE = "break-at-line";
45 public static final String BREAK_AT_LINE_ONCE = "break-at-line-once";
46 public static final String BREAK_AT_THROW = "break-at-throw";
47 public static final String BREAK_AT_THROW_ONCE = "break-at-throw-once";
48 public static final String BREAKPOINT_CONDITION = "breakpoint-condition";
49 public static final String BREAKPOINT_GROUP_ID = "breakpoint-group-id";
50 public static final String BREAKPOINT_HIT_COUNT = "breakpoint-hit-count";
51 public static final String BREAKPOINT_ID = "breakpoint-id";
52 public static final String BREAKPOINT_IGNORE_COUNT = "breakpoint-ignore-count";
53 public static final String BREAKPOINT_INFO = "breakpoint-info";
54 public static final String BREAKPOINT_STATE = "breakpoint-state";
55 public static final String CLEAR_BREAK = "clear-breakpoint";
56 public static final String CODE = "code";
57 public static final String CONTINUE = "continue";
58 public static final String DEBUG_LEVEL = "debug-level";
59 public static final String DELETE_BREAK = "delete-breakpoint";
60 public static final String DISABLE_BREAK = "disable-breakpoint";
61 public static final String DISPLAY_MSG = "displayable-message";
62 public static final String DOWN = "down";
63 public static final String ENABLE_BREAK = "enable-breakpoint";
64 public static final String EVAL = "eval";
65 public static final String FAILED = "failed";
66 public static final String FILE = "file";
67 public static final String FILE_PATH = "path";
68 public static final String FRAME = "frame";
69 public static final String FRAME_INFO = "frame-info";
70 public static final String FRAME_NUMBER = "frame-number";
71 public static final String INFO = "info";
72 public static final String INFO_KEY = "info-key";
73 public static final String INFO_VALUE = "info-value";
74 public static final String KILL = "kill";
75 public static final String LANGUAGE = "language";
76 public static final String LINE_NUMBER = "line-number";
77 public static final String LIST = "list";
78 public static final String LOAD_RUN = "load-run-source";
79 public static final String LOAD_STEP = "load-step-into-source";
80 public static final String METHOD_NAME = "method-name";
81 public static final String OP = "op";
82 public static final String OPTION = "option";
83 public static final String QUIT = "quit";
84 public static final String REPEAT = "repeat";
85 public static final String SET = "set";
86 public static final String SET_BREAK_CONDITION = "set-breakpoint-condition";
87 public static final String SOURCE_LINE_TEXT = "source-line-text";
88 public static final String SOURCE_LOCATION = "source-location";
89 public static final String SOURCE_NAME = "source-name";
90 public static final String SOURCE_TEXT = "source-text";
91 public static final String STACK_SIZE = "stack-size";
92 public static final String STATUS = "status";
93 public static final String STEP_INTO = "step-into";
94 public static final String STEP_OUT = "step-out";
95 public static final String STEP_OVER = "step-over";
96 public static final String STOPPED = "stopped";
97 public static final String SUB = "sub";
98 public static final String SUBTREE = "subtree";
99 public static final String SUCCEEDED = "succeeded";
100 public static final String TOPIC = "topic";
101 public static final String TRUFFLE = "truffle";
102 public static final String TRUFFLE_AST = "truffle-ast";
103 public static final String TRUFFLE_NODE = "truffle-node";
104 public static final String TRUFFLE_SUBTREE = "truffle-subtree";
105 public static final String UNSET_BREAK_CONDITION = "unset-breakpoint-condition";
106 public static final String UP = "up";
107 public static final String VALUE = "value";
108 public static final String WARNINGS = "warnings";
109 private final Map<String, String> map;
110
111 /**
112 * Creates an empty REPL message.
113 */
114 public REPLMessage() {
115 this.map = new TreeMap<>();
116 }
117
118 /**
119 * Creates a REPL message with an initial entry.
120 */
121 public REPLMessage(String key, String value) {
122 this();
123 map.put(key, value);
124 }
125
126 public REPLMessage(REPLMessage message) {
127 this.map = new TreeMap<>(message.map);
128 }
129
130 public String get(String key) {
131 return map.get(key);
132 }
133
134 /**
135 * Returns the specified key value as an integer; {@code null} if missing or non-numeric.
136 */
137 public Integer getIntValue(String key) {
138 final String value = map.get(key);
139 if (value != null) {
140 try {
141 return Integer.parseInt(value);
142 } catch (NumberFormatException e) {
143
144 }
145 }
146 return null;
147 }
148
149 public String put(String key, String value) {
150 return map.put(key, value);
151 }
152
153 public String remove(String key) {
154 return map.remove(key);
155 }
156
157 public Set<String> keys() {
158 return map.keySet();
159 }
160
161 public void print(PrintStream out, String linePrefix) {
162 map.keySet();
163
164 for (Entry<String, String> entry : map.entrySet()) {
165 String value = entry.getValue();
166 if (value != null && value.length() > 50) {
167 value = value.substring(0, 50) + " ...";
168 }
169 out.println(linePrefix + entry.getKey() + " = \"" + value + "\"");
170 }
171 }
172 }