aboutsummaryrefslogtreecommitdiffstats
path: root/debian/patches/700-ltrace-support.patch
blob: 44b5d705ad59cfe24ffb786147c271e7f7d1c487 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Add support for 'ltrace' in addition to 'strace' support.
Index: htop/TraceScreen.c
===================================================================
--- htop.orig/TraceScreen.c	2014-05-01 12:58:42.000000000 +0300
+++ htop/TraceScreen.c	2014-05-01 12:59:07.000000000 +0300
@@ -29,10 +29,16 @@
 #include "Panel.h"
 #include "FunctionBar.h"
 
+typedef enum TraceType_ {
+   STRACE,
+   LTRACE
+} TraceType;
+
 typedef struct TraceScreen_ {
    Process* process;
    Panel* display;
    bool tracing;
+   TraceType type;
 } TraceScreen;
 
 }*/
@@ -43,9 +49,10 @@
 
 static int tsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
 
-TraceScreen* TraceScreen_new(Process* process) {
+TraceScreen* TraceScreen_new(Process* process, TraceType type) {
    TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen));
    this->process = process;
+   this->type = type;
    this->display = Panel_new(0, 1, COLS, LINES-2, false, Class(ListItem));
    this->tracing = true;
    return this;
@@ -59,7 +66,14 @@
 static void TraceScreen_draw(TraceScreen* this, IncSet* inc) {
    attrset(CRT_colors[PANEL_HEADER_FOCUS]);
    mvhline(0, 0, ' ', COLS);
-   mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm);
+   switch(this->type) {
+       case STRACE:
+          mvprintw(0, 0, "Trace of process %d - %s (STRACE)", this->process->pid, this->process->comm);
+          break;
+       case LTRACE:
+          mvprintw(0, 0, "Trace of process %d - %s (LTRACE)", this->process->pid, this->process->comm);
+          break;
+   }
    attrset(CRT_colors[DEFAULT_COLOR]);
    IncSet_drawBar(inc);
 }
@@ -90,16 +104,31 @@
       int ok = fcntl(fdpair[1], F_SETFL, O_NONBLOCK);
       if (ok != -1) {
          sprintf(buffer, "%d", this->process->pid);
-         execlp("strace", "strace", "-p", buffer, NULL);
+         switch(this->type) {
+            case STRACE:
+               execlp("strace", "strace", "-p", buffer, NULL);
+               break;
+            case LTRACE:
+               execlp("ltrace", "ltrace", "-p", buffer, NULL);
+               break;
+         }
+      }
+      const char* message;
+      switch(this->type) {
+         case STRACE:
+            message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
+            break;
+         case LTRACE:
+            message = "Could not execute 'ltrace'. Please make sure it is available in your $PATH.";
+            break;
       }
-      const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
       write(fdpair[1], message, strlen(message));
       exit(1);
    }
    fcntl(fdpair[0], F_SETFL, O_NONBLOCK);
-   FILE* strace = fdopen(fdpair[0], "r");
+   FILE* trace = fdopen(fdpair[0], "r");
    Panel* panel = this->display;
-   int fd_strace = fileno(strace);
+   int fd_trace = fileno(trace);
    CRT_disableDelay();
    bool contLine = false;
    bool follow = false;
@@ -125,13 +154,13 @@
          fd_set fds;
          FD_ZERO(&fds);
 //         FD_SET(STDIN_FILENO, &fds);
-         FD_SET(fd_strace, &fds);
+         FD_SET(fd_trace, &fds);
          struct timeval tv;
          tv.tv_sec = 0; tv.tv_usec = 500;
-         int ready = select(fd_strace+1, &fds, NULL, NULL, &tv);
+         int ready = select(fd_trace+1, &fds, NULL, NULL, &tv);
          int nread = 0;
-         if (ready > 0 && FD_ISSET(fd_strace, &fds))
+         if (ready > 0 && FD_ISSET(fd_trace, &fds))
-            nread = fread(buffer, 1, 1000, strace);
+            nread = fread(buffer, 1, 1000, trace);
          if (nread && this->tracing) {
             char* line = buffer;
             buffer[nread] = '\0';
@@ -224,6 +253,6 @@
    
    kill(child, SIGTERM);
    waitpid(child, NULL, 0);
-   fclose(strace);
+   fclose(trace);
    CRT_enableDelay();
 }
Index: htop/htop.1.in
===================================================================
--- htop.orig/htop.1.in	2014-05-01 12:58:42.000000000 +0300
+++ htop/htop.1.in	2014-05-01 12:59:07.000000000 +0300
@@ -67,6 +67,11 @@
 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.
 .TP
+.B L
+Trace process library calls: if ltrace(1) is installed, pressing this key
+will attach it to the currently selected process, presenting a live
+update of library calls issued by the process.
+.TP
 .B F1, h, ?
 Go to the help screen
 .TP
Index: htop/htop.c
===================================================================
--- htop.orig/htop.c	2014-05-01 12:58:42.000000000 +0300
+++ htop/htop.c	2014-05-01 12:59:07.000000000 +0300
@@ -103,7 +103,7 @@
 #endif
    { .key = "      l: ", .info = "list open files with lsof" },
    { .key = "      s: ", .info = "trace syscalls with strace" },
-   { .key = "         ", .info = "" },
+   { .key = "      L: ", .info = "trace library calls with ltrace" },
    { .key = "   F2 S: ", .info = "setup" },
    { .key = "   F1 h: ", .info = "show this help screen" },
    { .key = "  F10 q: ", .info = "quit" },
@@ -711,11 +711,24 @@
          Panel_onKey(panel, KEY_DOWN);
          break;
       }
+      case 'L':
+      {
+         Process* p = (Process*) Panel_getSelected(panel);
+         if (!p) break;
+         TraceScreen* ts = TraceScreen_new(p, LTRACE);
+         TraceScreen_run(ts);
+         TraceScreen_delete(ts);
+         clear();
+         FunctionBar_draw(defaultBar, NULL);
+         refreshTimeout = 0;
+         CRT_enableDelay();
+         break;
+      }
       case 's':
       {
          Process* p = (Process*) Panel_getSelected(panel);
          if (!p) break;
-         TraceScreen* ts = TraceScreen_new(p);
+         TraceScreen* ts = TraceScreen_new(p, STRACE);
          TraceScreen_run(ts);
          TraceScreen_delete(ts);
          clear();

© 2014-2024 Faster IT GmbH | imprint | privacy policy