diff --git a/tooling/static/connection/endpoint_base.cpp b/tooling/static/connection/endpoint_base.cpp index 5f06a37afdfd4d1e0981b6dcb18a2befccdd3592..1454419fee8b3885fc8ddb6f75870f5feedc6d64 100644 --- a/tooling/static/connection/endpoint_base.cpp +++ b/tooling/static/connection/endpoint_base.cpp @@ -36,7 +36,7 @@ void EndpointBase::HandleMessage(const std::string &message) return; } - LOG(DEBUG, DEBUGGER) << "Received " << message; + LOG(INFO, DEBUGGER) << "Received " << message; auto sessionId = request.GetValue("sessionId"); auto id = request.GetValue("id"); diff --git a/tooling/static/connection/endpoint_base.h b/tooling/static/connection/endpoint_base.h index 629bd741bdea9842ca5008d9c498908e8c78d752..ffe1ddda3aa53f74c46e0551ccba9af15745a1a4 100644 --- a/tooling/static/connection/endpoint_base.h +++ b/tooling/static/connection/endpoint_base.h @@ -103,7 +103,7 @@ private: JsonObjectBuilder builder; build(builder); auto message = std::move(builder).Build(); - LOG(DEBUG, DEBUGGER) << "Sending " << message; + LOG(INFO, DEBUGGER) << "Sending " << message; SendMessage(message); } diff --git a/tooling/static/inspector.cpp b/tooling/static/inspector.cpp index cc55c7c02d0e053e04650416edec6db8af47d33a..3bb69c21f95f79e0c8643226c26231f4f03e2b9b 100644 --- a/tooling/static/inspector.cpp +++ b/tooling/static/inspector.cpp @@ -88,8 +88,6 @@ void Inspector::CollectModules() void Inspector::Run(const std::string& msg) { - CollectModules(); - inspectorServer_.Run(msg); } @@ -138,6 +136,9 @@ void Inspector::MethodEntry(PtThread thread, Method * /* method */) if (stack.IsCFrame()) { return; } + if (debuggableThread == nullptr) { + return; + } if (debuggableThread->OnMethodEntry()) { HandleError(debugger_.NotifyFramePop(thread, 0)); } @@ -152,7 +153,7 @@ void Inspector::SourceNameInsert(const panda_file::DebugInfoExtractor *extractor } for (const auto &sourceName : sourceNames) { // Get src file name - auto scriptId = inspectorServer_.GetSourceManager().GetScriptId(sourceName); + auto [scriptId, isNew] = inspectorServer_.GetSourceManager().GetScriptId(sourceName); inspectorServer_.CallDebuggerScriptParsed(scriptId, sourceName); } } @@ -165,9 +166,6 @@ void Inspector::LoadModule(std::string_view fileName) [this, fileName](auto &file) { if (file.GetFilename() == fileName) { debugInfoCache_.AddPandaFile(file, true); - const auto *extractor = debugInfoCache_.GetDebugInfo(&file); - SourceNameInsert(extractor); - ResolveBreakpoints(file, extractor); } return true; @@ -767,11 +765,6 @@ void Inspector::DebuggerEnable() dbgThread.Reset(); } breakpointStorage_.Reset(); - Runtime::GetCurrent()->GetClassLinker()->EnumeratePandaFiles([this](auto &file) { - const auto *extractor = debugInfoCache_.GetDebugInfo(&file); - SourceNameInsert(extractor); - return true; - }); } void Inspector::RegisterMethodHandlers() diff --git a/tooling/static/inspector_server.cpp b/tooling/static/inspector_server.cpp index 5130066c12cefc4fb00462150ff98bc23a7aed6b..8639e37cd28baa40bd6c84a14ecdfafb2b6245e3 100644 --- a/tooling/static/inspector_server.cpp +++ b/tooling/static/inspector_server.cpp @@ -1025,7 +1025,11 @@ void InspectorServer::AddCallFrameInfo(JsonArrayBuilder &callFrames, const CallF const std::optional &objThis) { callFrames.Add([&](JsonObjectBuilder &callFrame) { - auto scriptId = sourceManager_.GetScriptId(callFrameInfo.sourceFile); + auto [scriptId, isNew] = sourceManager_.GetScriptId(callFrameInfo.sourceFile); + + if (isNew) { + CallDebuggerScriptParsed(scriptId, callFrameInfo.sourceFile); + } callFrame.AddProperty("callFrameId", std::to_string(callFrameInfo.frameId)); callFrame.AddProperty("functionName", callFrameInfo.methodName.data()); @@ -1047,7 +1051,11 @@ void InspectorServer::AddLocations(UrlBreakpointResponse &response, const std::s size_t lineNumber, [[maybe_unused]] PtThread thread) { for (auto sourceFile : sourceFiles) { - auto scriptId = sourceManager_.GetScriptId(sourceFile); + auto [scriptId, isNew] = sourceManager_.GetScriptId(sourceFile); + + if (isNew) { + CallDebuggerScriptParsed(scriptId, sourceFile); + } response.AddLocation(Location {scriptId, lineNumber}); } } diff --git a/tooling/static/source_manager.cpp b/tooling/static/source_manager.cpp index 2e01a477d261899763661d4f52b599f049310114..670197d5b8991f865bf04ef84406f2e6b66dbc12 100644 --- a/tooling/static/source_manager.cpp +++ b/tooling/static/source_manager.cpp @@ -21,19 +21,20 @@ #include "types/numeric_id.h" namespace ark::tooling::inspector { -ScriptId SourceManager::GetScriptId(std::string_view fileName) +std::pair SourceManager::GetScriptId(std::string_view fileName) { os::memory::LockHolder lock(mutex_); auto p = fileNameToId_.emplace(std::string(fileName), fileNameToId_.size()); ScriptId id(p.first->second); + bool isNewForThread = knownSources_.insert(id).second; if (p.second) { std::string_view name {p.first->first}; idToFileName_.emplace(id, name); } - return id; + return {id, isNewForThread}; } std::string_view SourceManager::GetSourceFileName(ScriptId id) const diff --git a/tooling/static/source_manager.h b/tooling/static/source_manager.h index 8b77611e4a87f177dd083def19d2d621eef8747d..dd7a348aab35c2c63e0204e125ab96e93c3ca4d9 100644 --- a/tooling/static/source_manager.h +++ b/tooling/static/source_manager.h @@ -37,13 +37,14 @@ public: NO_COPY_SEMANTIC(SourceManager); NO_MOVE_SEMANTIC(SourceManager); - ScriptId GetScriptId(std::string_view fileName); + std::pair GetScriptId(std::string_view fileName); [[nodiscard]] std::string_view GetSourceFileName(ScriptId id) const; private: mutable os::memory::Mutex mutex_; std::unordered_map fileNameToId_ GUARDED_BY(mutex_); std::unordered_map idToFileName_ GUARDED_BY(mutex_); + std::unordered_set knownSources_ GUARDED_BY(mutex_); }; } // namespace ark::tooling::inspector diff --git a/tooling/static/tests/source_manager.cpp b/tooling/static/tests/source_manager.cpp index 0230cfa5e00b55becdcd1ddcd865edd0b59bdc69..47aae4b510b27768c0a0af687b76d7782879ed5d 100644 --- a/tooling/static/tests/source_manager.cpp +++ b/tooling/static/tests/source_manager.cpp @@ -63,29 +63,27 @@ TEST_F(SourceManagerTest, General) } auto test_id0 = sm_.GetScriptId("test.pa"); - ASSERT_EQ(test_id0, ScriptId(0)); + ASSERT_EQ(test_id0.first, ScriptId(0)); + ASSERT_EQ(test_id0.second, true); - ASSERT_EQ(sm_.GetSourceFileName(test_id0), "test.pa"); + ASSERT_EQ(sm_.GetSourceFileName(test_id0.first), "test.pa"); ASSERT_EQ(sm_.GetSourceFileName(ScriptId(1)), ""); test_id0 = sm_.GetScriptId("test.pa"); - ASSERT_EQ(test_id0, ScriptId(0)); + ASSERT_EQ(test_id0.first, ScriptId(0)); + ASSERT_EQ(test_id0.second, false); auto test_id1 = sm_.GetScriptId("test1.pa"); - ASSERT_EQ(test_id1, ScriptId(1)); + ASSERT_EQ(test_id1.first, ScriptId(1)); + ASSERT_EQ(test_id1.second, true); auto test_id2 = sm_.GetScriptId("test2.pa"); auto test_id3 = sm_.GetScriptId("test3.pa"); - ASSERT_EQ(sm_.GetSourceFileName(test_id2), "test2.pa"); - ASSERT_EQ(sm_.GetSourceFileName(test_id3), "test3.pa"); + ASSERT_EQ(sm_.GetSourceFileName(test_id2.first), "test2.pa"); + ASSERT_EQ(sm_.GetSourceFileName(test_id3.first), "test3.pa"); ASSERT_EQ(sm_.GetSourceFileName(ScriptId(5U)), ""); - ASSERT_EQ(sm_.GetSourceFileName(test_id2), "test2.pa"); - - test_id0 = sm_.GetScriptId("test.pa"); - ASSERT_EQ(test_id0, ScriptId(0)); - sync_flag1 = false; mthread1.join();