Commit 9b78d20b authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol

New Rev: 8c3f1afc2dc5b8588bc2dc5f12a93255383d7236

Change-Id: I88fcc74b969d114cc6c491c9d1aa5872245f8f5c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1590624Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61138}
parent ff14c886
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: 16b370abe6f4b59efea00377473b5dddb438defb Revision: 8c3f1afc2dc5b8588bc2dc5f12a93255383d7236
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import os.path import os.path
import sys import sys
import optparse import argparse
import collections import collections
import functools import functools
import re import re
...@@ -17,6 +17,13 @@ except ImportError: ...@@ -17,6 +17,13 @@ except ImportError:
import pdl import pdl
try:
unicode
except NameError:
# Define unicode for Py3
def unicode(s, *_):
return s
# Path handling for libraries and templates # Path handling for libraries and templates
# Paths have to be normalized because Jinja uses the exact template path to # Paths have to be normalized because Jinja uses the exact template path to
# determine the hash used in the cache filename, and we need a pre-caching step # determine the hash used in the cache filename, and we need a pre-caching step
...@@ -53,28 +60,17 @@ def read_config(): ...@@ -53,28 +60,17 @@ def read_config():
return collections.namedtuple('X', keys)(*values) return collections.namedtuple('X', keys)(*values)
try: try:
cmdline_parser = optparse.OptionParser() cmdline_parser = argparse.ArgumentParser()
cmdline_parser.add_option("--output_base") cmdline_parser.add_argument("--output_base", type=unicode, required=True)
cmdline_parser.add_option("--jinja_dir") cmdline_parser.add_argument("--jinja_dir", type=unicode, required=True)
cmdline_parser.add_option("--config") cmdline_parser.add_argument("--config", type=unicode, required=True)
cmdline_parser.add_option("--config_value", action="append", type="string") cmdline_parser.add_argument("--config_value", default=[], action="append")
arg_options, _ = cmdline_parser.parse_args() arg_options = cmdline_parser.parse_args()
jinja_dir = arg_options.jinja_dir jinja_dir = arg_options.jinja_dir
if not jinja_dir:
raise Exception("jinja directory must be specified")
jinja_dir = jinja_dir.decode('utf8')
output_base = arg_options.output_base output_base = arg_options.output_base
if not output_base:
raise Exception("Base output directory must be specified")
output_base = output_base.decode('utf8')
config_file = arg_options.config config_file = arg_options.config
if not config_file:
raise Exception("Config file name must be specified")
config_file = config_file.decode('utf8')
config_base = os.path.dirname(config_file) config_base = os.path.dirname(config_file)
config_values = arg_options.config_value config_values = arg_options.config_value
if not config_values:
config_values = []
except Exception: except Exception:
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
exc = sys.exc_info()[1] exc = sys.exc_info()[1]
......
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
# found in the LICENSE file. # found in the LICENSE file.
import argparse import argparse
import collections
import json import json
import os.path import os.path
import re
import sys import sys
import pdl import pdl
......
...@@ -237,75 +237,6 @@ Binary Binary::fromSpan(const uint8_t* data, size_t size) { ...@@ -237,75 +237,6 @@ Binary Binary::fromSpan(const uint8_t* data, size_t size) {
new base::RefCountedBytes(data, size))); new base::RefCountedBytes(data, size)));
} }
namespace {
int32_t ReadEnvelopeSize(const uint8_t* in) {
return (in[0] << 24) + (in[1] << 16) + (in[2] << 8) + in[3];
}
void WriteEnvelopeSize(uint32_t value, uint8_t* out) {
*(out++) = (value >> 24) & 0xFF;
*(out++) = (value >> 16) & 0xFF;
*(out++) = (value >> 8) & 0xFF;
*(out++) = (value) & 0xFF;
}
}
bool AppendStringValueToMapBinary(base::StringPiece in,
base::StringPiece key, base::StringPiece value, std::string* out) {
if (in.size() < 1 + 1 + 4 + 1 + 1)
return false;
const uint8_t* envelope = reinterpret_cast<const uint8_t*>(in.data());
if (cbor::InitialByteForEnvelope() != envelope[0])
return false;
if (cbor::InitialByteFor32BitLengthByteString() != envelope[1])
return false;
if (cbor::EncodeIndefiniteLengthMapStart() != envelope[6])
return false;
uint32_t envelope_size = ReadEnvelopeSize(envelope + 2);
if (envelope_size + 2 + 4 != in.size())
return false;
if (cbor::EncodeStop() != static_cast<uint8_t>(*in.rbegin()))
return false;
std::vector<uint8_t> encoded_entry;
encoded_entry.reserve(1 + 4 + key.size() + 1 + 4 + value.size());
span<uint8_t> key_span(
reinterpret_cast<const uint8_t*>(key.data()), key.size());
cbor::EncodeString8(key_span, &encoded_entry);
span<uint8_t> value_span(
reinterpret_cast<const uint8_t*>(value.data()), value.size());
cbor::EncodeString8(value_span, &encoded_entry);
out->clear();
out->reserve(in.size() + encoded_entry.size());
out->append(in.begin(), in.end() - 1);
out->append(reinterpret_cast<const char*>(encoded_entry.data()),
encoded_entry.size());
out->append(1, static_cast<char>(cbor::EncodeStop()));
std::size_t new_size = envelope_size + out->size() - in.size();
if (new_size > static_cast<std::size_t>(
std::numeric_limits<uint32_t>::max())) {
return false;
}
WriteEnvelopeSize(new_size, reinterpret_cast<uint8_t*>(&*out->begin() + 2));
return true;
}
bool AppendStringValueToMapJSON(base::StringPiece in,
base::StringPiece key, base::StringPiece value, std::string* out) {
if (!in.length() || *in.rbegin() != '}')
return false;
std::string suffix =
base::StringPrintf(", \"%s\": \"%s\"}", key.begin(), value.begin());
out->clear();
out->reserve(in.length() + suffix.length() - 1);
out->append(in.data(), in.length() - 1);
out->append(suffix);
return true;
}
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
...@@ -136,12 +136,6 @@ class {{config.lib.export_macro}} Binary { ...@@ -136,12 +136,6 @@ class {{config.lib.export_macro}} Binary {
std::unique_ptr<Value> toProtocolValue(const base::Value* value, int depth); std::unique_ptr<Value> toProtocolValue(const base::Value* value, int depth);
std::unique_ptr<base::Value> toBaseValue(Value* value, int depth); std::unique_ptr<base::Value> toBaseValue(Value* value, int depth);
bool AppendStringValueToMapBinary(base::StringPiece in,
base::StringPiece key, base::StringPiece value, std::string* out);
bool AppendStringValueToMapJSON(base::StringPiece in,
base::StringPiece key, base::StringPiece value, std::string* out);
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -62,15 +63,27 @@ class span { ...@@ -62,15 +63,27 @@ class span {
}; };
template <typename T> template <typename T>
span<T> SpanFromVector(const std::vector<T>& v) { span<T> SpanFrom(const std::vector<T>& v) {
return span<T>(v.data(), v.size()); return span<T>(v.data(), v.size());
} }
inline span<uint8_t> SpanFromStdString(const std::string& v) { template <size_t N>
span<uint8_t> SpanFrom(const char (&str)[N]) {
return span<uint8_t>(reinterpret_cast<const uint8_t*>(str), N - 1);
}
inline span<uint8_t> SpanFrom(const char* str) {
return str ? span<uint8_t>(reinterpret_cast<const uint8_t*>(str), strlen(str))
: span<uint8_t>();
}
inline span<uint8_t> SpanFrom(const std::string& v) {
return span<uint8_t>(reinterpret_cast<const uint8_t*>(v.data()), v.size()); return span<uint8_t>(reinterpret_cast<const uint8_t*>(v.data()), v.size());
} }
// Error codes. // =============================================================================
// Status and Error codes
// =============================================================================
enum class Error { enum class Error {
OK = 0, OK = 0,
// JSON parsing errors - json_parser.{h,cc}. // JSON parsing errors - json_parser.{h,cc}.
...@@ -102,11 +115,10 @@ enum class Error { ...@@ -102,11 +115,10 @@ enum class Error {
CBOR_UNEXPECTED_EOF_IN_MAP = 0x19, CBOR_UNEXPECTED_EOF_IN_MAP = 0x19,
CBOR_INVALID_MAP_KEY = 0x1a, CBOR_INVALID_MAP_KEY = 0x1a,
CBOR_STACK_LIMIT_EXCEEDED = 0x1b, CBOR_STACK_LIMIT_EXCEEDED = 0x1b,
CBOR_STRING8_MUST_BE_7BIT = 0x1c, CBOR_TRAILING_JUNK = 0x1c,
CBOR_TRAILING_JUNK = 0x1d, CBOR_MAP_START_EXPECTED = 0x1d,
CBOR_MAP_START_EXPECTED = 0x1e, CBOR_MAP_STOP_EXPECTED = 0x1e,
CBOR_MAP_STOP_EXPECTED = 0x1f, CBOR_ENVELOPE_SIZE_LIMIT_EXCEEDED = 0x1f,
CBOR_ENVELOPE_SIZE_LIMIT_EXCEEDED = 0x20,
}; };
// A status value with position that can be copied. The default status // A status value with position that can be copied. The default status
...@@ -120,6 +132,13 @@ struct Status { ...@@ -120,6 +132,13 @@ struct Status {
std::ptrdiff_t pos = npos(); std::ptrdiff_t pos = npos();
Status(Error error, std::ptrdiff_t pos) : error(error), pos(pos) {} Status(Error error, std::ptrdiff_t pos) : error(error), pos(pos) {}
Status() = default; Status() = default;
// Returns a 7 bit US-ASCII string, either "OK" or an error message
// that includes the position.
std::string ToASCIIString() const;
private:
std::string ToASCIIString(const char* msg) const;
}; };
// Handler interface for parser events emitted by a streaming parser. // Handler interface for parser events emitted by a streaming parser.
......
...@@ -74,20 +74,20 @@ def parse(data, file_name, map_binary_to_string=False): ...@@ -74,20 +74,20 @@ def parse(data, file_name, map_binary_to_string=False):
if len(trimLine) == 0: if len(trimLine) == 0:
continue continue
match = re.compile('^(experimental )?(deprecated )?domain (.*)').match(line) match = re.compile(r'^(experimental )?(deprecated )?domain (.*)').match(line)
if match: if match:
domain = createItem({'domain' : match.group(3)}, match.group(1), match.group(2)) domain = createItem({'domain' : match.group(3)}, match.group(1), match.group(2))
protocol['domains'].append(domain) protocol['domains'].append(domain)
continue continue
match = re.compile('^ depends on ([^\s]+)').match(line) match = re.compile(r'^ depends on ([^\s]+)').match(line)
if match: if match:
if 'dependencies' not in domain: if 'dependencies' not in domain:
domain['dependencies'] = [] domain['dependencies'] = []
domain['dependencies'].append(match.group(1)) domain['dependencies'].append(match.group(1))
continue continue
match = re.compile('^ (experimental )?(deprecated )?type (.*) extends (array of )?([^\s]+)').match(line) match = re.compile(r'^ (experimental )?(deprecated )?type (.*) extends (array of )?([^\s]+)').match(line)
if match: if match:
if 'types' not in domain: if 'types' not in domain:
domain['types'] = [] domain['types'] = []
...@@ -96,7 +96,7 @@ def parse(data, file_name, map_binary_to_string=False): ...@@ -96,7 +96,7 @@ def parse(data, file_name, map_binary_to_string=False):
domain['types'].append(item) domain['types'].append(item)
continue continue
match = re.compile('^ (experimental )?(deprecated )?(command|event) (.*)').match(line) match = re.compile(r'^ (experimental )?(deprecated )?(command|event) (.*)').match(line)
if match: if match:
list = [] list = []
if match.group(3) == 'command': if match.group(3) == 'command':
...@@ -114,7 +114,7 @@ def parse(data, file_name, map_binary_to_string=False): ...@@ -114,7 +114,7 @@ def parse(data, file_name, map_binary_to_string=False):
list.append(item) list.append(item)
continue continue
match = re.compile('^ (experimental )?(deprecated )?(optional )?(array of )?([^\s]+) ([^\s]+)').match(line) match = re.compile(r'^ (experimental )?(deprecated )?(optional )?(array of )?([^\s]+) ([^\s]+)').match(line)
if match: if match:
param = createItem({}, match.group(1), match.group(2), match.group(6)) param = createItem({}, match.group(1), match.group(2), match.group(6))
if match.group(3): if match.group(3):
...@@ -125,36 +125,36 @@ def parse(data, file_name, map_binary_to_string=False): ...@@ -125,36 +125,36 @@ def parse(data, file_name, map_binary_to_string=False):
subitems.append(param) subitems.append(param)
continue continue
match = re.compile('^ (parameters|returns|properties)').match(line) match = re.compile(r'^ (parameters|returns|properties)').match(line)
if match: if match:
subitems = item[match.group(1)] = [] subitems = item[match.group(1)] = []
continue continue
match = re.compile('^ enum').match(line) match = re.compile(r'^ enum').match(line)
if match: if match:
enumliterals = item['enum'] = [] enumliterals = item['enum'] = []
continue continue
match = re.compile('^version').match(line) match = re.compile(r'^version').match(line)
if match: if match:
continue continue
match = re.compile('^ major (\d+)').match(line) match = re.compile(r'^ major (\d+)').match(line)
if match: if match:
protocol['version']['major'] = match.group(1) protocol['version']['major'] = match.group(1)
continue continue
match = re.compile('^ minor (\d+)').match(line) match = re.compile(r'^ minor (\d+)').match(line)
if match: if match:
protocol['version']['minor'] = match.group(1) protocol['version']['minor'] = match.group(1)
continue continue
match = re.compile('^ redirect ([^\s]+)').match(line) match = re.compile(r'^ redirect ([^\s]+)').match(line)
if match: if match:
item['redirect'] = match.group(1) item['redirect'] = match.group(1)
continue continue
match = re.compile('^ ( )?[^\s]+$').match(line) match = re.compile(r'^ ( )?[^\s]+$').match(line)
if match: if match:
# enum literal # enum literal
enumliterals.append(trimLine) enumliterals.append(trimLine)
......
...@@ -203,12 +203,12 @@ void Frontend::flush() ...@@ -203,12 +203,12 @@ void Frontend::flush()
m_frontendChannel->flushProtocolNotifications(); m_frontendChannel->flushProtocolNotifications();
} }
void Frontend::sendRawNotification(String notification) void Frontend::sendRawJSONNotification(String notification)
{ {
m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification))); m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
} }
void Frontend::sendRawNotification(std::vector<uint8_t> notification) void Frontend::sendRawCBORNotification(std::vector<uint8_t> notification)
{ {
m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification))); m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
} }
......
...@@ -269,8 +269,8 @@ public: ...@@ -269,8 +269,8 @@ public:
{% endfor %} {% endfor %}
void flush(); void flush();
void sendRawNotification(String); void sendRawJSONNotification(String);
void sendRawNotification(std::vector<uint8_t>); void sendRawCBORNotification(std::vector<uint8_t>);
private: private:
FrontendChannel* m_frontendChannel; FrontendChannel* m_frontendChannel;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment