Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Add 'press g to attach gdb' feature #991

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add 'press g to attach gdb' feature
Michael Ensslin committed Mar 19, 2020
commit 91f63163443b7f89a4d273fbfb48c00265db5443
20 changes: 20 additions & 0 deletions Action.c
Original file line number Diff line number Diff line change
@@ -392,6 +392,24 @@ static Htop_Reaction actionStrace(State* st) {
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}

static Htop_Reaction actionGdb(State* st) {
Process* p = (Process*) Panel_getSelected(st->panel);
if (!p) return HTOP_OK;

char buf[32];
xSnprintf(buf, sizeof(buf), "gdb -p %d", (int) p->pid);

endwin();
int result = system(buf);
refresh();

// we don't really care about the invocation result
(void) result;

CRT_enableDelay();
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}

static Htop_Reaction actionTag(State* st) {
Process* p = (Process*) Panel_getSelected(st->panel);
if (!p) return HTOP_OK;
@@ -437,6 +455,7 @@ static const struct { const char* key; const char* info; } helpRight[] = {
{ .key = " i: ", .info = "set IO priority" },
{ .key = " l: ", .info = "list open files with lsof" },
{ .key = " s: ", .info = "trace syscalls with strace" },
{ .key = " g: ", .info = "debug with gdb" },
{ .key = " ", .info = "" },
{ .key = " F2 C S: ", .info = "setup" },
{ .key = " F1 h: ", .info = "show this help screen" },
@@ -588,6 +607,7 @@ void Action_setBindings(Htop_Action* keys) {
keys[KEY_F(2)] = actionSetup;
keys['l'] = actionLsof;
keys['s'] = actionStrace;
keys['g'] = actionGdb;
keys[' '] = actionTag;
keys['\014'] = actionRedraw; // Ctrl+L
keys[KEY_F(1)] = actionHelp;
3 changes: 3 additions & 0 deletions htop.1.in
Original file line number Diff line number Diff line change
@@ -101,6 +101,9 @@ update of system calls issued by the process.
.B l
Display open files for a process: if lsof(1) is installed, pressing this key
will display the list of file descriptors opened by the process.
.B g
Debug process: if gdb(1) is installed, pressing this key will attach it
to the currently selected process, allowing you to debug it.
.TP
.B F1, h, ?
Go to the help screen