Repository navigation
Show memory map of highlighted process #2148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pwilke
wants to merge
3
commits into
htop-dev:main
Choose a base branch
from
pwilke:mem-maps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| /* | ||
| htop - MapsScreen.c | ||
| (C) 2025 Pierre Wilke | ||
| (C) 2025 htop dev team | ||
| Released under the GNU GPLv2+, see the COPYING file | ||
| in the source distribution for its full text. | ||
| */ | ||
|
|
||
| #include "config.h" // IWYU pragma: keep | ||
|
|
||
| #include "MapsScreen.h" | ||
|
|
||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| #include "Macros.h" | ||
| #include "Panel.h" | ||
| #include "Platform.h" | ||
| #include "ProvideCurses.h" | ||
| #include "XUtils.h" | ||
|
|
||
|
|
||
| MapsScreen* MapsScreen_new(Process* process) { | ||
| MapsScreen* this = xMalloc(sizeof(MapsScreen)); | ||
| Object_setClass(this, Class(MapsScreen)); | ||
| return (MapsScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " "); | ||
| } | ||
|
|
||
| void MapsScreen_delete(Object* this) { | ||
| free(InfoScreen_done((InfoScreen*)this)); | ||
| } | ||
|
|
||
| static void MapsScreen_draw(InfoScreen* this) { | ||
| InfoScreen_drawTitled(this, "Maps of process %d - %s", Process_getPid(this->process), Process_getCommand(this->process)); | ||
| } | ||
|
|
||
| static void MapsScreen_scan(InfoScreen* this) { | ||
| Panel* panel = this->display; | ||
| int idx = MAXIMUM(Panel_getSelectedIndex(panel), 0); | ||
|
|
||
| Panel_prune(panel); | ||
|
|
||
| char* maps = Platform_getProcessMaps(Process_getPid(this->process)); | ||
| if (maps) { | ||
| char* p = maps; | ||
| char* pp = maps; | ||
| while (*p) { | ||
| if (*p == '\n') { | ||
| *p = '\0'; | ||
| InfoScreen_addLine(this, pp); | ||
| pp = p + 1; | ||
| } | ||
| p++; | ||
| } | ||
| free(maps); | ||
| } else { | ||
| InfoScreen_addLine(this, "Could not read process maps."); | ||
| } | ||
|
|
||
| /* The kernel already lists mappings in ascending start-address order; | ||
| keep it rather than sorting the lines as text (which would order the | ||
| addresses lexically). */ | ||
| Panel_setSelected(panel, idx); | ||
| } | ||
|
|
||
| const InfoScreenClass MapsScreen_class = { | ||
| .super = { | ||
| .extends = Class(Object), | ||
| .delete = MapsScreen_delete | ||
| }, | ||
| .scan = MapsScreen_scan, | ||
| .draw = MapsScreen_draw | ||
| }; |
This file contains hidden or 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,26 @@ | ||
| #ifndef HEADER_MapsScreen | ||
| #define HEADER_MapsScreen | ||
| /* | ||
| htop - MapsScreen.h | ||
| (C) 2025 Pierre Wilke | ||
| (C) 2025 htop dev team | ||
| Released under the GNU GPLv2+, see the COPYING file | ||
| in the source distribution for its full text. | ||
| */ | ||
|
|
||
| #include "InfoScreen.h" | ||
| #include "Object.h" | ||
| #include "Process.h" | ||
|
|
||
|
|
||
| typedef struct MapsScreen_ { | ||
| InfoScreen super; | ||
| } MapsScreen; | ||
|
|
||
| extern const InfoScreenClass MapsScreen_class; | ||
|
|
||
| MapsScreen* MapsScreen_new(Process* process); | ||
|
|
||
| void MapsScreen_delete(Object* this); | ||
|
|
||
| #endif |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clang analyzer complains about this line, with EOF/error state not properly checked.