From 6550ea21064545b512d2be64ed292918951c1b30 Mon Sep 17 00:00:00 2001 From: liu-yaxue Date: Fri, 6 Dec 2024 15:17:11 +0800 Subject: [PATCH] Description: 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp index 635dbb14a027..298e468c1550 100644 --- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp +++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -172,15 +172,26 @@ struct ForkLaunchInfo { ec = llvm::sys::fs::is_directory(proc_fd_path, result); if (result) { std::vector files_to_close; + // get proc_fd_path for the process(/proc/pid/fd) + char path[PATH_MAX]; + lldb::pid_t pid = getpid(); + std::string dir_name = "/proc/" + std::to_string(pid) + "/fd"; // Directory iterator doesn't ensure any sequence. for (llvm::sys::fs::directory_iterator iter(proc_fd_path, ec), file_end; iter != file_end && !ec; iter.increment(ec)) { int fd = std::stoi(iter->path().substr(proc_fd_path.size() + 1)); - // Don't close first three entries since they are stdin, stdout and // stderr. - if (fd > 2 && !info.has_action(fd) && fd != error_fd) + if (fd > 2 && !info.has_action(fd) && fd != error_fd) { + ssize_t len = readlink(iter->path().c_str(), path, sizeof(path) - 1); + if (len != -1) { + path[len] = '\0'; + } + if (dir_name.compare(std::string(path)) == 0) + continue; + files_to_close.push_back(fd); + } } for (int file_to_close : files_to_close) close(file_to_close); -- Gitee