Skip to content

Commit 94248d8

Browse files
committed
Create proc status reader
1 parent 80182a7 commit 94248d8

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

lldb/source/Plugins/Process/Utility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_lldb_library(lldbPluginProcessUtility
66
HistoryUnwind.cpp
77
InferiorCallPOSIX.cpp
88
LinuxProcMaps.cpp
9+
LinuxProcStatus.cpp
910
LinuxSignals.cpp
1011
MemoryTagManagerAArch64MTE.cpp
1112
NativeProcessSoftwareSingleStep.cpp
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- LinuxProcStatus.h ---------------------------------------*- 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+
#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPROCSTATUS_H
10+
#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPROCSTATUS_H
11+
12+
#include "lldb/Utility/StructuredData.h"
13+
#include "lldb/lldb-forward.h"
14+
#include "llvm/ADT/StringRef.h"
15+
16+
namespace lldb_private {
17+
18+
StructuredData::Dictionary ParseProcStatus(llvm::StringRef proc_status);
19+
20+
} // namespace lldb_private
21+
22+
#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPROCSTATUS_H

0 commit comments

Comments
 (0)