Skip to content
This repository was 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
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions htop.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down