-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmtrace-ng.1
522 lines (495 loc) · 16 KB
/
mtrace-ng.1
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
.\" -*-nroff-*-
.\" Copyright (c) 2015 Stefani Seibold <[email protected]>
.\"
.\" This program is free software; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of the
.\" License, or (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
.\" General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program; if not, write to the Free Software
.\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
.\" 02110-1301 USA
.\"
.TH MTRACE "12" "Oct 2015" "" "User Commands"
.SH NAME
mtrace-ng \- A dynamic memory allocation tracer
.SH SYNOPSIS
.\"
.\" ---------------------------------------------------------------------------
.\"
.PP
.BR mtrace-ng " \-t|\-\-trace
.\"
.\" Output formatting:
.\"
[\-d|\-\-depth \fIlevel\fR]
[\-F|\-\-config \fIfilename\fR]
[\-S|\-\-sort \fIoption\fR]
[\-o|\-\-output \fIfilename\fR]
.\"
.\" Various:
.\"
[\-a|\-\-autoscan]
[\-b|\-\-binpath \fIpath\fR]
[\-C|\-\-cwd \fIpath\fR]
[\-D|\-\-debug \fImask\fR]
[\-i|\-\-interactive]
[\-l|\-\-logfile \fIfilename\fR]
[\-L|\-\-long]
[\-n|\-\-nocpp]
[\-N|\-\-nohwbp]
[\-S|\-\-sanity]
[\-O|\-\-omit \fIfilename\fR]
[\-u|\-\-user \fIusername\fR]
[\-v|\-\-verbose]
.\"
.\" What processes to trace:
.\"
[\-e|\-\-follow\-exec]
[\-f|\-\-follow\-fork]
[\-p|\-\-pid \fIpid\fR]
[[\-\-] \fIcommand [arg ...]\fR]
.\"
.\" ---------------------------------------------------------------------------
.\"
.PP
.BR mtrace-ng " \-t|\-\-trace \-r|\-\-remote \fIaddr\fR"
[\-P|\-\-port \fInum\fR]
[\-w|\-\-wait]
.\"
.\" Output formatting:
.\"
[\-d|\-\-depth \fIlevel\fR]
.\"
.\" Various:
.\"
[\-C|\-\-cwd \fIpath\fR]
[\-D|\-\-debug \fImask\fR]
[\-l|\-\-logfile \fIfilename\fR]
[\-L|\-\-long]
[\-n|\-\-nocpp]
[\-N|\-\-nohwbp]
[\-S|\-\-sanity]
[\-O|\-\-omit \fIfilename\fR]
[\-u|\-\-user \fIusername\fR]
[\-v|\-\-verbose]
.\"
.\" What processes to trace:
.\"
[\-e|\-\-follow\-exec]
[\-f|\-\-follow\-fork]
[\-p|\-\-pid \fIpid\fR]
[[\-\-] \fIcommand [arg ...]\fR]
.\"
.\" ---------------------------------------------------------------------------
.\"
.PP
.BR mtrace-ng
[\-r|\-\-remote \fIaddr\fR]
[\-P|\-\-port \fInum\fR]
.\"
.\" Output formatting:
.\"
[\-F|\-\-config \fIfilename\fR]
[\-S|\-\-sort \fIoption\fR]
[\-o|\-\-output \fIfilename\fR]
.\"
.\" Various:
.\"
[\-a|\-\-autoscan]
[\-b|\-\-binpath \fIpath\fR]
[\-D|\-\-debug \fImask\fR]
[\-i|\-\-interactive]
[\-l|\-\-logfile \fIfilename\fR]
[\-v|\-\-verbose]
.\"
.\" ---------------------------------------------------------------------------
.\"
.PP
.BR mtrace-ng " \-V|\-\-version"
.PP
.BR mtrace-ng " \-h|\-\-help"
.SH DESCRIPTION
.B mtrace-ng
is a dynamic memory tracer, debugger and statistical analyses tool for C and
C++. It traces, records and reports all dynamic memory functions which are
called by the specified
.I command
or
.I process
until it exits or
.B mtrace-ng
is terminated.
Unlike other memory tracers, the trace will be performed by setting
breakpoints on each know dynamic allocation function. So no additional
library nor any kind of instrumentation or recompiling is needed to trace
and hunt for memory leaks.
.B mtrace-ng
is able to find no longer referenced memory allocation by scanning all
writable memory mappings of the program against the pointer of an allocation.
If the memory address will be not found during a scan there is a high change
for a missing reference and therefore for a memory leak.
The following functions will be intercepted:
.in +4
.nf
void *malloc(size_t size);
void free(void *ptr);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *aligned_alloc(size_t alignment, size_t size);
void *valloc(size_t size);
void *memalign(size_t alignment, size_t size);
void *pvalloc(size_t size);
void cfree(void *ptr);
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
int munmap(void *addr, size_t length);
void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
void *operator new(size_t size) throw (std::bad_alloc)
void *operator new(size_t size, const std::nothrow_t& nt) __THROW
void *operator new[](size_t size) throw (std::bad_alloc)
void *operator new[](size_t size, const std::nothrow_t& nt) __THROW
void operator delete(void* p) __THROW
void operator delete(void* p, const std::nothrow_t& nt) __THROW
void operator delete[](void* p) __THROW
void operator delete[](void* p, const std::nothrow_t& nt) __THROW
void operator delete(void*, unsigned long)
void operator delete[](void*, unsigned long)
.fi
.in
.PP
.B mtrace-ng
offers three different kind of working modes. A non interactive mode, a
server mode and a interactive client mode.
The most common mode is the non interactive mode, which allows to run
and/or attach to a process, similar to strace.
.B mtrace-ng
will show all open allocations when the traced program exists or
.B mtrace-ng
will be terminated.
For system with memory restrictions or for using in a cross architecture
environment,
.B mtrace-ng
offers a server mode which moves the memory bookkeeping and address resolution
outside to a connected client. In this case the server must be started on
target system where the program is executed. Then the client has to be started
on the remote host system.
To get a more detailed information about the dynamic memory consumption
.B mtrace-ng
can be started in an interactive mode. This mode is available for client
mode or when attaching to a process. See the section \fBINTERACTIVE MODE\fR
to learn more about the interactive commands in
\fBmtrace-ng\fR.
.SH OPTIONS
.PP
.IP "\-a, \-\-autoscan"
Scan all writeable memory mappings of the process for leaked pointers on exit
of the traced program or termination of \fBmtrace-ng\fR. If the pointer value of an
open allocated memory block will be not found on any aligned memory addresses,
it will be marked and reported as leaked. The scan can take some time,
depending on the size of the writeable memory mappings and the number of open
allocations.
.IP "\-b, \-\-binpath \fIpath\fR"
Set the binary search path. This option is mostly needed for remote cross
architecture trace and tells the client where to find the binaries or
libraries. The client tries to locate the binaries by adding the remote path
of the binary to the search path. If the binary is not found it will strip
down the leading directory of the remote path and try again until no more
leading directory is found. It is possible to add several binary search paths
by passing more than one \-b option.
.IP "\-c, \-\-cwd \fIpath\fR"
This option is valid in any mode except the client mode. Its used for locating
libraries for an attached process which are linked with relative paths. In this
case
.B mtrace-ng
does not know the origin state of the current working directory and need
to manually add this information.
.IP "\-D, \-\-debug \fImask\fR"
Show debugging output of
.B mtrace-ng
itself. \fImask\fR is a number
describing which debug messages should be displayed. Use the \-Dh option
to see what can be used. This option is only available when
.B mtrace-ng
was build with --enable-debug.
.IP "\-d, \-\-depth \fIlevel\fR"
Do backtrace of \fIlevel\fR stack frames for each memory allocation function.
.IP "\-e, \-\-follow-exec"
Trace processes as they are created by one of the currently traced processes as
a result of execve(2) system call.
.IP "\-f, \-\-follow-fork"
Trace child processes as they are created by one of the currently traced
processes as a result of the fork(2) system call.
.IP "\-F, \-\-config \fIpath"
Set the config file. For a detailed description of this file see
mtrace-ng.conf(5). It is possible to pass several config files by passing more
than one \-F option. If no -F is given,
.B mtrace-ng
will look up for one of the default files in the following order:
$HOME/.mtrace-ng,
$XDG_CONFIG_HOME/mtrace-ng,
SYSCONFDIR/mtrace-ng.conf,
/etc/mtrace-ng.conf
.IP "\-h, \-\-help"
Show a summary of the options to \fBmtrace-ng\fR and exit.
.IP "\-i, \-\-interactive"
Enables the interactive mode for client or when attaching to a process. See
the section \fBINTERACTIVE MODE\fR to learn more about the interactive commands
in this mode.
.IP "\-k, \-\-kill"
Kill \fBmtrace-ng\fR in case of a bookkeeping error. This options is intended for
.B mtrace-ng
development only!
.IP "\-O, \-\-omit \fIfilename"
Do not place any dynamic memory interception breakpoints in the given file.
This is usefull when a library offers memory allocation functions which does
only forward the calls. Use of this option can improve the trace performace in
this case. It is possible to omit several files by passing more than one
\-O option.
.IP "\-o, \-\-output \fIfilename"
Write the trace output to the file \fIfilename\fR rather than to stderr. When
passing this option the output will be written in reserve order in opposite the
stderr output. So the highest value of the sort order is at the beginning of
the file and the lowest at the end of the file.
.IP "\-l, \-\-logfile \fIfilename"
Use a given logfile instead of a socket connection. In trace mode all data will
be written into the logfile. In the non trace mode the data will be retrieved
from the logfile. This option can improve the performance of the trace
since the trace will be split into to different actions.
.IP "\-L, \-\-long"
Do a long dump which includes map file as well.
.IP "\-n, \-\-nocpp"
Disable the trace of C++ allocation operators. This is safe and faster for libstdc++,
since this library does call malloc() and free() inside the allocation operators.
.IP "\-N, \-\-nohwbp"
Disable the usage of hardware breakpoints. This options is intended for some
virtual machines, where hardware breakpoints do not work well.
.IP "\-p, \-\-pid \fIpid"
Attach to the process with the process ID \fIpid\fR and begin tracing.
This option can be used together with passing a command to execute.
It is possible to attach to several processes by passing more than one
\-p option.
.IP "\-P, \-\-port \fInum"
Set the port number for client or server mode. The default port number is 4576.
.IP "\-r, \-\-remote \fIaddr"
Run \fBmtrace-ng\fR in remote mode. Use \fIaddr\fR as socket path or address. If
\fIaddr\fR begins with / or . it will assumed a named socket, otherwise it
will be passed to getaddrinfo(3), which handles any kind of hostname, IPv4 or
IPv6 addresses. If this option is passed in conjunction with -t, mtrace-ng will be
execute in server mode, otherwise in client mode.
.IP "\-s, \-\-sortby keyword"
Sort the output of the stack backtraces by keyword. Valid keywords are:
.RS
\fIallocations\fR
.RS
Sort by the number of open allocations.
.RE
.RE
.RS
\fIaverage\fR
.RS
Sort by the number of average allocations (number of bytes in used / number of open allocations).
.RE
.RE
.RS
\fIbadfree\fR
.RS
Sort by number of bad free releases (only useful with \-S option).
.RE
.RE
.RS
\fIbytes-leaked\fR
.RS
Sort by number of bytes leaked (only useful with \-a option).
.RE
.RE
.RS
\fImismatched\fR
.RS
Sort by number of mismatched releases (only useful with \-S option).
.RE
.RE
.RS
\fIleaks\fR
.RS
Sort by number of leaked allocations (only useful with \-a option).
.RE
.RE
.RS
\fIstacks\fR
.RS
Like \fIallocations\fR but show also all stack backtraces with zero open allocations.
.RE
.RE
.RS
\fItotal\fR
.RS
Sort by the total number of allocations.
.RE
.RE
.RS
\fItsc\fR
.RS
Sort by the pseudo time stamp counter. Each stack backtrace will get an incremented counter value.
.RE
.RE
.RS
\fIusage\fR
.RS
Sort by number of bytes in use of all open allocations.
.RE
.RE
.IP "\-S, \-\-sanity"
Check mismatching operations against new/delete or free releases. This options
also sets the sort-by options to mismatched if no other sort option was set.
.IP "\-t, \-\-trace"
Run \fBmtrace-ng\fR in trace mode. In this mode all attached processes will run under
the control of \fBmtrace-ng\fR and all dynamic memory function calls will be traced.
If this options is not given, \fBmtrace-ng\fR will run in client mode.
.IP "\-u, \-\-user \fIusername\fR"
Run command with the userid, groupid and supplementary groups of
.IR username .
This option is only useful when running as root and enables the
correct execution of setuid and/or setgid binaries.
.IP "\-v, \-\-verbose"
Be verbose and display more details about what going on. This option can be
repeated for a more detailed view.
.IP "\-V, \-\-version"
Show the version number of \fBmtrace-ng\fR and exit.
.IP "\-w, \-\-wait"
This option stops the execution of the traced processes until a client is
connected to the server. So this option is only valid in server mode.
.SH INTERACTIVE MODE
The interactive mode offers a command line interface, which allows to gather
different kind of debug statistics during the runtime and after termination of
the traced program. Due the use of readline it offers auto completion by
using the TAB key. The following commands are available:
.in +4
.nf
dump
help
proclist
quit
reset
scan
set
show
start
status
stop
.fi
.in
.PP
.IP "dump \fIsortby\fR \fIpid\fR \fI>filename\fR"
The dump command allows to output the current state of the memory bookkeeping
at any time. It accepts a maximum of three parameters:
.RS
\fIsortby\fR
.RS
Sort the output of dump by the keyword. The keyword is the same as for the
\-S option (\fIallocations, \fIaverage\fR, \fIbadfree\fR \fIbytes-leaked\fR, \fIleaks\fR,
\fImismatched\fR, \fIstacks\fR, \fItotal\fR, \fItsc\fR and \fIusage\fR). See
\-S option for more details about the sortby keywords. The default sort order
is \fIallocations\fR when no sortby parameter is used.
.RE
.RE
.RS
\fIpid\fR
.RS
Process Id. When no process Id is specified the lowest pid of all currently
traced processes will be used as default.
.RE
.RE
.RS
\fI>filename\fR
.RS
Write the output to a file. When the parameter is omitted it will paging the
dump output.
.RE
.RE
.IP "help \fIcommand\fR"
Shows the help text for a given command. If no command parameter is passed, it
will show all available commands.
.IP "proclist"
Shows the list of currently traced processes.
.IP "quit"
Close the client connection and exit the
.B mtrace-ng
debugger.
.IP "reset \fIpid\fR"
Reset the bookkeeping of a given process Id.
.IP "scan \fIpid\fR \fImode\fR"
Scan for memory leaks for a given process Id. The scan operation can be only
performed when tracing is running. \fImode\fR is one of the following keywords:
.RS
\fIall\fR
.RS
Scan all open allocations for leaking.
.RE
.RE
.RS
\fIleak\fR
.RS
Scan all leaked marked allocations again.
.RE
.RE
.RS
\fInew\fR
.RS
Scan only allocations since last scan.
.RE
.RE
.IP "set searchpath \fIpathes\fR"
Set the searchpath for binaries and libraries. This is similar to to options
-b. To pass more the one path search path, use a colon as seperator. For a
detailed description about the search path see \-b option.
.IP "show \fI...\fR"
Show information about
.RS
\fIinfo\fR
.RS
Shows client settings.
.RE
.RE
.RS
\fIsearchpath\fR
.RS
Show searchpath for binaries and libraries.
.RE
.RE
.IP "start \fIpid\fR"
Start allocation tracing.
.IP "status \fIpid\fR"
Show allocation status.
.IP "stop \fIpid\fR"
Stop allocation tracing. Note that in this state a \fIscan\fR command can
not performed.
.SH BUGS
It only works on Linux for X86, X86_64, ARM 32 and PowerPC 32. No Hardware
Breakpoint support on ARM and PowerPC. No ARM Thumb support. See TODO file
for more open issues.
.LP
.PP
If you would like to report a bug, send a mail to [email protected]
.SH FILES
.TP
.I /etc/mtrace-ng.conf\fR or \fISYSCONFDIR/mtrace-ng.conf
System configuration file
.TP
.I $HOME/.mtrace-ng\fR or \fI$XDG_CONFIG_HOME/mtrace-ng
Personal config file, overrides system configuration file
.PP
See mtrace-ng.conf(5) for details on the syntax of this file.
.SH AUTHOR
Stefani Seibold <[email protected]>
.SH "SEE ALSO"
.BR mtrace-ng.conf(5),
.BR ptrace(2),
.BR perf(1)