Pavel Labath | 7e437f8 | 2017-03-15 15:08:49 +0000 | [diff] [blame^] | 1 | //===-- Support.cpp ---------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Host/linux/Support.h" |
| 11 | #include "lldb/Utility/Log.h" |
| 12 | #include "llvm/Support/MemoryBuffer.h" |
| 13 | |
| 14 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> |
| 15 | lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) { |
| 16 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); |
| 17 | std::string File = |
| 18 | ("/proc/" + llvm::Twine(pid) + "/task/" + llvm::Twine(tid) + "/" + file) |
| 19 | .str(); |
| 20 | auto Ret = llvm::MemoryBuffer::getFileAsStream(File); |
| 21 | if (!Ret) |
| 22 | LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message()); |
| 23 | return Ret; |
| 24 | } |
| 25 | |
| 26 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> |
| 27 | lldb_private::getProcFile(::pid_t pid, const llvm::Twine &file) { |
| 28 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); |
| 29 | std::string File = ("/proc/" + llvm::Twine(pid) + "/" + file).str(); |
| 30 | auto Ret = llvm::MemoryBuffer::getFileAsStream(File); |
| 31 | if (!Ret) |
| 32 | LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message()); |
| 33 | return Ret; |
| 34 | } |