!479 Bugfix of socketpair process

Merge pull request !479 from lijiamin/debug
This commit is contained in:
openharmony_ci 2023-12-05 04:23:44 +00:00 committed by Gitee
commit e662764274
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 27 additions and 7 deletions

View File

@ -57,6 +57,7 @@ GetDispatchStatus g_getDispatchStatus = nullptr;
std::atomic<bool> g_hasArkFuncsInited = false; std::atomic<bool> g_hasArkFuncsInited = false;
std::unordered_map<const void*, Inspector*> g_inspectors; std::unordered_map<const void*, Inspector*> g_inspectors;
std::unordered_map<uint32_t, const DebuggerPostTask> g_debuggerPostTasks;
std::shared_mutex g_mutex; std::shared_mutex g_mutex;
#if !defined(IOS_PLATFORM) #if !defined(IOS_PLATFORM)
@ -142,7 +143,7 @@ void ResetServiceLocked(void *vm, bool isCloseHandle)
} }
bool InitializeInspector( bool InitializeInspector(
void* vm, const DebuggerPostTask& debuggerPostTask, const DebugInfo& debugInfo, uint32_t tidOfMainThread = 0) void* vm, const DebuggerPostTask& debuggerPostTask, const DebugInfo& debugInfo, uint32_t tidForSocketPair = 0)
{ {
std::unique_lock<std::shared_mutex> lock(g_mutex); std::unique_lock<std::shared_mutex> lock(g_mutex);
Inspector *newInspector = nullptr; Inspector *newInspector = nullptr;
@ -157,7 +158,7 @@ bool InitializeInspector(
} }
} }
newInspector->tidForSocketPair_ = tidOfMainThread; newInspector->tidForSocketPair_ = tidForSocketPair;
newInspector->tid_ = pthread_self(); newInspector->tid_ = pthread_self();
newInspector->vm_ = vm; newInspector->vm_ = vm;
newInspector->debuggerPostTask_ = debuggerPostTask; newInspector->debuggerPostTask_ = debuggerPostTask;
@ -277,9 +278,17 @@ void Inspector::OnMessage(std::string&& msg)
} }
} }
const DebuggerPostTask &GetDebuggerTask(uint32_t tid)
{
std::unique_lock<std::shared_mutex> lock(g_mutex);
if (g_debuggerPostTasks.find(tid) == g_debuggerPostTasks.end()) {
return {};
}
return g_debuggerPostTasks[tid];
}
// for ohos platform. // for ohos platform.
bool StartDebugForSocketpair(void* vm, uint32_t tidOfMainThread, bool StartDebugForSocketpair(void* vm, uint32_t tid, int socketfd)
const DebuggerPostTask& debuggerPostTask, int socketfd)
{ {
g_vm = vm; g_vm = vm;
#if !defined(IOS_PLATFORM) #if !defined(IOS_PLATFORM)
@ -294,8 +303,9 @@ bool StartDebugForSocketpair(void* vm, uint32_t tidOfMainThread,
g_initializeDebugger(vm, std::bind(&SendReply, vm, std::placeholders::_2)); g_initializeDebugger(vm, std::bind(&SendReply, vm, std::placeholders::_2));
const DebuggerPostTask &realDebuggerPostTask = GetDebuggerTask(tid);
DebugInfo debugInfo = {socketfd}; DebugInfo debugInfo = {socketfd};
if (!InitializeInspector(vm, debuggerPostTask, debugInfo, tidOfMainThread)) { if (!InitializeInspector(vm, realDebuggerPostTask, debugInfo, tid)) {
LOGE("Initialize inspector failed"); LOGE("Initialize inspector failed");
return false; return false;
} }
@ -366,4 +376,13 @@ void StopOldDebug(void* vm, const std::string& componentName)
ResetServiceLocked(vm, false); ResetServiceLocked(vm, false);
LOGI("StopDebug end"); LOGI("StopDebug end");
} }
// for socketpair process.
void StoreDebuggerPostTask(uint32_t tid, const DebuggerPostTask& debuggerPostTask)
{
std::unique_lock<std::shared_mutex> lock(g_mutex);
if (g_debuggerPostTasks.find(tid) == g_debuggerPostTasks.end()) {
g_debuggerPostTasks.emplace(tid, debuggerPostTask);
}
}
} // namespace OHOS::ArkCompiler::Toolchain } // namespace OHOS::ArkCompiler::Toolchain

View File

@ -35,8 +35,7 @@ extern "C" {
bool StartDebug(const std::string& componentName, void* vm, bool isDebugMode, bool StartDebug(const std::string& componentName, void* vm, bool isDebugMode,
int32_t instanceId, const DebuggerPostTask& debuggerPostTask, int port); int32_t instanceId, const DebuggerPostTask& debuggerPostTask, int port);
bool StartDebugForSocketpair(void* vm, uint32_t tidOfMainThread, bool StartDebugForSocketpair(void* vm, uint32_t tid, int socketfd);
const DebuggerPostTask& debuggerPostTask, int socketfd);
void StopDebug(const std::string& componentName); void StopDebug(const std::string& componentName);
@ -44,6 +43,8 @@ void StopOldDebug(void* vm, const std::string& componentName);
void WaitForDebugger(void* vm); void WaitForDebugger(void* vm);
void StoreDebuggerPostTask(uint32_t tid, const DebuggerPostTask& debuggerPostTask);
#if __cplusplus #if __cplusplus
} }
#endif #endif