LLDB  mainline
Support.cpp
Go to the documentation of this file.
1 //===-- Support.cpp -------------------------------------------------------===//
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/LLDBLog.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 = GetLog(LLDBLog::Host);
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 = GetLog(LLDBLog::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 }
35 
36 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
37 lldb_private::getProcFile(const llvm::Twine &file) {
38  Log *log = GetLog(LLDBLog::Host);
39  std::string File = ("/proc/" + file).str();
40  auto Ret = llvm::MemoryBuffer::getFileAsStream(File);
41  if (!Ret)
42  LLDB_LOG(log, "Failed to open {0}: {1}", File, Ret.getError().message());
43  return Ret;
44 }
Log.h
lldb_private::File
Definition: File.h:35
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::getProcFile
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file)
Definition: Support.cpp:15
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
Support.h
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:336
lldb_private::Log
Definition: Log.h:115
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:308
LLDBLog.h