summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-01-15 20:49:32 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-15 23:26:47 +0100
commit0187fd4fdd7c9272265d24abe9a37debfb864dee (patch)
tree4f03dad87ba402374bca65a1d58a07b6527f6292
parent1ccc2e6482aa9567039c8bc8b9df35f9275c4947 (diff)
downloadserenity-0187fd4fdd7c9272265d24abe9a37debfb864dee.zip
LibCoreDump: Expose arguments and environment
We can pull those from the coredump's ProcessInfo JSON, do some basic sanity checks and expose them as ready-to-use Vector<String>s.
-rw-r--r--Userland/Libraries/LibCoreDump/Reader.cpp30
-rw-r--r--Userland/Libraries/LibCoreDump/Reader.h4
2 files changed, 32 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCoreDump/Reader.cpp b/Userland/Libraries/LibCoreDump/Reader.cpp
index 843513e04c..ef6dd837f7 100644
--- a/Userland/Libraries/LibCoreDump/Reader.cpp
+++ b/Userland/Libraries/LibCoreDump/Reader.cpp
@@ -184,7 +184,35 @@ String Reader::process_executable_path() const
return executable_path.as_string_or({});
}
-const HashMap<String, String> Reader::metadata() const
+Vector<String> Reader::process_arguments() const
+{
+ auto process_info = this->process_info();
+ auto arguments = process_info.get("arguments");
+ if (!arguments.is_array())
+ return {};
+ Vector<String> vector;
+ arguments.as_array().for_each([&](auto& value) {
+ if (value.is_string())
+ vector.append(value.as_string());
+ });
+ return vector;
+}
+
+Vector<String> Reader::process_environment() const
+{
+ auto process_info = this->process_info();
+ auto environment = process_info.get("environment");
+ if (!environment.is_array())
+ return {};
+ Vector<String> vector;
+ environment.as_array().for_each([&](auto& value) {
+ if (value.is_string())
+ vector.append(value.as_string());
+ });
+ return vector;
+}
+
+HashMap<String, String> Reader::metadata() const
{
const ELF::Core::Metadata* metadata_notes_entry = nullptr;
for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) {
diff --git a/Userland/Libraries/LibCoreDump/Reader.h b/Userland/Libraries/LibCoreDump/Reader.h
index 15a7f38198..7fd3aaf715 100644
--- a/Userland/Libraries/LibCoreDump/Reader.h
+++ b/Userland/Libraries/LibCoreDump/Reader.h
@@ -65,7 +65,9 @@ public:
int process_pid() const;
u8 process_termination_signal() const;
String process_executable_path() const;
- const HashMap<String, String> metadata() const;
+ Vector<String> process_arguments() const;
+ Vector<String> process_environment() const;
+ HashMap<String, String> metadata() const;
private:
Reader(NonnullRefPtr<MappedFile>);