From 7ede8de5e2a3101619723aa73ccd3ecbdf0f7d1e Mon Sep 17 00:00:00 2001 From: liu-yaxue Date: Fri, 6 Dec 2024 15:17:11 +0800 Subject: [PATCH] [LLDB] Fix double close fd for lldb-server : The new image of phone require lldb to fix the close fd error(double close). The edited code fix the problem. issue: https://gitee.com/openharmony/third_party_llvm-project/issues/IB97T4?from=project-issue Test: recompile the lldb-server and upload it to the phone, remotely debug and execute the file. Signed-off-by: liu-yaxue --- .../Host/posix/ProcessLauncherPosixFork.cpp | 16 ++++++++++++++++ llvm/include/llvm/Support/FileSystem.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp index 635dbb14a027..6554df539ca3 100644 --- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp +++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -20,6 +20,9 @@ #include #include #include +#ifdef __OHOS_FAMILY__ +#include +#endif #include #include @@ -179,8 +182,21 @@ struct ForkLaunchInfo { // Don't close first three entries since they are stdin, stdout and // stderr. + #ifdef __OHOS_FAMILY__ + //OHOS_LOCAL begin + //Also do not close the directory itself since it would be + // closed after iteration. + //Here iter.get_handler() would return a int_ptr type, + //while dirfd() aacepts DIR* type to return the fd, so we use + //reinterpret_cast to cast the iter.get_handler() to DIR*. + int dir_fd = dirfd(reinterpret_cast(iter.get_handler())); + if (fd > 2 && !info.has_action(fd) && fd != error_fd && dir_fd != fd) + //OHOS_LOCAL end + #else if (fd > 2 && !info.has_action(fd) && fd != error_fd) + #endif files_to_close.push_back(fd); + } for (int file_to_close : files_to_close) close(file_to_close); diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h index 033482977a10..55783ac776f9 100644 --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -1451,6 +1451,12 @@ public: return *this; } + // OHOS_LOCAL begin + intptr_t get_handler() { + return State->IterationHandle; + } + // OHOS_LOCAL end + const directory_entry &operator*() const { return State->CurrentEntry; } const directory_entry *operator->() const { return &State->CurrentEntry; } -- Gitee