1 //===-- Support.cpp ---------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Host/linux/Support.h" 10 #include "lldb/Utility/Log.h" 11 #include "llvm/Support/MemoryBuffer.h" 12 13 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> 14 lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) { 15 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 16 std::string File = 17 ("/proc/" + llvm::Twine(pid) + "/task/" + llvm::Twine(tid) + "/" + file) 18 .str(); 19 auto Ret = llvm::MemoryBuffer::getFileAsStream(File); 20 if (!Ret) 21 LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message()); 22 return Ret; 23 } 24 25 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> 26 lldb_private::getProcFile(::pid_t pid, const llvm::Twine &file) { 27 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 28 std::string File = ("/proc/" + llvm::Twine(pid) + "/" + file).str(); 29 auto Ret = llvm::MemoryBuffer::getFileAsStream(File); 30 if (!Ret) 31 LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message()); 32 return Ret; 33 } 34 35 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> 36 lldb_private::getProcFile(const llvm::Twine &file) { 37 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 38 std::string File = ("/proc/" + file).str(); 39 auto Ret = llvm::MemoryBuffer::getFileAsStream(File); 40 if (!Ret) 41 LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message()); 42 return Ret; 43 } 44