Pavel Labath | 7e437f8 | 2017-03-15 15:08:49 +0000 | [diff] [blame] | 1 | //===-- Support.cpp ---------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Pavel Labath | 7e437f8 | 2017-03-15 15:08:49 +0000 | [diff] [blame] | 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 | } |
Ravitheja Addepally | 99e3769 | 2017-06-28 07:58:31 +0000 | [diff] [blame] | 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 | } |