Commit cd0015aa authored by yangguo's avatar yangguo Committed by Commit bot

Remove d8's interactive Javascript debugger.

The code is unmaintained and full of errors...
but this CL wipes them all away.

Nobody seems to use it anyways.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/1243213004

Cr-Commit-Position: refs/heads/master@{#29801}
parent af6e874e
......@@ -1761,8 +1761,6 @@ if ((current_toolchain == host_toolchain && v8_toolset_for_d8 == "host") ||
if (!is_component_build) {
sources += [
"src/d8-debug.cc",
"src/d8-debug.h",
"$target_gen_dir/d8-js.cc",
]
}
......
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/d8.h"
#include "src/d8-debug.h"
namespace v8 {
void PrintPrompt(bool is_running) {
const char* prompt = is_running? "> " : "dbg> ";
printf("%s", prompt);
fflush(stdout);
}
void HandleDebugEvent(const Debug::EventDetails& event_details) {
// TODO(svenpanne) There should be a way to retrieve this in the callback.
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
DebugEvent event = event_details.GetEvent();
// Check for handled event.
if (event != Break && event != Exception && event != AfterCompile) {
return;
}
TryCatch try_catch(isolate);
// Get the toJSONProtocol function on the event and get the JSON format.
Local<String> to_json_fun_name =
String::NewFromUtf8(isolate, "toJSONProtocol", NewStringType::kNormal)
.ToLocalChecked();
Local<Object> event_data = event_details.GetEventData();
Local<Function> to_json_fun =
Local<Function>::Cast(event_data->Get(isolate->GetCurrentContext(),
to_json_fun_name).ToLocalChecked());
Local<Value> event_json;
if (!to_json_fun->Call(isolate->GetCurrentContext(), event_data, 0, NULL)
.ToLocal(&event_json)) {
Shell::ReportException(isolate, &try_catch);
return;
}
// Print the event details.
Local<Object> details =
Shell::DebugMessageDetails(isolate, Local<String>::Cast(event_json));
if (try_catch.HasCaught()) {
Shell::ReportException(isolate, &try_catch);
return;
}
String::Utf8Value str(
details->Get(isolate->GetCurrentContext(),
String::NewFromUtf8(isolate, "text", NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked());
if (str.length() == 0) {
// Empty string is used to signal not to process this event.
return;
}
printf("%s\n", *str);
// Get the debug command processor.
Local<String> fun_name =
String::NewFromUtf8(isolate, "debugCommandProcessor",
NewStringType::kNormal).ToLocalChecked();
Local<Object> exec_state = event_details.GetExecutionState();
Local<Function> fun = Local<Function>::Cast(
exec_state->Get(isolate->GetCurrentContext(), fun_name).ToLocalChecked());
Local<Value> cmd_processor_value;
if (!fun->Call(isolate->GetCurrentContext(), exec_state, 0, NULL)
.ToLocal(&cmd_processor_value)) {
Shell::ReportException(isolate, &try_catch);
return;
}
Local<Object> cmd_processor = Local<Object>::Cast(cmd_processor_value);
static const int kBufferSize = 256;
bool running = false;
while (!running) {
char command[kBufferSize];
PrintPrompt(running);
char* str = fgets(command, kBufferSize, stdin);
if (str == NULL) break;
// Ignore empty commands.
if (strlen(command) == 0) continue;
TryCatch try_catch(isolate);
// Convert the debugger command to a JSON debugger request.
Local<Value> request = Shell::DebugCommandToJSONRequest(
isolate, String::NewFromUtf8(isolate, command, NewStringType::kNormal)
.ToLocalChecked());
if (try_catch.HasCaught()) {
Shell::ReportException(isolate, &try_catch);
continue;
}
// If undefined is returned the command was handled internally and there is
// no JSON to send.
if (request->IsUndefined()) {
continue;
}
Local<String> fun_name;
Local<Function> fun;
// All the functions used below take one argument.
static const int kArgc = 1;
Local<Value> args[kArgc];
// Invoke the JavaScript to convert the debug command line to a JSON
// request, invoke the JSON request and convert the JSON respose to a text
// representation.
fun_name = String::NewFromUtf8(isolate, "processDebugRequest",
NewStringType::kNormal).ToLocalChecked();
fun = Local<Function>::Cast(cmd_processor->Get(isolate->GetCurrentContext(),
fun_name).ToLocalChecked());
args[0] = request;
Local<Value> response_val;
if (!fun->Call(isolate->GetCurrentContext(), cmd_processor, kArgc, args)
.ToLocal(&response_val)) {
Shell::ReportException(isolate, &try_catch);
continue;
}
Local<String> response = Local<String>::Cast(response_val);
// Convert the debugger response into text details and the running state.
Local<Object> response_details =
Shell::DebugMessageDetails(isolate, response);
if (try_catch.HasCaught()) {
Shell::ReportException(isolate, &try_catch);
continue;
}
String::Utf8Value text_str(
response_details->Get(isolate->GetCurrentContext(),
String::NewFromUtf8(isolate, "text",
NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked());
if (text_str.length() > 0) {
printf("%s\n", *text_str);
}
running = response_details->Get(isolate->GetCurrentContext(),
String::NewFromUtf8(isolate, "running",
NewStringType::kNormal)
.ToLocalChecked())
.ToLocalChecked()
->ToBoolean(isolate->GetCurrentContext())
.ToLocalChecked()
->Value();
}
}
} // namespace v8
// Copyright 2008 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_D8_DEBUG_H_
#define V8_D8_DEBUG_H_
#include "src/d8.h"
#include "src/debug.h"
namespace v8 {
void HandleDebugEvent(const Debug::EventDetails& event_details);
} // namespace v8
#endif // V8_D8_DEBUG_H_
......@@ -44,8 +44,6 @@
#include "src/base/platform/platform.h"
#include "src/base/sys-info.h"
#include "src/basic-block-profiler.h"
#include "src/d8-debug.h"
#include "src/debug.h"
#include "src/snapshot/natives.h"
#include "src/utils.h"
#include "src/v8.h"
......@@ -328,18 +326,9 @@ MaybeLocal<Script> Shell::CompileString(
bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
Local<Value> name, bool print_result,
bool report_exceptions, SourceType source_type) {
#ifndef V8_SHARED
bool FLAG_debugger = i::FLAG_debugger;
#else
bool FLAG_debugger = false;
#endif // !V8_SHARED
HandleScope handle_scope(isolate);
TryCatch try_catch(isolate);
options.script_executed = true;
if (FLAG_debugger) {
// When debugging make exceptions appear to be uncaught.
try_catch.SetVerbose(true);
}
MaybeLocal<Value> maybe_result;
{
......@@ -351,8 +340,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
if (!Shell::CompileString(isolate, source, name, options.compile_options,
source_type).ToLocal(&script)) {
// Print errors that happened during compilation.
if (report_exceptions && !FLAG_debugger)
ReportException(isolate, &try_catch);
if (report_exceptions) ReportException(isolate, &try_catch);
return false;
}
maybe_result = script->Run(realm);
......@@ -363,8 +351,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
if (!maybe_result.ToLocal(&result)) {
DCHECK(try_catch.HasCaught());
// Print errors that happened during execution.
if (report_exceptions && !FLAG_debugger)
ReportException(isolate, &try_catch);
if (report_exceptions) ReportException(isolate, &try_catch);
return false;
}
DCHECK(!try_catch.HasCaught());
......@@ -954,47 +941,6 @@ Local<Array> Shell::GetCompletions(Isolate* isolate, Local<String> text,
}
Local<Object> Shell::DebugMessageDetails(Isolate* isolate,
Local<String> message) {
EscapableHandleScope handle_scope(isolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
Local<Object> global = context->Global();
Local<Value> fun =
global->Get(context, String::NewFromUtf8(isolate, "DebugMessageDetails",
NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked();
static const int kArgc = 1;
Local<Value> argv[kArgc] = {message};
Local<Value> val = Local<Function>::Cast(fun)
->Call(context, global, kArgc, argv)
.ToLocalChecked();
return handle_scope.Escape(Local<Object>(Local<Object>::Cast(val)));
}
Local<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate,
Local<String> command) {
EscapableHandleScope handle_scope(isolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context);
Local<Object> global = context->Global();
Local<Value> fun =
global->Get(context,
String::NewFromUtf8(isolate, "DebugCommandToJSONRequest",
NewStringType::kNormal).ToLocalChecked())
.ToLocalChecked();
static const int kArgc = 1;
Local<Value> argv[kArgc] = {command};
Local<Value> val = Local<Function>::Cast(fun)
->Call(context, global, kArgc, argv)
.ToLocalChecked();
return handle_scope.Escape(Local<Value>(val));
}
int32_t* Counter::Bind(const char* name, bool is_histogram) {
int i;
for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
......@@ -1110,6 +1056,8 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
HandleScope scope(isolate);
// If we use the utility context, we have to set the security tokens so that
// utility, evaluation and debug context can all access each other.
Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
utility_context_.Reset(isolate, Context::New(isolate, NULL, global_template));
v8::Local<v8::Context> utility_context =
v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Local<v8::Context> evaluation_context =
......@@ -1118,22 +1066,6 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
evaluation_context->SetSecurityToken(Undefined(isolate));
v8::Context::Scope context_scope(utility_context);
if (i::FLAG_debugger) printf("JavaScript debugger enabled\n");
// Install the debugger object in the utility scope
i::Debug* debug = reinterpret_cast<i::Isolate*>(isolate)->debug();
debug->Load();
i::Handle<i::Context> debug_context = debug->debug_context();
i::Handle<i::JSObject> js_debug
= i::Handle<i::JSObject>(debug_context->global_object());
utility_context->Global()
->Set(utility_context,
String::NewFromUtf8(isolate, "$debug", NewStringType::kNormal)
.ToLocalChecked(),
Utils::ToLocal(js_debug))
.FromJust();
debug_context->set_security_token(
reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value());
// Run the d8 shell utility script in the utility context
int source_index = i::NativesCollection<i::D8>::GetIndex("d8");
i::Vector<const char> shell_source =
......@@ -1160,9 +1092,6 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
: i::Handle<i::Script>(i::Script::cast(
i::SharedFunctionInfo::cast(*compiled_script)->script()));
script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE));
// Start the in-process debugger if requested.
if (i::FLAG_debugger) v8::Debug::SetDebugEventListener(HandleDebugEvent);
}
#endif // !V8_SHARED
......@@ -1298,21 +1227,6 @@ void Shell::Initialize(Isolate* isolate) {
}
void Shell::InitializeDebugger(Isolate* isolate) {
if (options.test_shell) return;
#ifndef V8_SHARED
HandleScope scope(isolate);
Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
utility_context_.Reset(isolate,
Context::New(isolate, NULL, global_template));
if (utility_context_.IsEmpty()) {
printf("Failed to initialize debugger\n");
Shell::Exit(1);
}
#endif // !V8_SHARED
}
Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
#ifndef V8_SHARED
// This needs to be a critical section since this is not thread-safe
......@@ -2027,9 +1941,6 @@ bool Shell::SetOptions(int argc, char* argv[]) {
} else if (strcmp(argv[i], "--dump-counters") == 0) {
printf("D8 with shared library does not include counters\n");
return false;
} else if (strcmp(argv[i], "--debugger") == 0) {
printf("Javascript debugger not included\n");
return false;
#endif // V8_SHARED
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
} else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
......@@ -2103,13 +2014,6 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[]) {
if (options.last_run && options.use_interactive_shell()) {
// Keep using the same context in the interactive shell.
evaluation_context_.Reset(isolate, context);
#ifndef V8_SHARED
// If the interactive debugger is enabled make sure to activate
// it before running the files passed on the command line.
if (i::FLAG_debugger) {
InstallUtilityScript(isolate);
}
#endif // !V8_SHARED
}
{
Context::Scope cscope(context);
......@@ -2535,7 +2439,6 @@ int Shell::Main(int argc, char* argv[]) {
Isolate::Scope scope(isolate);
Initialize(isolate);
PerIsolateData data(isolate);
InitializeDebugger(isolate);
#ifndef V8_SHARED
if (options.dump_heap_constants) {
......@@ -2574,9 +2477,7 @@ int Shell::Main(int argc, char* argv[]) {
// executed, but never on --test
if (options.use_interactive_shell()) {
#ifndef V8_SHARED
if (!i::FLAG_debugger) {
InstallUtilityScript(isolate);
}
InstallUtilityScript(isolate);
#endif // !V8_SHARED
RunShell(isolate);
}
......
......@@ -75,8 +75,6 @@
}],
[ 'component!="shared_library"', {
'sources': [
'd8-debug.h',
'd8-debug.cc',
'<(SHARED_INTERMEDIATE_DIR)/d8-js.cc',
],
'conditions': [
......
......@@ -390,11 +390,6 @@ class Shell : public i::AllStatic {
static void AddHistogramSample(void* histogram, int sample);
static void MapCounters(v8::Isolate* isolate, const char* name);
static Local<Object> DebugMessageDetails(Isolate* isolate,
Local<String> message);
static Local<Value> DebugCommandToJSONRequest(Isolate* isolate,
Local<String> command);
static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args);
#endif // !V8_SHARED
......@@ -492,7 +487,6 @@ class Shell : public i::AllStatic {
static void InstallUtilityScript(Isolate* isolate);
#endif // !V8_SHARED
static void Initialize(Isolate* isolate);
static void InitializeDebugger(Isolate* isolate);
static void RunShell(Isolate* isolate);
static bool SetOptions(int argc, char* argv[]);
static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
......
This diff is collapsed.
......@@ -804,8 +804,6 @@ DEFINE_BOOL(manual_evacuation_candidates_selection, false,
DEFINE_BOOL(help, false, "Print usage message, including flags, on console")
DEFINE_BOOL(dump_counters, false, "Dump counters on exit")
DEFINE_BOOL(debugger, false, "Enable JavaScript debugger")
DEFINE_STRING(map_counters, "", "Map counters to a file")
DEFINE_ARGS(js_arguments,
"Pass all remaining arguments to the script. Alias for \"--\".")
......
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