This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monitor: Add ability to inspect process memory layout
- Loading branch information
Showing
6 changed files
with
173 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SET(SOURCES main.cpp ProcessListWidget.cpp MemoryUsageWidget.cpp ProcessManager.cpp ProcessInspectorWidget.cpp) | ||
SET(SOURCES main.cpp ProcessListWidget.cpp MemoryUsageWidget.cpp ProcessManager.cpp ProcessInspectorWidget.cpp ProcessMemoryLayoutWidget.cpp) | ||
MAKE_APP(monitor) | ||
TARGET_LINK_LIBRARIES(monitor libui libsys) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
programs/applications/monitor/ProcessMemoryLayoutWidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later */ | ||
/* Copyright © 2016-2024 Byteduck */ | ||
|
||
#include "ProcessMemoryLayoutWidget.h" | ||
#include <libui/widget/Label.h> | ||
|
||
using namespace Sys; | ||
using namespace UI; | ||
|
||
ProcessMemoryLayoutWidget::ProcessMemoryLayoutWidget(Sys::Process process): | ||
m_process(std::move(process)) | ||
{} | ||
|
||
void ProcessMemoryLayoutWidget::update() { | ||
m_memory_regions = m_process.memory_regions(); | ||
m_table_view->update_data(); | ||
} | ||
|
||
void ProcessMemoryLayoutWidget::initialize() { | ||
set_sizing_mode(UI::FILL); | ||
m_table_view->set_delegate(self()); | ||
add_child(m_table_view); | ||
} | ||
|
||
Duck::Ptr<UI::Widget> ProcessMemoryLayoutWidget::tv_create_entry(int row, int col) { | ||
auto reg = m_memory_regions[row]; | ||
std::string contents; | ||
|
||
switch(col) { | ||
case Col::Start: | ||
contents = Duck::format("{#x}", reg.start); | ||
break; | ||
case Col::Size: | ||
contents = reg.size.readable(); | ||
break; | ||
case Col::Offset: | ||
contents = Duck::format("{#x}", reg.object_start); | ||
break; | ||
case Col::Mode: | ||
contents = Duck::format("{}{}{}{}", | ||
reg.shared ? "s" : "p", | ||
reg.prot.read ? "r" : "-", | ||
reg.prot.write ? "w" : "-", | ||
reg.prot.execute ? "x" : "-"); | ||
break; | ||
case Col::Type: | ||
contents = reg.type == Sys::Process::MemoryRegion::Inode ? "Inode" : "Anonymous"; | ||
break; | ||
case Col::Name: | ||
contents = reg.name; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return Label::make(contents); | ||
} | ||
|
||
std::string ProcessMemoryLayoutWidget::tv_column_name(int col) { | ||
switch(col) { | ||
case Col::Start: | ||
return "Start"; | ||
case Col::Size: | ||
return "Size"; | ||
case Col::Offset: | ||
return "Offset"; | ||
case Col::Mode: | ||
return "Mode"; | ||
case Col::Type: | ||
return "Type"; | ||
case Col::Name: | ||
return "Name"; | ||
default: | ||
return ""; | ||
} | ||
} | ||
|
||
int ProcessMemoryLayoutWidget::tv_num_entries() { | ||
return m_memory_regions.size(); | ||
} | ||
|
||
int ProcessMemoryLayoutWidget::tv_row_height() { | ||
return 18; | ||
} | ||
|
||
int ProcessMemoryLayoutWidget::tv_column_width(int col) { | ||
switch(col) { | ||
case Col::Start: | ||
return 80; | ||
case Col::Size: | ||
return 50; | ||
case Col::Offset: | ||
return 100; | ||
case Col::Mode: | ||
return 40; | ||
case Col::Type: | ||
return 80; | ||
case Col::Name: | ||
return -1; | ||
default: | ||
return -1; | ||
} | ||
} | ||
|
||
void ProcessMemoryLayoutWidget::tv_selection_changed(const std::set<int>& selected_items) { | ||
TableViewDelegate::tv_selection_changed(selected_items); | ||
} | ||
|
||
Duck::Ptr<UI::Menu> ProcessMemoryLayoutWidget::tv_entry_menu(int row) { | ||
return TableViewDelegate::tv_entry_menu(row); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later */ | ||
/* Copyright © 2016-2024 Byteduck */ | ||
|
||
#pragma once | ||
|
||
#include <libui/widget/TableView.h> | ||
#include <libsys/Process.h> | ||
|
||
class ProcessMemoryLayoutWidget: public UI::Widget, public UI::TableViewDelegate { | ||
public: | ||
WIDGET_DEF(ProcessMemoryLayoutWidget); | ||
void update(); | ||
|
||
protected: | ||
// ListViewDelegate | ||
Duck::Ptr<Widget> tv_create_entry(int row, int col) override; | ||
std::string tv_column_name(int col) override; | ||
int tv_num_entries() override; | ||
int tv_row_height() override; | ||
int tv_column_width(int col) override; | ||
UI::TableViewSelectionMode tv_selection_mode() override { return UI::TableViewSelectionMode::SINGLE; } | ||
void tv_selection_changed(const std::set<int>& selected_items) override; | ||
Duck::Ptr<UI::Menu> tv_entry_menu(int row) override; | ||
|
||
// Object | ||
void initialize() override; | ||
|
||
private: | ||
enum Col { | ||
Start = 0, | ||
Size = 1, | ||
Offset = 2, | ||
Mode = 3, | ||
Type = 4, | ||
Name = 5 | ||
}; | ||
|
||
ProcessMemoryLayoutWidget(Sys::Process process); | ||
|
||
Sys::Process m_process; | ||
Duck::Ptr<UI::TableView> m_table_view = UI::TableView::make(6, true); | ||
std::vector<Sys::Process::MemoryRegion> m_memory_regions; | ||
}; |