From 528bb41a4f56726c182a788330e97b9fa2ec5ad7 Mon Sep 17 00:00:00 2001 From: huangtianzhi Date: Tue, 20 Feb 2024 10:45:12 +0800 Subject: [PATCH] Debugger support custom defined class displaying className Retriving its classname and resolving it in RemoteObject's description Issue: #I8OX0X Test: Build & Boost & Debug Signed-off-by: huangtianzhi --- tooling/base/pt_types.cpp | 12 ++++- tooling/base/pt_types.h | 1 + tooling/test/testcases/js/variable_second.js | 43 ++++++++++++++++++ .../test/testcases/js_module_variable_test.h | 16 +++---- .../test/testcases/js_variable_first_test.h | 32 +++++++------- .../test/testcases/js_variable_second_test.h | 44 ++++++++++++------- 6 files changed, 107 insertions(+), 41 deletions(-) diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index a4700db3..d763e84d 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -251,6 +251,16 @@ void RemoteObject::AppendingHashToDescription(const EcmaVM *ecmaVM, Local tagged) +{ + std::string description = RemoteObject::ObjectDescription; + if (!tagged->IsObject()) { + return description; + } + DebuggerApi::GetObjectClassName(ecmaVM, tagged, description); + return description.empty() ? RemoteObject::ObjectDescription : description; +} + PrimitiveRemoteObject::PrimitiveRemoteObject(const EcmaVM *ecmaVm, Local tagged) { if (tagged->IsNull()) { @@ -494,7 +504,7 @@ std::string ObjectRemoteObject::DescriptionForObject(const EcmaVM *ecmaVm, Local if (tagged->IsNativePointer()) { return DescriptionForNativePointer(Local(tagged)); } - return RemoteObject::ObjectDescription; + return ResolveClassNameToDescription(ecmaVm, tagged); } std::string ObjectRemoteObject::DescriptionForNativePointer(const Local &tagged) diff --git a/tooling/base/pt_types.h b/tooling/base/pt_types.h index 8fb8b40e..e6487443 100644 --- a/tooling/base/pt_types.h +++ b/tooling/base/pt_types.h @@ -256,6 +256,7 @@ public: std::unique_ptr ToJson() const override; static void AppendingHashToDescription(const EcmaVM *ecmaVM, Local tagged, std::string &description); + static std::string ResolveClassNameToDescription(const EcmaVM *ecmaVM, Local tagged); /* * @see {#ObjectType} */ diff --git a/tooling/test/testcases/js/variable_second.js b/tooling/test/testcases/js/variable_second.js index ab933922..2e20d037 100644 --- a/tooling/test/testcases/js/variable_second.js +++ b/tooling/test/testcases/js/variable_second.js @@ -123,6 +123,49 @@ var o = { weakSet2.add(p2); weakSet2.add(weakSet1); + class Parent { + name; + age; + constructor(name, age) { + this.name = name; + this.age = age; + } + print() { + print(this.name + " " + this.age); + } + } + + class Child extends Parent { + idNumber; + constructor(name, age, idNumber) { + super(name, age); + this.idNumber = idNumber; + } + print() { + print(this.name + " " + this.age + " " + this.idNumber); + } + } + let parent = new Parent("parent", 50); + let child = new Child("child", 15, "1234"); + parent.print(); + child.print(); + + function customClass(a, b, child) { + this._a = a; + this._b = b; + this.child = child; + this.print = function() { + print("customClass print is called"); + } + } + let class1 = new customClass(1, 2, child); + class1.print(); + + let class2 = { + name: "class2" + } + print(class2.name); + var nop = undefined; } } diff --git a/tooling/test/testcases/js_module_variable_test.h b/tooling/test/testcases/js_module_variable_test.h index 2ee3bee1..4df6cdf5 100644 --- a/tooling/test/testcases/js_module_variable_test.h +++ b/tooling/test/testcases/js_module_variable_test.h @@ -501,27 +501,27 @@ private: "\"value\":{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":\"Uint8Array(24)\"," "\"description\":\"Uint8Array(24)\",\"objectId\":\"102\"},\"writable\":true,\"configurable\":true," "\"enumerable\":false,\"isOwn\":true},{\"name\":\"[[Uint8ClampedArray]]\",\"value\":{\"type\":\"object\"," - "\"className\":\"Object\",\"unserializableValue\":\"Object\",\"description\":\"Object\",\"objectId\":\"103\"}," + "\"className\":\"Object\",\"unserializableValue\":\"Uint8ClampedArray\",\"description\":\"Uint8ClampedArray\",\"objectId\":\"103\"}," "\"writable\":true,\"configurable\":true,\"enumerable\":false,\"isOwn\":true},{\"name\":\"[[Int16Array]]\"," "\"value\":{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":\"Int16Array(12)\"," "\"description\":\"Int16Array(12)\",\"objectId\":\"104\"},\"writable\":true,\"configurable\":true," "\"enumerable\":false,\"isOwn\":true},{\"name\":\"[[Uint16Array]]\",\"value\":{\"type\":\"object\"," - "\"className\":\"Object\",\"unserializableValue\":\"Object\",\"description\":\"Object\",\"objectId\":" + "\"className\":\"Object\",\"unserializableValue\":\"Uint16Array\",\"description\":\"Uint16Array\",\"objectId\":" "\"105\"},\"writable\":true,\"configurable\":true,\"enumerable\":false,\"isOwn\":true},{\"name\":" "\"[[Int32Array]]\",\"value\":{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":" "\"Int32Array(6)\",\"description\":\"Int32Array(6)\",\"objectId\":\"106\"},\"writable\":true,\"configurable\":" "true,\"enumerable\":false,\"isOwn\":true},{\"name\":\"[[Uint32Array]]\",\"value\":{\"type\":\"object\"," - "\"className\":\"Object\",\"unserializableValue\":\"Object\",\"description\":\"Object\",\"objectId\":\"107\"}," + "\"className\":\"Object\",\"unserializableValue\":\"Uint32Array\",\"description\":\"Uint32Array\",\"objectId\":\"107\"}," "\"writable\":true,\"configurable\":true,\"enumerable\":false,\"isOwn\":true},{\"name\":\"[[Float32Array]]\"," - "\"value\":{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":\"Object\",\"description\":" - "\"Object\",\"objectId\":\"108\"},\"writable\":true,\"configurable\":true,\"enumerable\":false,\"isOwn\":true}," + "\"value\":{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":\"Float32Array\",\"description\":" + "\"Float32Array\",\"objectId\":\"108\"},\"writable\":true,\"configurable\":true,\"enumerable\":false,\"isOwn\":true}," "{\"name\":\"[[Float64Array]]\",\"value\":{\"type\":\"object\",\"className\":\"Object\"," - "\"unserializableValue\":\"Object\",\"description\":\"Object\",\"objectId\":\"109\"},\"writable\":true," + "\"unserializableValue\":\"Float64Array\",\"description\":\"Float64Array\",\"objectId\":\"109\"},\"writable\":true," "\"configurable\":true,\"enumerable\":false,\"isOwn\":true},{\"name\":\"[[BigInt64Array]]\",\"value\":" - "{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":\"Object\",\"description\":\"Object\"," + "{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":\"BigInt64Array\",\"description\":\"BigInt64Array\"," "\"objectId\":\"110\"},\"writable\":true,\"configurable\":true,\"enumerable\":false,\"isOwn\":true},{\"name\":" "\"[[BigUint64Array]]\",\"value\":{\"type\":\"object\",\"className\":\"Object\",\"unserializableValue\":" - "\"Object\",\"description\":\"Object\",\"objectId\":\"111\"},\"writable\":true,\"configurable\":true," + "\"BigUint64Array\",\"description\":\"BigUint64Array\",\"objectId\":\"111\"},\"writable\":true,\"configurable\":true," "\"enumerable\":false,\"isOwn\":true}]}}", "{\"id\":13,\"result\":{\"result\":[{\"name\":\"[[PrimitiveValue]]\",\"value\":{\"type\":\"boolean\"," diff --git a/tooling/test/testcases/js_variable_first_test.h b/tooling/test/testcases/js_variable_first_test.h index 81bdad86..2f7f52b4 100644 --- a/tooling/test/testcases/js_variable_first_test.h +++ b/tooling/test/testcases/js_variable_first_test.h @@ -224,15 +224,15 @@ private: "[[Int8Array]]", "object", "Object", "Int8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "[[Uint8Array]]", "object", "Object", "Uint8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", - "[[Uint8ClampedArray]]", "object", "Object", "Object", + "[[Uint8ClampedArray]]", "object", "Object", "Uint8ClampedArray", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "[[Int16Array]]", "object", "Object", "Int16Array(12)", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Uint16Array]]", "object", - "Object", "Object", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Int32Array]]", "object", "Object", - "Int32Array(6)", "0,0,0,0,0,0", "[[Uint32Array]]", "object", "Object", "Object", - "0,0,0,0,0,0", "[[Float32Array]]", "object", "Object", "Object", "0,0,0,0,0,0", - "[[Float64Array]]", "object", "Object", "Object", "0,0,0", "[[BigInt64Array]]", - "object", "Object", "Object", "0,0,0", "[[BigUint64Array]]", "object", "Object", - "Object", "0,0,0" } }, + "Object", "Uint16Array", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Int32Array]]", "object", "Object", + "Int32Array(6)", "0,0,0,0,0,0", "[[Uint32Array]]", "object", "Object", "Uint32Array", + "0,0,0,0,0,0", "[[Float32Array]]", "object", "Object", "Float32Array", "0,0,0,0,0,0", + "[[Float64Array]]", "object", "Object", "Float64Array", "0,0,0", "[[BigInt64Array]]", + "object", "Object", "BigInt64Array", "0,0,0", "[[BigUint64Array]]", "object", "Object", + "BigUint64Array", "0,0,0" } }, { "function0", { "function", "Function", "function function0( { [js code] }", "Cannot get source code of funtion" } }, { "generator0", { "function", "Generator", "function* generator0( { [js code] }", @@ -625,7 +625,7 @@ private: { "object9", { "object", "Object", "Object", "[object Object]", "none" } }, { "object10", { "object", "array", "Array", "Array(2)", "Apple,Banana", "0", "string", "Apple", "Apple", "1", "string", "Banana", "Banana", "length", "number", "2", "2" } }, - { "object11", { "object", "Object", "Object", "8998192055486250009", "none" } }, + { "object11", { "object", "Object", "BigInt", "8998192055486250009", "none" } }, { "object12", { "function", "Generator", "function* generator0( { [js code] }", "Cannot get source code of funtion" } }, { "object13", { "object", "regexp", "RegExp", "/^\\d+\\.\\d+$/i", "/^\\d+\\.\\d+$/i", "global", "boolean", @@ -634,20 +634,20 @@ private: "unicode", "boolean", "false", "false", "sticky", "boolean", "false", "false", "flags", "string", "i", "i", "source", "string", "^\\d+\\.\\d+$", "^\\d+\\.\\d+$", "lastIndex", "number", "0", "0" } }, - { "object14", { "object", "Object", "Object", "999", "none" } }, + { "object14", { "object", "Object", "BigInt", "999", "none" } }, { "object15", { "object", "arraybuffer", "Arraybuffer", "ArrayBuffer(24)", "[object ArrayBuffer]", "[[Int8Array]]", "object", "Object", "Int8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "[[Uint8Array]]", "object", "Object", "Uint8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", - "[[Uint8ClampedArray]]", "object", "Object", "Object", + "[[Uint8ClampedArray]]", "object", "Object", "Uint8ClampedArray", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "[[Int16Array]]", "object", "Object", "Int16Array(12)", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Uint16Array]]", "object", "Object", - "Object", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Int32Array]]", "object", "Object", - "Int32Array(6)", "0,0,0,0,0,0", "[[Uint32Array]]", "object", "Object", "Object", - "0,0,0,0,0,0", "[[Float32Array]]", "object", "Object", "Object", "0,0,0,0,0,0", - "[[Float64Array]]", "object", "Object", "Object", "0,0,0", "[[BigInt64Array]]", "object", - "Object", "Object", "0,0,0", "[[BigUint64Array]]", - "object", "Object", "Object", "0,0,0" } }, + "Uint16Array", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Int32Array]]", "object", "Object", + "Int32Array(6)", "0,0,0,0,0,0", "[[Uint32Array]]", "object", "Object", "Uint32Array", + "0,0,0,0,0,0", "[[Float32Array]]", "object", "Object", "Float32Array", "0,0,0,0,0,0", + "[[Float64Array]]", "object", "Object", "Float64Array", "0,0,0", "[[BigInt64Array]]", "object", + "Object", "BigInt64Array", "0,0,0", "[[BigUint64Array]]", + "object", "Object", "BigUint64Array", "0,0,0" } }, { "object16", { "object", "Object", "Uint8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "0", "number", "0", "0", "1", "number", "0", "0", "2", "number", "0", "0", "3", "number", "0", "0", "4", "number", "0", "0", "5", "number", "0", "0", "6", "number", "0", "0", "7", diff --git a/tooling/test/testcases/js_variable_second_test.h b/tooling/test/testcases/js_variable_second_test.h index d5835b11..89142dda 100644 --- a/tooling/test/testcases/js_variable_second_test.h +++ b/tooling/test/testcases/js_variable_second_test.h @@ -37,8 +37,9 @@ public: std::string sourceFile = DEBUGGER_JS_DIR "variable_second.js"; static_cast(channel_)->Initial(vm_, runtime_); runtime_->Enable(); - // 125: breakpointer line - location_ = TestUtil::GetLocation(sourceFile.c_str(), 125, 0, panfaFile.c_str()); + // 166: breakpointer line + int32_t line = 166; + location_ = TestUtil::GetLocation(sourceFile.c_str(), line, 0, panfaFile.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, panfaFile); @@ -223,15 +224,15 @@ private: "[[Int8Array]]", "object", "Object", "Int8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "[[Uint8Array]]", "object", "Object", "Uint8Array(24)", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", - "[[Uint8ClampedArray]]", "object", "Object", "Object", + "[[Uint8ClampedArray]]", "object", "Object", "Uint8ClampedArray", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "[[Int16Array]]", "object", "Object", "Int16Array(12)", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Uint16Array]]", "object", - "Object", "Object", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Int32Array]]", "object", "Object", - "Int32Array(6)", "0,0,0,0,0,0", "[[Uint32Array]]", "object", "Object", "Object", - "0,0,0,0,0,0", "[[Float32Array]]", "object", "Object", "Object", "0,0,0,0,0,0", - "[[Float64Array]]", "object", "Object", "Object", "0,0,0", "[[BigInt64Array]]", - "object", "Object", "Object", "0,0,0", "[[BigUint64Array]]", "object", "Object", - "Object", "0,0,0" } }, + "Object", "Uint16Array", "0,0,0,0,0,0,0,0,0,0,0,0", "[[Int32Array]]", "object", "Object", + "Int32Array(6)", "0,0,0,0,0,0", "[[Uint32Array]]", "object", "Object", "Uint32Array", + "0,0,0,0,0,0", "[[Float32Array]]", "object", "Object", "Float32Array", "0,0,0,0,0,0", + "[[Float64Array]]", "object", "Object", "Float64Array", "0,0,0", "[[BigInt64Array]]", + "object", "Object", "BigInt64Array", "0,0,0", "[[BigUint64Array]]", "object", "Object", + "BigUint64Array", "0,0,0" } }, { "function0", { "function", "Function", "function function0( { [js code] }", "Cannot get source code of funtion" } }, { "generator0", { "function", "Generator", "function* generator0( { [js code] }", @@ -324,15 +325,15 @@ private: "number", "3", "3" } }, { "array21", { "string", "banana", "banana" } }, { "typedarray1", { "object", "Object", "Int8Array(0)", "", "none" } }, - { "typedarray2", { "object", "Object", "Object", "", "none" } }, + { "typedarray2", { "object", "Object", "Uint8ClampedArray", "", "none" } }, { "typedarray3", { "object", "Object", "Int16Array(0)", "", "none" } }, - { "typedarray4", { "object", "Object", "Object", "", "none" } }, + { "typedarray4", { "object", "Object", "Uint16Array", "", "none" } }, { "typedarray5", { "object", "Object", "Int32Array(0)", "", "none" } }, - { "typedarray6", { "object", "Object", "Object", "", "none" } }, - { "typedarray7", { "object", "Object", "Object", "", "none" } }, - { "typedarray8", { "object", "Object", "Object", "", "none" } }, - { "typedarray9", { "object", "Object", "Object", "", "none" } }, - { "typedarray10", { "object", "Object", "Object", "", "none" } }, + { "typedarray6", { "object", "Object", "Uint32Array", "", "none" } }, + { "typedarray7", { "object", "Object", "Float32Array", "", "none" } }, + { "typedarray8", { "object", "Object", "Float64Array", "", "none" } }, + { "typedarray9", { "object", "Object", "BigInt64Array", "", "none" } }, + { "typedarray10", { "object", "Object", "BigUint64Array", "", "none" } }, { "typedarray11", { "object", "Object", "Uint8Array(1)", "0", "0", "number", "0", "0" } }, { "iterator1", { "function", "Function", "function values( { [native code] }", "function values() { [native code] }" } }, @@ -394,6 +395,17 @@ private: { "weakSet2", { "object", "weakset", "Weakset", "WeakSet(2) {Object, Object}", "[object WeakSet]", "[[Entries]]", "object", "array", "Array", "Array(2)", "[object Object],[object Object]" } }, + { "Parent", { "function", "Function", "function Parent( { [js code] }", "Cannot get source code of funtion" } }, + { "class1", { "object", "Object", "customClass", "[object Object]", "_a", "number", "1", "1", + "_b", "number", "2", "2", "child", "object", "Object", "Child", "[object Object]", "print", + "function", "Function", "function ( { [js code] }", "Cannot get source code of funtion" } }, + { "parent", { "object", "Object", "Parent", "[object Object]", "name", "string", "parent", "parent", + "age", "number", "50", "50" } }, + { "customClass", { "function", "Function", "function customClass( { [js code] }", "Cannot get source code of funtion" } }, + { "child", { "object", "Object", "Child", "[object Object]", "name", "string", "child", "child", + "age", "number", "15", "15", "idNumber", "string", "1234", "1234" } }, + { "class2", { "object", "Object", "Object", "[object Object]", "name", "string", "class2", "class2" } }, + { "Child", { "function", "Function", "function Child( { [js code] }", "Cannot get source code of funtion" } }, }; int32_t index_ {0}; -- Gitee