Skip to content

Commit

Permalink
More debugging, only snapshots don't work now
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Mar 14, 2020
1 parent 0481d8a commit 5fe59da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 4 additions & 2 deletions c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ clean:: local-clean
distclean:: local-distclean

local-clean:
cd $(V8_DIR) && $(DEPOT_DIR)/ninja -C out.gn/$(BUILD_ARCH).release -t clean erlang_v8
rm $(V8_LIB)/libv8_base.a
rm -rf $(TARGET_BIN)

local-distclean: local-clean
Expand Down Expand Up @@ -59,8 +61,8 @@ $(V8_LIB)/libv8_base.a: $(V8_DIR)
@echo "ROOT dir $(ROOT_DIR)"
#cd $(LIB_DIR) && gclient sync --revision $(V8_VERSION)
cd $(V8_DIR) && tools/dev/v8gen.py -vv $(BUILD_ARCH).release
cd $(V8_DIR) && gn gen "--args=is_component_build = false is_debug = false v8_static_library = true target_cpu = \"$(BUILD_ARCH)\"" out.gn/$(BUILD_ARCH).release
cd $(V8_DIR) && $(DEPOT_DIR)/ninja -C out.gn/$(BUILD_ARCH).release
cd $(V8_DIR) && gn gen "--args=is_component_build = true is_debug = true v8_static_library = true target_cpu = \"$(BUILD_ARCH)\"" out.gn/$(BUILD_ARCH).release
cd $(V8_DIR) && $(DEPOT_DIR)/ninja -C out.gn/$(BUILD_ARCH).release erlang_v8 v8_hello_world
@touch $@

$(PRIV_DIR)/natives_blob.bin: $(V8_LIB)/libv8_base.a
Expand Down
8 changes: 4 additions & 4 deletions c_src/erlang_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ int main(int argc, char* argv[]) {
source = NULL;
}

StartupData snapshot = create_snapshot_data_blob(source);
//StartupData snapshot = create_snapshot_data_blob(source);

ArrayBufferAllocator allocator;
params.snapshot_blob = &snapshot;
params.array_buffer_allocator = &allocator;
//params.snapshot_blob = &snapshot;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();

Isolate* isolate = Isolate::New(params);

Expand Down
5 changes: 4 additions & 1 deletion c_src/report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ void ReportError(Isolate* isolate, Local<Value> response) {

void ReportException(Isolate* isolate, TryCatch* try_catch) {
HandleScope handle_scope(isolate);
TRACE("CTX\n");
Local<Context> context = isolate->GetCurrentContext();
Local<Value> stack_trace = try_catch->StackTrace(context).ToLocalChecked();
TRACE("STACK\n");
MaybeLocal<Value> stack_trace = try_catch->StackTrace(context);

if (stack_trace.IsEmpty()) {
ReportError(isolate, try_catch->Exception());
} else {
TRACE("CSTR\n");
const char* st = ToCString(String::Utf8Value(isolate, try_catch->StackTrace(context).ToLocalChecked()));
FTRACE("Stack: %s\n", st);
ReportError(isolate, try_catch->StackTrace(context).ToLocalChecked());
Expand Down
13 changes: 10 additions & 3 deletions c_src/vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void VM::Eval(Packet* packet) {
Local<Context> context = Local<Context>::New(isolate,
contexts[packet->ref]);

TRACE("Marker \n");
if (context.IsEmpty()) {
Local<String> tt = String::NewFromUtf8(isolate, "empty context").ToLocalChecked();
Report(isolate, tt, OP_INVALID_CONTEXT);
Expand All @@ -108,17 +109,20 @@ void VM::Eval(Packet* packet) {

string input = packet->data;

TRACE("Marker\n");
Local<String> json_data = String::NewFromUtf8(isolate, input.c_str()).ToLocalChecked();
Local<Object> instructions = Local<Object>::Cast(
JSON::Parse(context, json_data).ToLocalChecked()
);

TRACE("Marker\n");
Local<String> timeout_key = String::NewFromUtf8(isolate, "timeout").ToLocalChecked();
Local<String> source_key = String::NewFromUtf8(isolate, "source").ToLocalChecked();

Local<String> source = instructions->Get(context, source_key).ToLocalChecked()->ToString(context).ToLocalChecked();
Local<Integer> timeout = instructions->Get(context, timeout_key).ToLocalChecked()->ToInteger(context).ToLocalChecked();

TRACE("Marker\n");
Local<Script> script = Script::Compile(context, source).ToLocalChecked();

if (script.IsEmpty()) {
Expand All @@ -133,13 +137,14 @@ void VM::Eval(Packet* packet) {
};

pthread_create(&t, NULL, TimeoutHandler, &timeout_handler_args);
TRACE("Fork\n");

Local<Value> result = script->Run(context).ToLocalChecked();
MaybeLocal<Value> result = script->Run(context);

pthread_cancel(t);
pthread_join(t, &res);

// FTRACE("Join: %x\n", res);
FTRACE("Join: %p\n", res);

if (result.IsEmpty()) {
assert(try_catch.HasCaught());
Expand All @@ -153,7 +158,7 @@ void VM::Eval(Packet* packet) {
}
// vm.CreateContext(packet->ref);
} else {
ReportOK(isolate, result);
ReportOK(isolate, result.ToLocalChecked());
}
}
}
Expand Down Expand Up @@ -217,11 +222,13 @@ void VM::Call(Packet* packet) {
};

pthread_create(&t, NULL, TimeoutHandler, &timeout_handler_args);
TRACE("Fork\n");

Local<Value> eval_result = script->Run(context).ToLocalChecked();

pthread_cancel(t);
pthread_join(t, &res);
FTRACE("Join: %p\n", res);

if (eval_result.IsEmpty()) {
assert(try_catch.HasCaught());
Expand Down

0 comments on commit 5fe59da

Please sign in to comment.