LLDB  mainline
Support.cpp
Go to the documentation of this file.
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 
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) {
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) {
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) {
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 }
#define LLDB_LOG(log,...)
Definition: Log.h:209
A file class.
Definition: File.h:29
#define LIBLLDB_LOG_HOST
Definition: Logging.h:28
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file)
Definition: Support.cpp:14
uint64_t pid_t
Definition: lldb-types.h:85