xref: /llvm-project/lldb/source/Host/linux/Support.cpp (revision c34698a811b137b705738b7f8d193bc896027fb8)
180814287SRaphael Isemann //===-- Support.cpp -------------------------------------------------------===//
27e437f8fSPavel Labath //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67e437f8fSPavel Labath //
77e437f8fSPavel Labath //===----------------------------------------------------------------------===//
87e437f8fSPavel Labath 
97e437f8fSPavel Labath #include "lldb/Host/linux/Support.h"
10*c34698a8SPavel Labath #include "lldb/Utility/LLDBLog.h"
117e437f8fSPavel Labath #include "lldb/Utility/Log.h"
127e437f8fSPavel Labath #include "llvm/Support/MemoryBuffer.h"
137e437f8fSPavel Labath 
147e437f8fSPavel Labath llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getProcFile(::pid_t pid,::pid_t tid,const llvm::Twine & file)157e437f8fSPavel Labath lldb_private::getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file) {
16a007a6d8SPavel Labath   Log *log = GetLog(LLDBLog::Host);
177e437f8fSPavel Labath   std::string File =
187e437f8fSPavel Labath       ("/proc/" + llvm::Twine(pid) + "/task/" + llvm::Twine(tid) + "/" + file)
197e437f8fSPavel Labath           .str();
207e437f8fSPavel Labath   auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
217e437f8fSPavel Labath   if (!Ret)
227e437f8fSPavel Labath     LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
237e437f8fSPavel Labath   return Ret;
247e437f8fSPavel Labath }
257e437f8fSPavel Labath 
267e437f8fSPavel Labath llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getProcFile(::pid_t pid,const llvm::Twine & file)277e437f8fSPavel Labath lldb_private::getProcFile(::pid_t pid, const llvm::Twine &file) {
28a007a6d8SPavel Labath   Log *log = GetLog(LLDBLog::Host);
297e437f8fSPavel Labath   std::string File = ("/proc/" + llvm::Twine(pid) + "/" + file).str();
307e437f8fSPavel Labath   auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
317e437f8fSPavel Labath   if (!Ret)
327e437f8fSPavel Labath     LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
337e437f8fSPavel Labath   return Ret;
347e437f8fSPavel Labath }
3599e37695SRavitheja Addepally 
3699e37695SRavitheja Addepally llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getProcFile(const llvm::Twine & file)3799e37695SRavitheja Addepally lldb_private::getProcFile(const llvm::Twine &file) {
38a007a6d8SPavel Labath   Log *log = GetLog(LLDBLog::Host);
3999e37695SRavitheja Addepally   std::string File = ("/proc/" + file).str();
4099e37695SRavitheja Addepally   auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
4199e37695SRavitheja Addepally   if (!Ret)
4299e37695SRavitheja Addepally     LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
4399e37695SRavitheja Addepally   return Ret;
4499e37695SRavitheja Addepally }
45