summaryrefslogtreecommitdiff
path: root/debuggerd/util.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2021-03-29 21:53:42 -0700
committerJosh Gao <jmgao@google.com>2021-03-30 12:15:56 -0700
commit31348a74e0708d8f51ee61b2fca2045f77e1f542 (patch)
treefc4484ce33e0d874d4e8acee745e3e9945f6ea56 /debuggerd/util.cpp
parent5d5e16db570f1da4b4115317c9aed32e632007c1 (diff)
debuggerd: store commandline instead of process name.
Bug: http://b/180605583 Test: debuggerd_test Change-Id: I018d399a5460f357766dc1b429f645f78fe88565
Diffstat (limited to 'debuggerd/util.cpp')
-rw-r--r--debuggerd/util.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/debuggerd/util.cpp b/debuggerd/util.cpp
index f3bff8c3d..ce0fd30f7 100644
--- a/debuggerd/util.cpp
+++ b/debuggerd/util.cpp
@@ -26,10 +26,31 @@
#include <android-base/strings.h>
#include "protocol.h"
+std::vector<std::string> get_command_line(pid_t pid) {
+ std::vector<std::string> result;
+
+ std::string cmdline;
+ android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid), &cmdline);
+
+ auto it = cmdline.cbegin();
+ while (it != cmdline.cend()) {
+ // string::iterator is a wrapped type, not a raw char*.
+ auto terminator = std::find(it, cmdline.cend(), '\0');
+ result.emplace_back(it, terminator);
+ it = std::find_if(terminator, cmdline.cend(), [](char c) { return c != '\0'; });
+ }
+ if (result.empty()) {
+ result.emplace_back("<unknown>");
+ }
+
+ return result;
+}
+
std::string get_process_name(pid_t pid) {
std::string result = "<unknown>";
android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid), &result);
- return result;
+ // We only want the name, not the whole command line, so truncate at the first NUL.
+ return result.c_str();
}
std::string get_thread_name(pid_t tid) {