/** * Copyright (c) 2022-2025 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 PANDA_TOOLING_INSPECTOR_INSPECTOR_SERVER_H #define PANDA_TOOLING_INSPECTOR_INSPECTOR_SERVER_H #include #include #include #include #include #include #include #include "include/console_call_type.h" #include "include/tooling/pt_thread.h" #include "common.h" #include "session_manager.h" #include "source_manager.h" #include "debugger/thread_state.h" #include "types/evaluation_result.h" #include "types/numeric_id.h" #include "types/pause_on_exceptions_state.h" #include "types/profile_result.h" #include "types/property_descriptor.h" #include "types/remote_object.h" #include "types/scope.h" namespace ark::tooling::inspector { class UrlBreakpointResponse; class Server; // NOLINT(fuchsia-virtual-inheritance) class UrlBreakpointRequest; class InspectorServer final { public: using SetBreakpointHandler = std::optional(PtThread, SourceFileFilter &&, size_t, std::set &, const std::string *); using FrameInfoHandler = std::function &, const std::optional &)>; public: explicit InspectorServer(Server &server); ~InspectorServer() = default; NO_COPY_SEMANTIC(InspectorServer); NO_MOVE_SEMANTIC(InspectorServer); void Kill(); void Run(const std::string& msg); void OnValidate(std::function &&handler); void OnOpen(std::function &&handler); void OnFail(std::function &&handler); void CallDebuggerPaused(PtThread thread, const std::vector &hitBreakpoints, const std::optional &exception, PauseReason pauseReason, const std::function &enumerateFrames); void CallDebuggerResumed(PtThread thread); void CallDebuggerScriptParsed(ScriptId scriptId, std::string_view sourceFile); void CallRuntimeConsoleApiCalled(PtThread thread, ConsoleCallType type, uint64_t timestamp, const std::vector &arguments); void CallRuntimeExecutionContextCreated(PtThread thread); void CallRuntimeExecutionContextsCleared(); void CallTargetAttachedToTarget(PtThread thread); void CallTargetDetachedFromTarget(PtThread thread); void OnCallDebuggerContinueToLocation(std::function &&handler); void OnCallDebuggerEnable(std::function &&handler); void OnCallDebuggerGetPossibleBreakpoints( std::function(std::string_view, size_t, size_t, bool)> &&handler); void OnCallDebuggerGetScriptSource(std::function &&handler); void OnCallDebuggerPause(std::function &&handler); void OnCallDebuggerRemoveBreakpoint(std::function &&handler); void OnCallDebuggerRemoveBreakpointsByUrl(std::function &&handler); void OnCallDebuggerRestartFrame(std::function &&handler); void OnCallDebuggerResume(std::function &&handler); void OnCallDebuggerSetAsyncCallStackDepth(std::function &&handler); void OnCallDebuggerSetBlackboxPatterns(std::function &&handler); void OnCallDebuggerSmartStepInto(std::function &&handler); void OnCallDebuggerSetBreakpoint(std::function &&handler); void OnCallDebuggerSetBreakpointByUrl(std::function &&handler); void OnCallDebuggerGetPossibleAndSetBreakpointByUrl(std::function &&handler); void OnCallDebuggerSetBreakpointsActive(std::function &&handler); void OnCallDebuggerSetSkipAllPauses(std::function &&handler); void OnCallDebuggerSetPauseOnExceptions(std::function &&handler); void OnCallDebuggerStepInto(std::function &&handler); void OnCallDebuggerStepOut(std::function &&handler); void OnCallDebuggerStepOver(std::function &&handler); void OnCallDebuggerEvaluateOnCallFrame( std::function(PtThread, const std::string &, size_t)> &&handler); void OnCallDebuggerClientDisconnect(std::function &&handler); void OnCallDebuggerDisable(std::function &&handler); void OnCallDebuggerDropFrame(std::function &&handler); void OnCallDebuggerSetNativeRange(std::function &&handler); void OnCallDebuggerReplyNativeCalling(std::function &&handler); void OnCallDebuggerCallFunctionOn( std::function(PtThread, const std::string &, size_t)> &&handler); void OnCallDebuggerSetMixedDebugEnabled(std::function &&handler); void OnCallRuntimeEnable(std::function &&handler); void OnCallRuntimeGetProperties( std::function(PtThread, RemoteObjectId, bool)> &&handler); void OnCallRuntimeRunIfWaitingForDebugger(std::function &&handler); void OnCallRuntimeEvaluate( std::function(PtThread, const std::string &)> &&handler); void OnCallProfilerEnable(); void OnCallProfilerDisable(); void OnCallProfilerSetSamplingInterval(std::function &&handler); void OnCallProfilerStart(std::function()> &&handler); void OnCallProfilerStop(std::function()> &&handler); SourceManager &GetSourceManager() { return sourceManager_; } private: struct CallFrameInfo { FrameId frameId; std::string_view sourceFile; std::string_view methodName; size_t lineNumber; }; private: void SendTargetAttachedToTarget(const std::string &sessionId); void EnumerateCallFrames(JsonArrayBuilder &callFrames, PtThread thread, const std::function &enumerateFrames); void AddCallFrameInfo(JsonArrayBuilder &callFrames, const CallFrameInfo &callFrameInfo, const std::vector &scopeChain, PtThread thread, const std::optional &objThis); Expected, std::string> SetBreakpointByUrl( const std::string &sessionId, const UrlBreakpointRequest &breakpointRequest, const std::function &handler); void AddLocations(UrlBreakpointResponse &response, const std::set &sourceFiles, size_t lineNumber, PtThread thread); static void AddHitBreakpoints(JsonArrayBuilder &hitBreakpointsBuilder, const std::vector &hitBreakpoints); static std::string GetExecutionContextUniqueId(const PtThread &thread); Server &server_; SessionManager sessionManager_; SourceManager sourceManager_; }; } // namespace ark::tooling::inspector #endif // PANDA_TOOLING_INSPECTOR_INSPECTOR_SERVER_H