Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@47ae4a21b0] [1.6>1.7] [MERGE #3486 @Cel…
Browse files Browse the repository at this point in the history
…lule] WASM - fix assert in jsrt debugger

Merge pull request #3486 from Cellule:users/micfer/wasm/debug

Support WebAssembly types in Jsrt debugger.
Add more wasm debugger test and move them to DebuggerCommon
  • Loading branch information
chakrabot committed Aug 12, 2017
1 parent 550e98b commit 8a7b363
Show file tree
Hide file tree
Showing 16 changed files with 506 additions and 178 deletions.
120 changes: 52 additions & 68 deletions deps/chakrashim/core/bin/ch/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,74 +244,58 @@ LPCWSTR Helpers::JsErrorCodeToString(JsErrorCode jsErrorCode)

switch (jsErrorCode)
{
case JsNoError:
return _u("JsNoError");
break;

case JsErrorInvalidArgument:
return _u("JsErrorInvalidArgument");
break;

case JsErrorNullArgument:
return _u("JsErrorNullArgument");
break;

case JsErrorNoCurrentContext:
return _u("JsErrorNoCurrentContext");
break;

case JsErrorInExceptionState:
return _u("JsErrorInExceptionState");
break;

case JsErrorNotImplemented:
return _u("JsErrorNotImplemented");
break;

case JsErrorWrongThread:
return _u("JsErrorWrongThread");
break;

case JsErrorRuntimeInUse:
return _u("JsErrorRuntimeInUse");
break;

case JsErrorBadSerializedScript:
return _u("JsErrorBadSerializedScript");
break;

case JsErrorInDisabledState:
return _u("JsErrorInDisabledState");
break;

case JsErrorCannotDisableExecution:
return _u("JsErrorCannotDisableExecution");
break;

case JsErrorHeapEnumInProgress:
return _u("JsErrorHeapEnumInProgress");
break;

case JsErrorOutOfMemory:
return _u("JsErrorOutOfMemory");
break;

case JsErrorScriptException:
return _u("JsErrorScriptException");
break;

case JsErrorScriptCompile:
return _u("JsErrorScriptCompile");
break;

case JsErrorScriptTerminated:
return _u("JsErrorScriptTerminated");
break;

case JsErrorFatal:
return _u("JsErrorFatal");
break;

case JsNoError: return _u("JsNoError");
// JsErrorCategoryUsage
case JsErrorCategoryUsage: return _u("JsErrorCategoryUsage");
case JsErrorInvalidArgument: return _u("JsErrorInvalidArgument");
case JsErrorNullArgument: return _u("JsErrorNullArgument");
case JsErrorNoCurrentContext: return _u("JsErrorNoCurrentContext");
case JsErrorInExceptionState: return _u("JsErrorInExceptionState");
case JsErrorNotImplemented: return _u("JsErrorNotImplemented");
case JsErrorWrongThread: return _u("JsErrorWrongThread");
case JsErrorRuntimeInUse: return _u("JsErrorRuntimeInUse");
case JsErrorBadSerializedScript: return _u("JsErrorBadSerializedScript");
case JsErrorInDisabledState: return _u("JsErrorInDisabledState");
case JsErrorCannotDisableExecution: return _u("JsErrorCannotDisableExecution");
case JsErrorHeapEnumInProgress: return _u("JsErrorHeapEnumInProgress");
case JsErrorArgumentNotObject: return _u("JsErrorArgumentNotObject");
case JsErrorInProfileCallback: return _u("JsErrorInProfileCallback");
case JsErrorInThreadServiceCallback: return _u("JsErrorInThreadServiceCallback");
case JsErrorCannotSerializeDebugScript: return _u("JsErrorCannotSerializeDebugScript");
case JsErrorAlreadyDebuggingContext: return _u("JsErrorAlreadyDebuggingContext");
case JsErrorAlreadyProfilingContext: return _u("JsErrorAlreadyProfilingContext");
case JsErrorIdleNotEnabled: return _u("JsErrorIdleNotEnabled");
case JsCannotSetProjectionEnqueueCallback: return _u("JsCannotSetProjectionEnqueueCallback");
case JsErrorCannotStartProjection: return _u("JsErrorCannotStartProjection");
case JsErrorInObjectBeforeCollectCallback: return _u("JsErrorInObjectBeforeCollectCallback");
case JsErrorObjectNotInspectable: return _u("JsErrorObjectNotInspectable");
case JsErrorPropertyNotSymbol: return _u("JsErrorPropertyNotSymbol");
case JsErrorPropertyNotString: return _u("JsErrorPropertyNotString");
case JsErrorInvalidContext: return _u("JsErrorInvalidContext");
case JsInvalidModuleHostInfoKind: return _u("JsInvalidModuleHostInfoKind");
case JsErrorModuleParsed: return _u("JsErrorModuleParsed");
// JsErrorCategoryEngine
case JsErrorCategoryEngine: return _u("JsErrorCategoryEngine");
case JsErrorOutOfMemory: return _u("JsErrorOutOfMemory");
case JsErrorBadFPUState: return _u("JsErrorBadFPUState");
// JsErrorCategoryScript
case JsErrorCategoryScript: return _u("JsErrorCategoryScript");
case JsErrorScriptException: return _u("JsErrorScriptException");
case JsErrorScriptCompile: return _u("JsErrorScriptCompile");
case JsErrorScriptTerminated: return _u("JsErrorScriptTerminated");
case JsErrorScriptEvalDisabled: return _u("JsErrorScriptEvalDisabled");
// JsErrorCategoryFatal
case JsErrorCategoryFatal: return _u("JsErrorCategoryFatal");
case JsErrorFatal: return _u("JsErrorFatal");
case JsErrorWrongRuntime: return _u("JsErrorWrongRuntime");
// JsErrorCategoryDiagError
case JsErrorCategoryDiagError: return _u("JsErrorCategoryDiagError");
case JsErrorDiagAlreadyInDebugMode: return _u("JsErrorDiagAlreadyInDebugMode");
case JsErrorDiagNotInDebugMode: return _u("JsErrorDiagNotInDebugMode");
case JsErrorDiagNotAtBreak: return _u("JsErrorDiagNotAtBreak");
case JsErrorDiagInvalidHandle: return _u("JsErrorDiagInvalidHandle");
case JsErrorDiagObjectNotFound: return _u("JsErrorDiagObjectNotFound");
case JsErrorDiagUnableToPerformAction: return _u("JsErrorDiagUnableToPerformAction");
default:
return _u("<unknown>");
break;
Expand Down
13 changes: 12 additions & 1 deletion deps/chakrashim/core/lib/Jsrt/JsrtDebugUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ void JsrtDebugUtils::AddPropertyType(Js::DynamicObject * object, Js::IDiagObject
case Js::TypeIds_Promise:
case Js::TypeIds_GlobalObject:
case Js::TypeIds_SpreadArgument:
#ifdef ENABLE_WASM
case Js::TypeIds_WebAssemblyModule:
case Js::TypeIds_WebAssemblyInstance:
case Js::TypeIds_WebAssemblyMemory:
case Js::TypeIds_WebAssemblyTable:
#endif

case Js::TypeIds_Proxy:
{
Expand Down Expand Up @@ -480,7 +486,12 @@ const char16 * JsrtDebugUtils::GetClassName(Js::TypeId typeId)
case Js::TypeIds_Promise: return _u("Promise");
case Js::TypeIds_GlobalObject: return _u("Object");
case Js::TypeIds_SpreadArgument: return _u("Spread");

#ifdef ENABLE_WASM
case Js::TypeIds_WebAssemblyModule: return _u("WebAssembly.Module");
case Js::TypeIds_WebAssemblyInstance:return _u("WebAssembly.Instance");
case Js::TypeIds_WebAssemblyMemory: return _u("WebAssembly.Memory");
case Js::TypeIds_WebAssemblyTable: return _u("WebAssembly.Table");
#endif
default:
Assert(false);
}
Expand Down
2 changes: 2 additions & 0 deletions deps/chakrashim/core/lib/Runtime/Library/ScriptFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ namespace Js

private:
Field(Field(Var)*) m_moduleMemory;
#ifdef ENABLE_WASM
Field(Wasm::WasmSignature *) m_signature;
#endif
};

class ScriptFunctionWithInlineCache : public ScriptFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
//-------------------------------------------------------------------------------------------------------

#pragma once
#ifdef ENABLE_WASM

namespace Js
{
class WebAssemblyInstance : public DynamicObject
{
protected:
DEFINE_VTABLE_CTOR(WebAssemblyInstance, DynamicObject);
DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(WebAssemblyInstance);

public:
class EntryInfo
{
Expand Down Expand Up @@ -40,3 +45,4 @@ namespace Js
};

} // namespace Js
#endif
40 changes: 22 additions & 18 deletions deps/chakrashim/core/lib/Runtime/Library/WebAssemblyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
m_memoryMaxSize(0),
m_tableInitSize(0),
m_tableMaxSize(0),
m_alloc(_u("WebAssemblyModule"), scriptContext->GetThreadContext()->GetPageAllocator(), Js::Throw::OutOfMemory),
m_indirectfuncs(nullptr),
m_exports(nullptr),
m_exportCount(0),
Expand All @@ -37,12 +36,13 @@ WebAssemblyModule::WebAssemblyModule(Js::ScriptContext* scriptContext, const byt
m_binaryBufferLength(binaryBufferLength),
m_customSections(nullptr)
{
m_alloc = HeapNew(ArenaAllocator, _u("WebAssemblyModule"), scriptContext->GetThreadContext()->GetPageAllocator(), Js::Throw::OutOfMemory);
//the first elm is the number of Vars in front of I32; makes for a nicer offset computation
memset(m_globalCounts, 0, sizeof(uint) * Wasm::WasmTypes::Limit);
m_functionsInfo = RecyclerNew(scriptContext->GetRecycler(), WasmFunctionInfosList, scriptContext->GetRecycler());
m_imports = Anew(&m_alloc, WasmImportsList, &m_alloc);
m_globals = Anew(&m_alloc, WasmGlobalsList, &m_alloc);
m_reader = Anew(&m_alloc, Wasm::WasmBinaryReader, &m_alloc, this, binaryBuffer, binaryBufferLength);
m_imports = Anew(m_alloc, WasmImportsList, m_alloc);
m_globals = Anew(m_alloc, WasmGlobalsList, m_alloc);
m_reader = Anew(m_alloc, Wasm::WasmBinaryReader, m_alloc, this, binaryBuffer, binaryBufferLength);
}

/* static */
Expand Down Expand Up @@ -428,7 +428,7 @@ WebAssemblyModule::AddWasmFunctionInfo(Wasm::WasmSignature* sig)
{
uint32 functionId = GetWasmFunctionCount();
// must be recycler memory, since it holds reference to the function body
Wasm::WasmFunctionInfo* funcInfo = RecyclerNew(GetRecycler(), Wasm::WasmFunctionInfo, &m_alloc, sig, functionId);
Wasm::WasmFunctionInfo* funcInfo = RecyclerNew(GetRecycler(), Wasm::WasmFunctionInfo, m_alloc, sig, functionId);
m_functionsInfo->Add(funcInfo);
return funcInfo;
}
Expand Down Expand Up @@ -464,7 +464,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
throw Wasm::WasmCompilationException(_u("InOut tracing reader signature mismatch"));
}
// Create the custom reader to generate the import thunk
Wasm::WasmCustomReader* customReader = Anew(&m_alloc, Wasm::WasmCustomReader, &m_alloc);
Wasm::WasmCustomReader* customReader = Anew(m_alloc, Wasm::WasmCustomReader, m_alloc);
// Print the function name we are calling
{
Wasm::WasmNode nameNode;
Expand Down Expand Up @@ -543,7 +543,7 @@ WebAssemblyModule::AttachCustomInOutTracingReader(Wasm::WasmFunctionInfo* func,
void
WebAssemblyModule::AllocateFunctionExports(uint32 entries)
{
m_exports = AnewArrayZ(&m_alloc, Wasm::WasmExport, entries);
m_exports = AnewArrayZ(m_alloc, Wasm::WasmExport, entries);
m_exportCount = entries;
}

Expand Down Expand Up @@ -581,7 +581,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
}

// Store the information about the import
Wasm::WasmImport* importInfo = Anew(&m_alloc, Wasm::WasmImport);
Wasm::WasmImport* importInfo = Anew(m_alloc, Wasm::WasmImport);
importInfo->kind = Wasm::ExternalKinds::Function;
importInfo->modNameLen = modNameLen;
importInfo->modName = modName;
Expand All @@ -592,7 +592,7 @@ WebAssemblyModule::AddFunctionImport(uint32 sigId, const char16* modName, uint32
Wasm::WasmSignature* signature = GetSignature(sigId);
Wasm::WasmFunctionInfo* funcInfo = AddWasmFunctionInfo(signature);
// Create the custom reader to generate the import thunk
Wasm::WasmCustomReader* customReader = Anew(&m_alloc, Wasm::WasmCustomReader, &m_alloc);
Wasm::WasmCustomReader* customReader = Anew(m_alloc, Wasm::WasmCustomReader, m_alloc);
for (uint32 iParam = 0; iParam < (uint32)signature->GetParamCount(); iParam++)
{
Wasm::WasmNode node;
Expand Down Expand Up @@ -641,7 +641,7 @@ WebAssemblyModule::GetImport(uint32 i) const
void
WebAssemblyModule::AddGlobalImport(const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
{
Wasm::WasmImport* wi = Anew(&m_alloc, Wasm::WasmImport);
Wasm::WasmImport* wi = Anew(m_alloc, Wasm::WasmImport);
wi->kind = Wasm::ExternalKinds::Global;
wi->importName = importName;
wi->importNameLen = importNameLen;
Expand All @@ -653,7 +653,7 @@ WebAssemblyModule::AddGlobalImport(const char16* modName, uint32 modNameLen, con
void
WebAssemblyModule::AddMemoryImport(const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
{
Wasm::WasmImport* wi = Anew(&m_alloc, Wasm::WasmImport);
Wasm::WasmImport* wi = Anew(m_alloc, Wasm::WasmImport);
wi->kind = Wasm::ExternalKinds::Memory;
wi->importName = importName;
wi->importNameLen = importNameLen;
Expand All @@ -666,7 +666,7 @@ WebAssemblyModule::AddMemoryImport(const char16* modName, uint32 modNameLen, con
void
WebAssemblyModule::AddTableImport(const char16* modName, uint32 modNameLen, const char16* importName, uint32 importNameLen)
{
Wasm::WasmImport* wi = Anew(&m_alloc, Wasm::WasmImport);
Wasm::WasmImport* wi = Anew(m_alloc, Wasm::WasmImport);
wi->kind = Wasm::ExternalKinds::Table;
wi->importName = importName;
wi->importNameLen = importNameLen;
Expand Down Expand Up @@ -724,7 +724,7 @@ WebAssemblyModule::ValidateInitExportForOffset(const Wasm::WasmNode& initExpr) c
void
WebAssemblyModule::AddGlobal(Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
{
Wasm::WasmGlobal* global = Anew(&m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
Wasm::WasmGlobal* global = Anew(m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
m_globals->Add(global);
}

Expand All @@ -749,7 +749,7 @@ WebAssemblyModule::AllocateDataSegs(uint32 count)
{
Assert(count != 0);
m_datasegCount = count;
m_datasegs = AnewArray(&m_alloc, Wasm::WasmDataSegment*, count);
m_datasegs = AnewArray(m_alloc, Wasm::WasmDataSegment*, count);
}

void
Expand All @@ -774,7 +774,7 @@ WebAssemblyModule::AllocateElementSegs(uint32 count)
{
Assert(count != 0);
m_elementsegCount = count;
m_elementsegs = AnewArrayZ(&m_alloc, Wasm::WasmElementSegment*, count);
m_elementsegs = AnewArrayZ(m_alloc, Wasm::WasmElementSegment*, count);
}

void
Expand Down Expand Up @@ -834,13 +834,17 @@ WebAssemblyModule::GetModuleEnvironmentSize() const
void
WebAssemblyModule::Finalize(bool isShutdown)
{
m_alloc.Clear();
if (m_alloc)
{
HeapDelete(m_alloc);
m_alloc = nullptr;
}
}

void
WebAssemblyModule::Dispose(bool isShutdown)
{
Assert(m_alloc.Size() == 0);
Assert(!m_alloc);
}

void
Expand Down Expand Up @@ -915,7 +919,7 @@ WebAssemblyModule::AddCustomSection(Wasm::CustomSection customSection)
{
if (!m_customSections)
{
m_customSections = Anew(&m_alloc, CustomSectionsList, &m_alloc);
m_customSections = Anew(m_alloc, CustomSectionsList, m_alloc);
}
m_customSections->Add(customSection);
}
Expand Down
9 changes: 7 additions & 2 deletions deps/chakrashim/core/lib/Runtime/Library/WebAssemblyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

#pragma once

#ifdef ENABLE_WASM
#include "../WasmReader/WasmParseTree.h"

namespace Wasm
Expand All @@ -24,6 +24,10 @@ namespace Js
{
class WebAssemblyModule : public DynamicObject
{
protected:
DEFINE_VTABLE_CTOR(WebAssemblyModule, DynamicObject);
DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(WebAssemblyModule);

public:

class EntryInfo
Expand Down Expand Up @@ -187,7 +191,8 @@ class WebAssemblyModule : public DynamicObject

Field(uint32) m_startFuncIndex;

FieldNoBarrier(ArenaAllocator) m_alloc;
FieldNoBarrier(ArenaAllocator*) m_alloc;
};

} // namespace Js
#endif
1 change: 0 additions & 1 deletion deps/chakrashim/core/test/wasm/debugger.js.dbg.baseline

This file was deleted.

Binary file removed deps/chakrashim/core/test/wasm/debugger.wasm
Binary file not shown.
20 changes: 0 additions & 20 deletions deps/chakrashim/core/test/wasm/debugger.wast

This file was deleted.

Loading

0 comments on commit 8a7b363

Please sign in to comment.