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.
This commit is contained in:
Linus Groh 2021-01-15 20:49:32 +01:00 committed by Andreas Kling
parent 1ccc2e6482
commit 0187fd4fdd
Notes: sideshowbarker 2024-07-18 23:47:27 +09:00
2 changed files with 32 additions and 2 deletions

View File

@ -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()) {

View File

@ -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>);