|
| 1 | +//===-- LinuxProcMaps.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 | + |
| 9 | +#include "LinuxProcStatus.h" |
| 10 | +#include <sstream> |
| 11 | +#include <string> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +static std::vector<std::string> SplitLines(llvm::StringRef proc_status) { |
| 15 | + std::istringstream inputstream(proc_status.str()); |
| 16 | + std::vector<std::string> lines; |
| 17 | + std::string line; |
| 18 | + while (std::getline(inputstream, line)) { |
| 19 | + lines.push_back(line); |
| 20 | + } |
| 21 | + return lines; |
| 22 | +} |
| 23 | + |
| 24 | +lldb_private::StructuredData::Dictionary |
| 25 | +ParseProcStatus(llvm::StringRef proc_status) { |
| 26 | + std::vector<std::string> lines = SplitLines(proc_status); |
| 27 | + lldb_private::StructuredData::Dictionary proc_status_data; |
| 28 | + for (auto &str : lines) { |
| 29 | + // proc/pid/status is a delineated by a colon, so we split all the lines |
| 30 | + // and then return a structureddata of each name : value. We keep these |
| 31 | + // all as text, and let the caller sort the type they want them as. |
| 32 | + size_t colonPos = str.find(':'); |
| 33 | + if (colonPos == std::string::npos) { |
| 34 | + continue; |
| 35 | + } |
| 36 | + std::string name = str.substr(0, colonPos); |
| 37 | + std::string value = str.substr(colonPos + 1); |
| 38 | + proc_status_data.AddStringItem(name, value); |
| 39 | + } |
| 40 | + |
| 41 | + return proc_status_data; |
| 42 | +} |
0 commit comments