Author: labath Date: Tue Mar 21 08:49:45 2017 New Revision: 298374 URL: http://llvm.org/viewvc/llvm-project?rev=298374&view=rev Log: Remove ProcFileReader
This removes the last usage of ProcFileReader from NativeProcessLinux and then deletes the class itself. Removed: lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.cpp lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.h Modified: lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Modified: lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt?rev=298374&r1=298373&r2=298374&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt (original) +++ lldb/trunk/source/Plugins/Process/Linux/CMakeLists.txt Tue Mar 21 08:49:45 2017 @@ -11,7 +11,6 @@ add_lldb_library(lldbPluginProcessLinux NativeRegisterContextLinux_mips64.cpp NativeRegisterContextLinux_s390x.cpp NativeThreadLinux.cpp - ProcFileReader.cpp SingleStepCheck.cpp LINK_LIBS Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=298374&r1=298373&r2=298374&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Tue Mar 21 08:49:45 2017 @@ -46,7 +46,6 @@ #include "NativeThreadLinux.h" #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" -#include "ProcFileReader.h" #include "Procfs.h" #include "llvm/Support/FileSystem.h" @@ -1432,11 +1431,11 @@ Error NativeProcessLinux::Kill() { } static Error -ParseMemoryRegionInfoFromProcMapsLine(const std::string &maps_line, +ParseMemoryRegionInfoFromProcMapsLine(llvm::StringRef &maps_line, MemoryRegionInfo &memory_region_info) { memory_region_info.Clear(); - StringExtractor line_extractor(maps_line.c_str()); + StringExtractor line_extractor(maps_line); // Format: {address_start_hex}-{address_end_hex} perms offset dev inode // pathname @@ -1597,36 +1596,36 @@ Error NativeProcessLinux::PopulateMemory return Error(); } - Error error = ProcFileReader::ProcessLineByLine( - GetID(), "maps", [&](const std::string &line) -> bool { - MemoryRegionInfo info; - const Error parse_error = - ParseMemoryRegionInfoFromProcMapsLine(line, info); - if (parse_error.Success()) { - m_mem_region_cache.emplace_back( - info, FileSpec(info.GetName().GetCString(), true)); - return true; - } else { - LLDB_LOG(log, "failed to parse proc maps line '{0}': {1}", line, - parse_error); - return false; - } - }); - - // If we had an error, we'll mark unsupported. - if (error.Fail()) { + auto BufferOrError = getProcFile(GetID(), "maps"); + if (!BufferOrError) { m_supports_mem_region = LazyBool::eLazyBoolNo; - return error; - } else if (m_mem_region_cache.empty()) { + return BufferOrError.getError(); + } + StringRef Rest = BufferOrError.get()->getBuffer(); + while (! Rest.empty()) { + StringRef Line; + std::tie(Line, Rest) = Rest.split('\n'); + MemoryRegionInfo info; + const Error parse_error = ParseMemoryRegionInfoFromProcMapsLine(Line, info); + if (parse_error.Fail()) { + LLDB_LOG(log, "failed to parse proc maps line '{0}': {1}", Line, + parse_error); + m_supports_mem_region = LazyBool::eLazyBoolNo; + return parse_error; + } + m_mem_region_cache.emplace_back( + info, FileSpec(info.GetName().GetCString(), true)); + } + + if (m_mem_region_cache.empty()) { // No entries after attempting to read them. This shouldn't happen if // /proc/{pid}/maps is supported. Assume we don't support map entries // via procfs. + m_supports_mem_region = LazyBool::eLazyBoolNo; LLDB_LOG(log, "failed to find any procfs maps entries, assuming no support " "for memory region metadata retrieval"); - m_supports_mem_region = LazyBool::eLazyBoolNo; - error.SetErrorString("not supported"); - return error; + return Error("not supported"); } LLDB_LOG(log, "read {0} memory region entries from /proc/{1}/maps", Removed: lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.cpp?rev=298373&view=auto ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.cpp (removed) @@ -1,103 +0,0 @@ -//===-- ProcFileReader.cpp --------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "Plugins/Process/Linux/ProcFileReader.h" - -// C Headers -#include <fcntl.h> -#include <inttypes.h> -#include <limits.h> -#include <stdio.h> -#include <sys/stat.h> - -// C++ Headers -#include <fstream> - -// LLDB Headers -#include "lldb/Utility/DataBufferHeap.h" -#include "lldb/Utility/Error.h" - -using namespace lldb_private; -using namespace lldb_private::process_linux; - -lldb::DataBufferSP ProcFileReader::ReadIntoDataBuffer(lldb::pid_t pid, - const char *name) { - int fd; - char path[PATH_MAX]; - - // Make sure we've got a nil terminated buffer for all the folks calling - // GetBytes() directly off our returned DataBufferSP if we hit an error. - lldb::DataBufferSP buf_sp(new DataBufferHeap(1, 0)); - - // Ideally, we would simply create a FileSpec and call ReadFileContents. - // However, files in procfs have zero size (since they are, in general, - // dynamically generated by the kernel) which is incompatible with the - // current ReadFileContents implementation. Therefore we simply stream the - // data into a DataBuffer ourselves. - if (snprintf(path, PATH_MAX, "/proc/%" PRIu64 "/%s", pid, name) > 0) { - if ((fd = open(path, O_RDONLY, 0)) >= 0) { - size_t bytes_read = 0; - std::unique_ptr<DataBufferHeap> buf_ap(new DataBufferHeap(1024, 0)); - - for (;;) { - size_t avail = buf_ap->GetByteSize() - bytes_read; - ssize_t status = read(fd, buf_ap->GetBytes() + bytes_read, avail); - - if (status < 0) - break; - - if (status == 0) { - buf_ap->SetByteSize(bytes_read); - buf_sp.reset(buf_ap.release()); - break; - } - - bytes_read += status; - - if (avail - status == 0) - buf_ap->SetByteSize(2 * buf_ap->GetByteSize()); - } - - close(fd); - } - } - - return buf_sp; -} - -Error ProcFileReader::ProcessLineByLine( - lldb::pid_t pid, const char *name, - std::function<bool(const std::string &line)> line_parser) { - Error error; - - // Try to open the /proc/{pid}/maps entry. - char filename[PATH_MAX]; - snprintf(filename, sizeof(filename), "/proc/%" PRIu64 "/%s", pid, name); - filename[sizeof(filename) - 1] = '\0'; - - std::ifstream proc_file(filename); - if (proc_file.fail()) { - error.SetErrorStringWithFormat("failed to open file '%s'", filename); - return error; - } - - // Read the file line by line, processing until either end of file or when the - // line_parser returns false. - std::string line; - bool should_continue = true; - - while (should_continue && std::getline(proc_file, line)) { - // Pass the line over to the line_parser for processing. If the line_parser - // returns false, we - // stop processing. - should_continue = line_parser(line); - } - - return error; -} Removed: lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.h?rev=298373&view=auto ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcFileReader.h (removed) @@ -1,37 +0,0 @@ -//===-- ProcFileReader.h ----------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_ProcFileReader_h_ -#define liblldb_ProcFileReader_h_ - -#include <functional> - -#include "lldb/lldb-forward.h" -#include "lldb/lldb-types.h" - -namespace lldb_private { -namespace process_linux { - -class ProcFileReader { -public: - static lldb::DataBufferSP ReadIntoDataBuffer(lldb::pid_t pid, - const char *name); - - /// Parse the /proc/{@a pid}/{@a name} file line by line, passing each line to - /// line_parser, until - /// either end of file or until line_parser returns false. - static Error - ProcessLineByLine(lldb::pid_t pid, const char *name, - std::function<bool(const std::string &line)> line_parser); -}; - -} // namespace process_linux -} // namespace lldb_private - -#endif // #ifndef liblldb_ProcFileReader_h_ _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits