blob: b9deb21b55ebf834b78b0932a052e2e6571087ea [file] [log] [blame]
Pavel Labath7e437f82017-03-15 15:08:49 +00001//===-- Support.cpp ---------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Labath7e437f82017-03-15 15:08:49 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Host/linux/Support.h"
10#include "lldb/Utility/Log.h"
11#include "llvm/Support/MemoryBuffer.h"
12
13llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
14lldb_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
25llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
26lldb_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 Addepally99e37692017-06-28 07:58:31 +000034
35llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
36lldb_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}