加载依赖库时异常,异常定位信息增强

issues:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9QG90

Signed-off-by: rentangyu <rentangyu@huawei.com>
This commit is contained in:
rentangyu 2024-05-19 18:16:05 +08:00
parent a22f6ca7ad
commit af7c281cc0
19 changed files with 184 additions and 2 deletions

View File

@ -650,6 +650,7 @@ ecma_source = [
"ecmascript/deoptimizer/calleeReg.cpp",
"ecmascript/deoptimizer/deoptimizer.cpp",
"ecmascript/dfx/dump_code/jit_dump_elf.cpp",
"ecmascript/dfx/native_module_error.cpp",
"ecmascript/dfx/stackinfo/js_stackinfo.cpp",
"ecmascript/dfx/vmstat/caller_stat.cpp",
"ecmascript/dfx/vmstat/function_call_timer.cpp",

View File

@ -60,6 +60,7 @@
#include "ecmascript/builtins/builtins_weak_ref.h"
#include "ecmascript/builtins/builtins_weak_set.h"
#include "ecmascript/containers/containers_private.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/global_index.h"
#include "ecmascript/js_array.h"
@ -393,6 +394,7 @@ void Builtins::Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool
thread->CheckSafepointIfSuspended();
#endif
InitializeModuleNamespace(env, objFuncClass);
InitializeNativeModuleError(env, objFuncClass);
InitializeCjsModule(env);
InitializeCjsExports(env);
InitializeCjsRequire(env);
@ -3766,6 +3768,21 @@ void Builtins::InitializeModuleNamespace(const JSHandle<GlobalEnv> &env,
SetStringTagSymbol(env, moduleNamespacePrototype, "Module");
}
void Builtins::InitializeNativeModuleError(const JSHandle<GlobalEnv> &env,
const JSHandle<JSHClass> &objFuncClass) const
{
[[maybe_unused]] EcmaHandleScope scope(thread_);
// NativeModuleError.prototype
JSHandle<JSObject> nativeModuleErrorPrototype = factory_->NewJSObjectWithInit(objFuncClass);
JSHandle<JSTaggedValue> nativeModuleErrorPrototypeValue(nativeModuleErrorPrototype);
// NativeModuleError.prototype_or_hclass
JSHandle<JSHClass> nativeModuleErrorHClass =
factory_->NewEcmaHClass(NativeModuleError::SIZE, JSType::NATIVE_MODULE_ERROR, nativeModuleErrorPrototypeValue);
nativeModuleErrorHClass->SetPrototype(thread_, JSTaggedValue::Null());
env->SetNativeModuleErrorClass(thread_, nativeModuleErrorHClass.GetTaggedValue());
}
void Builtins::InitializeCjsModule(const JSHandle<GlobalEnv> &env) const
{
[[maybe_unused]] EcmaHandleScope scope(thread_);

View File

@ -281,6 +281,8 @@ private:
void InitializeSModuleNamespace(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &sObjIHClass) const;
void InitializeNativeModuleError(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &objFuncClass) const;
void InitializeCjsModule(const JSHandle<GlobalEnv> &env) const;
void InitializeCjsExports(const JSHandle<GlobalEnv> &env) const;

View File

@ -25,7 +25,7 @@ public:
// Release Version Snapshot Version
// 3.2 0.0.0.x
// 4.0 4.0.0.x
static constexpr base::FileHeaderBase::VersionType AN_VERSION = {4, 0, 0, 6};
static constexpr base::FileHeaderBase::VersionType AN_VERSION = {4, 0, 0, 7};
static constexpr bool AN_STRICT_MATCH = true;
static constexpr base::FileHeaderBase::VersionType AI_VERSION = {4, 0, 0, 3};
static constexpr bool AI_STRICT_MATCH = true;

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/dfx/native_module_error.h"
namespace panda::ecmascript {
JSHandle<NativeModuleError> NativeModuleError::CreateNativeModuleError(const EcmaVM *vm, const std::string &errorMsg)
{
ObjectFactory *factory = vm->GetFactory();
JSHandle<NativeModuleError> nativeModuleError = factory->NewNativeModuleError();
JSHandle<EcmaString> errorMsgStr = factory->NewFromUtf8(errorMsg);
nativeModuleError->SetArkNativeModuleError(vm->GetJSThread(), JSHandle<JSTaggedValue>(errorMsgStr));
return nativeModuleError;
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMASCRIPT_DFX_NATIVE_MODULE_ERROR_H
#define ECMASCRIPT_DFX_NATIVE_MODULE_ERROR_H
#include "ecmascript/js_object.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory-inl.h"
namespace panda::ecmascript {
class NativeModuleError final : public JSObject {
public:
CAST_CHECK(NativeModuleError, IsNativeModuleError);
static JSHandle<NativeModuleError> CreateNativeModuleError(const EcmaVM *vm, const std::string &errorMsg);
static constexpr size_t ARK_NATIVE_MODULE_ERROR_OFFSET = JSObject::SIZE;
ACCESSORS(ArkNativeModuleError, ARK_NATIVE_MODULE_ERROR_OFFSET, SIZE)
DECL_DUMP()
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ARK_NATIVE_MODULE_ERROR_OFFSET, SIZE)
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_DFX_NATIVE_MODULE_ERROR_H

View File

@ -20,6 +20,7 @@
#include "ecmascript/accessor_data.h"
#include "ecmascript/dfx/hprof/heap_snapshot.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_dictionary-inl.h"
#include "ecmascript/global_env.h"
@ -230,6 +231,8 @@ CString JSHClass::DumpJSType(JSType type)
return "Shared Function";
case JSType::JS_ERROR:
return "Error";
case JSType::NATIVE_MODULE_ERROR:
return "NativeModule Error";
case JSType::JS_EVAL_ERROR:
return "Eval Error";
case JSType::JS_RANGE_ERROR:
@ -1329,6 +1332,9 @@ static void DumpObject(TaggedObject *obj, std::ostream &os)
case JSType::RESOLVEDRECORDBINDING_RECORD:
ResolvedRecordBinding::Cast(obj)->Dump(os);
break;
case JSType::NATIVE_MODULE_ERROR:
NativeModuleError::Cast(obj)->Dump(os);
break;
case JSType::JS_MODULE_NAMESPACE:
ModuleNamespace::Cast(obj)->Dump(os);
break;
@ -3843,6 +3849,13 @@ void ModuleNamespace::Dump(std::ostream &os) const
os << "\n";
}
void NativeModuleError::Dump(std::ostream &os) const
{
os << " - ArkNativeModuleError: ";
GetArkNativeModuleError().Dump(os);
os << "\n";
}
void CjsModule::Dump(std::ostream &os) const
{
os << " - current module path: ";
@ -4467,6 +4480,9 @@ static void DumpObject(TaggedObject *obj, std::vector<Reference> &vec, bool isVm
case JSType::JS_MODULE_NAMESPACE:
ModuleNamespace::Cast(obj)->DumpForSnapshot(vec);
break;
case JSType::NATIVE_MODULE_ERROR:
NativeModuleError::Cast(obj)->DumpForSnapshot(vec);
break;
case JSType::JS_API_PLAIN_ARRAY:
JSAPIPlainArray::Cast(obj)->DumpForSnapshot(vec);
break;
@ -5992,6 +6008,12 @@ void ModuleNamespace::DumpForSnapshot(std::vector<Reference> &vec) const
JSObject::DumpForSnapshot(vec);
}
void NativeModuleError::DumpForSnapshot(std::vector<Reference> &vec) const
{
vec.emplace_back(CString("ArkNativeModuleError"), GetArkNativeModuleError());
JSObject::DumpForSnapshot(vec);
}
void CjsModule::DumpForSnapshot(std::vector<Reference> &vec) const
{
vec.emplace_back(CString("Id"), GetId());

View File

@ -224,7 +224,8 @@
V(JSTaggedValue, CjsRequireFunction, CJS_REQUIRE_FUNCTION_INDEX) \
V(JSTaggedValue, GlobalPatch, GLOBAL_PATCH) \
V(JSTaggedValue, ExportOfScript, DEFAULT_EXPORT_OF_SCRIPT) \
V(JSTaggedValue, JsonObjectHclassCache, JSON_OBJECT_HCLASS_CACHE)
V(JSTaggedValue, JsonObjectHclassCache, JSON_OBJECT_HCLASS_CACHE) \
V(JSTaggedValue, NativeModuleErrorClass, NATIVE_MODULE_ERROR_CLASS)
#define GLOBAL_ENV_SHARED_FIELDS(V) \
V(JSTaggedValue, SObjectFunction, SHARED_OBJECT_FUNCTION_INDEX) \

View File

@ -223,6 +223,7 @@ struct Reference;
JS_CJS_MODULE, /* /////////////////////////////////////////////////////////////////////////////////-PADDING */ \
JS_CJS_EXPORTS, /* ////////////////////////////////////////////////////////////////////////////////-PADDING */ \
JS_CJS_REQUIRE, /* ////////////////////////////////////////////////////////////////////////////////-PADDING */ \
NATIVE_MODULE_ERROR, /* ///////////////////////////////////////////////////////////////////////////-PADDING */ \
JS_GLOBAL_OBJECT, /* JS_OBJECT_LAST////////////////////////////////////////////////////////////////-PADDING */ \
JS_PROXY, /* ECMA_OBJECT_LAST ///////////////////////////////////////////////////////////////////////////// */ \
\
@ -1712,6 +1713,11 @@ public:
return GetObjectType() == JSType::JS_MODULE_NAMESPACE;
}
inline bool IsNativeModuleError() const
{
return GetObjectType() == JSType::NATIVE_MODULE_ERROR;
}
inline bool IsJSSharedObject() const
{
return GetObjectType() == JSType::JS_SHARED_OBJECT;

View File

@ -1558,6 +1558,11 @@ inline bool JSTaggedValue::IsModuleNamespace() const
return IsHeapObject() && GetTaggedObject()->GetClass()->IsModuleNamespace();
}
inline bool JSTaggedValue::IsNativeModuleError() const
{
return IsHeapObject() && GetTaggedObject()->GetClass()->IsNativeModuleError();
}
inline bool JSTaggedValue::IsJSSharedObject() const
{
return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSSharedObject();

View File

@ -678,6 +678,7 @@ public:
bool IsResolvedRecordIndexBinding() const;
bool IsResolvedRecordBinding() const;
bool IsModuleNamespace() const;
bool IsNativeModuleError() const;
bool IsJSSharedObject() const;
bool IsJSSharedFunction() const;
bool IsJSShared() const;

View File

@ -106,6 +106,7 @@
#include "ecmascript/mem/mem.h"
#include "ecmascript/mem/slots.h"
#include "ecmascript/module/js_module_namespace.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/module/js_shared_module.h"
#include "ecmascript/shared_objects/js_shared_array.h"
@ -732,6 +733,9 @@ public:
case JSType::CLASS_LITERAL:
ClassLiteral::Cast(object)->VisitRangeSlot<visitType>(visitor);
break;
case JSType::NATIVE_MODULE_ERROR:
NativeModuleError::Cast(object)->VisitRangeSlot<visitType>(visitor);
break;
default:
LOG_ECMA(FATAL) << "this branch is unreachable, type: " << static_cast<size_t>(type);
UNREACHABLE();

View File

@ -178,6 +178,9 @@ JSHandle<JSTaggedValue> SourceTextModule::ResolveExportObject(JSThread *thread,
// bind with a number
return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, -1));
}
if (exports->IsNativeModuleError()) {
return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, -1));
}
if (exports->IsJSObject()) {
JSHandle<JSTaggedValue> resolution(thread, JSTaggedValue::Hole());
JSObject *exportObject = JSObject::Cast(exports.GetTaggedValue().GetTaggedObject());
@ -400,6 +403,11 @@ bool SourceTextModule::LoadNativeModule(JSThread *thread, JSHandle<SourceTextMod
LOG_FULL(ERROR) << "export objects of native so is undefined, so name is " << moduleName;
return false;
}
if (UNLIKELY(exportObject->IsNativeModuleErrorObject())) {
requiredModule->StoreModuleValue(thread, 0, JSNApiHelper::ToJSHandle(exportObject));
LOG_FULL(ERROR) << "loading fails, NativeModuleErrorObject is returned";
return false;
}
if (UNLIKELY(thread->HasPendingException())) {
thread->ClearException();
LOG_FULL(ERROR) << "LoadNativeModule has exception";

View File

@ -14,6 +14,8 @@
*/
#include "ecmascript/module/module_manager_helper.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/interpreter/slow_runtime_stub.h"
#include "ecmascript/jspandafile/js_pandafile_executor.h"
#include "ecmascript/module/js_module_source_text.h"
@ -28,6 +30,10 @@ JSTaggedValue ModuleManagerHelper::GetModuleValue(JSThread *thread, JSHandle<Sou
if (SourceTextModule::IsNativeModule(moduleType)) {
JSHandle<JSTaggedValue> nativeExports = JSHandle<JSTaggedValue>(thread,
module->GetModuleValue(thread, 0, false));
if (nativeExports->IsNativeModuleError()) {
JSTaggedValue errorInfo = JSHandle<NativeModuleError>::Cast(nativeExports)->GetArkNativeModuleError();
THROW_REFERENCE_ERROR_AND_RETURN(thread, ConvertToString(errorInfo).c_str(), JSTaggedValue::Undefined());
}
if (!nativeExports->IsJSObject()) {
JSHandle<JSTaggedValue> recordName(thread, module->GetEcmaModuleRecordName());
LOG_FULL(WARN) << "Load native module failed, so is " <<
@ -66,6 +72,10 @@ JSTaggedValue ModuleManagerHelper::GetNativeModuleValue(JSThread *thread,
{
JSHandle<JSTaggedValue> nativeExports = JSHandle<JSTaggedValue>(thread,
SourceTextModule::Cast(resolvedModule.GetTaggedObject())->GetModuleValue(thread, 0, false));
if (nativeExports->IsNativeModuleError()) {
JSTaggedValue errorInfo = JSHandle<NativeModuleError>::Cast(nativeExports)->GetArkNativeModuleError();
THROW_REFERENCE_ERROR_AND_RETURN(thread, ConvertToString(errorInfo).c_str(), JSTaggedValue::Undefined());
}
if (!nativeExports->IsJSObject()) {
JSHandle<JSTaggedValue> nativeModuleName(thread, SourceTextModule::GetModuleName(resolvedModule));
LOG_FULL(WARN) << "Load native module failed, so is " <<
@ -89,6 +99,10 @@ JSTaggedValue ModuleManagerHelper::GetNativeModuleValue(JSThread *thread, JSTagg
SourceTextModule *module = SourceTextModule::Cast(resolvedModule.GetTaggedObject());
JSHandle<JSTaggedValue> nativeExports = JSHandle<JSTaggedValue>(thread,
module->GetModuleValue(thread, 0, false));
if (nativeExports->IsNativeModuleError()) {
JSTaggedValue errorInfo = JSHandle<NativeModuleError>::Cast(nativeExports)->GetArkNativeModuleError();
THROW_REFERENCE_ERROR_AND_RETURN(thread, ConvertToString(errorInfo).c_str(), JSTaggedValue::Undefined());
}
if (!nativeExports->IsJSObject()) {
JSHandle<JSTaggedValue> recordName(thread, module->GetEcmaModuleRecordName());
LOG_FULL(WARN) << "Load native module failed, so is " <<

View File

@ -485,6 +485,7 @@ public:
bool IsAsyncGeneratorObject();
bool IsModuleNamespaceObject();
bool IsNativeModuleErrorObject();
bool IsSharedArrayBuffer();
bool IsSendableArrayBuffer();
@ -690,6 +691,7 @@ public:
static Local<ObjectRef> NewSWithProperties(const EcmaVM *vm, SendablePropertiesInfo &info);
static Local<ObjectRef> NewWithNamedProperties(const EcmaVM *vm, size_t propertyCount, const char **keys,
const Local<JSValueRef> *values);
static Local<ObjectRef> CreateNativeModuleError(const EcmaVM *vm, const std::string &errorMsg);
static Local<ObjectRef> CreateAccessorData(const EcmaVM *vm, Local<FunctionRef> getter, Local<FunctionRef> setter);
static Local<ObjectRef> CreateSendableAccessorData(const EcmaVM *vm,
Local<FunctionRef> getter,

View File

@ -39,6 +39,7 @@
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
#include "ecmascript/compiler/aot_file/aot_file_manager.h"
#include "ecmascript/debugger/js_debugger_manager.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/ecma_global_storage.h"
#include "ecmascript/ecma_runtime_call_info.h"
@ -159,6 +160,7 @@ using ecmascript::LinkedHashSet;
using ecmascript::LockHolder;
using ecmascript::MemMapAllocator;
using ecmascript::Method;
using ecmascript::NativeModuleError;
using ecmascript::Mutex;
using ecmascript::ObjectFactory;
using ecmascript::OperationResult;
@ -786,6 +788,11 @@ bool JSValueRef::IsModuleNamespaceObject()
return JSNApiHelper::ToJSTaggedValue(this).IsModuleNamespace();
}
bool JSValueRef::IsNativeModuleErrorObject()
{
return JSNApiHelper::ToJSTaggedValue(this).IsNativeModuleError();
}
bool JSValueRef::IsSharedArrayBuffer()
{
return JSNApiHelper::ToJSTaggedValue(this).IsSharedArrayBuffer();
@ -2041,6 +2048,14 @@ Local<ObjectRef> ObjectRef::NewWithNamedProperties(const EcmaVM *vm, size_t prop
return scope.Escape(JSNApiHelper::ToLocal<ObjectRef>(obj));
}
Local<ObjectRef> ObjectRef::CreateNativeModuleError(const EcmaVM *vm, const std::string &errorMsg)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
JSHandle<NativeModuleError> nativeModuleError = NativeModuleError::CreateNativeModuleError(vm, errorMsg);
return JSNApiHelper::ToLocal<ObjectRef>(JSHandle<JSTaggedValue>::Cast(nativeModuleError));
}
Local<ObjectRef> ObjectRef::CreateAccessorData(const EcmaVM *vm,
Local<FunctionRef> getter, Local<FunctionRef> setter)
{

View File

@ -18,6 +18,7 @@
#include "ecmascript/mem/heap.h"
#include "ecmascript/object_factory-inl.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/accessor_data.h"
#include "ecmascript/base/error_helper.h"
#include "ecmascript/builtins/builtins.h"
@ -3148,6 +3149,18 @@ JSHandle<ModuleNamespace> ObjectFactory::NewModuleNamespace()
return moduleNamespace;
}
JSHandle<NativeModuleError> ObjectFactory::NewNativeModuleError()
{
NewObjectHook();
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetNativeModuleErrorClass());
JSHandle<JSObject> obj = NewJSObject(hclass);
JSHandle<NativeModuleError> nativeModuleError = JSHandle<NativeModuleError>::Cast(obj);
nativeModuleError->SetArkNativeModuleError(thread_, JSTaggedValue::Undefined());
return nativeModuleError;
}
JSHandle<CjsModule> ObjectFactory::NewCjsModule()
{
NewObjectHook();

View File

@ -138,6 +138,7 @@ class JSAPIList;
class JSAPILinkedListIterator;
class JSAPIListIterator;
class ModuleNamespace;
class NativeModuleError;
class ImportEntry;
class LocalExportEntry;
class IndirectExportEntry;
@ -654,6 +655,7 @@ public:
const JSHandle<JSTaggedValue> &value);
// --------------------------------------module--------------------------------------------
JSHandle<ModuleNamespace> NewModuleNamespace();
JSHandle<NativeModuleError> NewNativeModuleError();
JSHandle<ImportEntry> NewImportEntry();
JSHandle<ImportEntry> NewImportEntry(const JSHandle<JSTaggedValue> &moduleRequest,
const JSHandle<JSTaggedValue> &importName,

View File

@ -19,6 +19,7 @@
#include "ecmascript/dfx/hprof/heap_snapshot.h"
#include "ecmascript/dfx/hprof/heap_snapshot_json_serializer.h"
#include "ecmascript/dfx/hprof/string_hashmap.h"
#include "ecmascript/dfx/native_module_error.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_dictionary-inl.h"
#include "ecmascript/global_env.h"
@ -1427,6 +1428,12 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
DUMP_FOR_HANDLE(moduleNamespace);
break;
}
case JSType::NATIVE_MODULE_ERROR: {
CHECK_DUMP_FIELDS(JSObject::SIZE, NativeModuleError::SIZE, 1U);
JSHandle<NativeModuleError> nativeModuleError = factory->NewNativeModuleError();
DUMP_FOR_HANDLE(nativeModuleError);
break;
}
case JSType::JS_CJS_EXPORTS: {
CHECK_DUMP_FIELDS(JSObject::SIZE, CjsExports::SIZE, 1U);
JSHandle<CjsExports> cjsExports = factory->NewCjsExports();