From 673414497faca0ad5ce784d7abcc91d4177623c0 Mon Sep 17 00:00:00 2001 From: yang-19970325 Date: Fri, 1 Dec 2023 20:41:03 +0800 Subject: [PATCH] Fix thread safe problem Signed-off-by: yang-19970325 Change-Id: I1157883387944e42f78167aada66e4582bf4d757 --- tooling/agent/debugger_impl.cpp | 4 ++-- tooling/agent/debugger_impl.h | 4 ++-- tooling/backend/js_pt_hooks.cpp | 3 +-- tooling/test/debugger_impl_test.cpp | 4 ++-- tooling/test/testcases/js_dropframe_test.h | 2 +- tooling/test/testcases/js_range_error_test.h | 2 +- tooling/test/testcases/js_step_into_test.h | 2 +- tooling/test/testcases/js_step_out_test.h | 2 +- tooling/test/testcases/js_step_over_test.h | 2 +- tooling/test/testcases/js_syntax_exception_test.h | 2 +- tooling/test/testcases/js_throw_exception_test.h | 2 +- tooling/test/testcases/js_variable_first_test.h | 2 +- tooling/test/testcases/js_variable_second_test.h | 2 +- 13 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index f71545c3..d54cf772 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -67,7 +67,7 @@ DebuggerImpl::~DebuggerImpl() DebuggerApi::DestroyJSDebugger(jsDebugger_); } -bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &fileName, std::string_view entryPoint) +bool DebuggerImpl::NotifyScriptParsed(const std::string &fileName, std::string_view entryPoint) { #if !defined(PANDA_TARGET_WINDOWS) && !defined(PANDA_TARGET_MACOS) \ && !defined(PANDA_TARGET_ANDROID) && !defined(PANDA_TARGET_IOS) \ @@ -109,7 +109,7 @@ bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &file } // Notify script parsed event - std::unique_ptr script = std::make_unique(scriptId, fileName, url, source); + std::unique_ptr script = std::make_unique(scriptId_++, fileName, url, source); frontend_.ScriptParsed(vm_, *script); diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index aece3b5a..5b9e9881 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -38,8 +38,7 @@ public: ~DebuggerImpl(); // event - bool NotifyScriptParsed(ScriptId scriptId, const std::string &fileName, - std::string_view entryPoint = "func_main_0"); + bool NotifyScriptParsed(const std::string &fileName, std::string_view entryPoint = "func_main_0"); bool NotifySingleStep(const JSPtLocation &location); void NotifyPaused(std::optional location, PauseReason reason); bool NotifyNativeOut(); @@ -263,6 +262,7 @@ private: bool nativeOutPause_ {false}; bool checkNeedPause_ {false}; + ScriptId scriptId_ {0}; std::vector nativeRanges_ {}; std::unordered_map scopeObjects_ {}; std::vector> callFrameHandlers_; diff --git a/tooling/backend/js_pt_hooks.cpp b/tooling/backend/js_pt_hooks.cpp index 352e05a8..927c6c88 100644 --- a/tooling/backend/js_pt_hooks.cpp +++ b/tooling/backend/js_pt_hooks.cpp @@ -85,8 +85,7 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entr [[maybe_unused]] LocalScope scope(debugger_->vm_); - static uint32_t scriptId = 0; - if (debugger_->NotifyScriptParsed(scriptId++, pandaFileName.data(), entryPoint)) { + if (debugger_->NotifyScriptParsed(pandaFileName.data(), entryPoint)) { firstTime_ = true; } } diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 72ad589e..606db119 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -62,11 +62,11 @@ HWTEST_F_L0(DebuggerImplTest, NotifyScriptParsed__001) // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH std::string strFilename = "filename"; - EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(0, strFilename, "")); + EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(strFilename, "")); // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH strFilename = "/filename"; - EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(0, strFilename, "")); + EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(strFilename, "")); if (protocolChannel) { delete protocolChannel; diff --git a/tooling/test/testcases/js_dropframe_test.h b/tooling/test/testcases/js_dropframe_test.h index 429495aa..e5ab1197 100644 --- a/tooling/test/testcases/js_dropframe_test.h +++ b/tooling/test/testcases/js_dropframe_test.h @@ -58,7 +58,7 @@ public: InitBreakpointOpQueue(); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + ASSERT_TRUE(debugger_->NotifyScriptParsed(pandaFile_)); auto condFuncRef = FunctionRef::Undefined(vm_); for (auto &iter : pointerLocations_) { auto ret = debugInterface_->SetBreakpoint(iter, condFuncRef); diff --git a/tooling/test/testcases/js_range_error_test.h b/tooling/test/testcases/js_range_error_test.h index 40fe953e..f246040a 100644 --- a/tooling/test/testcases/js_range_error_test.h +++ b/tooling/test/testcases/js_range_error_test.h @@ -61,7 +61,7 @@ public: ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + ASSERT_TRUE(debugger_->NotifyScriptParsed(pandaFile_)); auto condFuncRef = FunctionRef::Undefined(vm_); auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); ASSERT_TRUE(ret); diff --git a/tooling/test/testcases/js_step_into_test.h b/tooling/test/testcases/js_step_into_test.h index bc6e4253..894f4d55 100644 --- a/tooling/test/testcases/js_step_into_test.h +++ b/tooling/test/testcases/js_step_into_test.h @@ -41,7 +41,7 @@ public: SetJSPtLocation(stepInto[0], STEP_SIZE, stepLocations_); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); - debugger_->NotifyScriptParsed(0, moduleName.data()); + debugger_->NotifyScriptParsed(moduleName.data()); auto condFuncRef = FunctionRef::Undefined(vm_); for (auto &iter : pointerLocations_) { auto ret = debugInterface_->SetBreakpoint(iter, condFuncRef); diff --git a/tooling/test/testcases/js_step_out_test.h b/tooling/test/testcases/js_step_out_test.h index cf96640e..990af2b4 100644 --- a/tooling/test/testcases/js_step_out_test.h +++ b/tooling/test/testcases/js_step_out_test.h @@ -39,7 +39,7 @@ public: SetJSPtLocation(stepOut[0], STEP_SIZE, stepLocations_); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); - debugger_->NotifyScriptParsed(0, moduleName.data()); + debugger_->NotifyScriptParsed(moduleName.data()); auto condFuncRef = FunctionRef::Undefined(vm_); for (auto &iter : pointerLocations_) { auto ret = debugInterface_->SetBreakpoint(iter, condFuncRef); diff --git a/tooling/test/testcases/js_step_over_test.h b/tooling/test/testcases/js_step_over_test.h index 9a4f8f58..4bc6c0a8 100644 --- a/tooling/test/testcases/js_step_over_test.h +++ b/tooling/test/testcases/js_step_over_test.h @@ -39,7 +39,7 @@ public: SetJSPtLocation(stepOver[0], STEP_SIZE, stepLocations_); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); - debugger_->NotifyScriptParsed(0, moduleName.data()); + debugger_->NotifyScriptParsed(moduleName.data()); auto condFuncRef = FunctionRef::Undefined(vm_); for (auto &iter : pointerLocations_) { auto ret = debugInterface_->SetBreakpoint(iter, condFuncRef); diff --git a/tooling/test/testcases/js_syntax_exception_test.h b/tooling/test/testcases/js_syntax_exception_test.h index aa1c7334..5f2e4666 100644 --- a/tooling/test/testcases/js_syntax_exception_test.h +++ b/tooling/test/testcases/js_syntax_exception_test.h @@ -61,7 +61,7 @@ public: ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + ASSERT_TRUE(debugger_->NotifyScriptParsed(pandaFile_)); auto condFuncRef = FunctionRef::Undefined(vm_); auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); ASSERT_TRUE(ret); diff --git a/tooling/test/testcases/js_throw_exception_test.h b/tooling/test/testcases/js_throw_exception_test.h index cdddcc3b..a54b84f1 100644 --- a/tooling/test/testcases/js_throw_exception_test.h +++ b/tooling/test/testcases/js_throw_exception_test.h @@ -64,7 +64,7 @@ public: std::cout<<"vmStart2"<NotifyScriptParsed(0, pandaFile_)); + ASSERT_TRUE(debugger_->NotifyScriptParsed(pandaFile_)); auto condFuncRef = FunctionRef::Undefined(vm_); auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); ASSERT_TRUE(ret); diff --git a/tooling/test/testcases/js_variable_first_test.h b/tooling/test/testcases/js_variable_first_test.h index 7e5f0e3d..ec675b32 100644 --- a/tooling/test/testcases/js_variable_first_test.h +++ b/tooling/test/testcases/js_variable_first_test.h @@ -42,7 +42,7 @@ public: ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile); - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile)); + ASSERT_TRUE(debugger_->NotifyScriptParsed(pandaFile)); auto condFuncRef = FunctionRef::Undefined(vm_); auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); ASSERT_TRUE(ret); diff --git a/tooling/test/testcases/js_variable_second_test.h b/tooling/test/testcases/js_variable_second_test.h index d5835b11..3eddae17 100644 --- a/tooling/test/testcases/js_variable_second_test.h +++ b/tooling/test/testcases/js_variable_second_test.h @@ -42,7 +42,7 @@ public: ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, panfaFile); - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, panfaFile)); + ASSERT_TRUE(debugger_->NotifyScriptParsed(panfaFile)); auto condFuncRef = FunctionRef::Undefined(vm_); auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); ASSERT_TRUE(ret); -- Gitee