|
65 | 65 | #include "syscalltbl.h"
|
66 | 66 | #include "rb_resort.h"
|
67 | 67 | #include "../perf.h"
|
| 68 | +#include "trace_augment.h" |
68 | 69 |
|
69 | 70 | #include <errno.h>
|
70 | 71 | #include <inttypes.h>
|
@@ -864,6 +865,10 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
|
864 | 865 | { .scnprintf = SCA_FILENAME, \
|
865 | 866 | .from_user = true, }
|
866 | 867 |
|
| 868 | +static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg); |
| 869 | + |
| 870 | +#define SCA_BUF syscall_arg__scnprintf_buf |
| 871 | + |
867 | 872 | static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size,
|
868 | 873 | struct syscall_arg *arg)
|
869 | 874 | {
|
@@ -1387,6 +1392,8 @@ static const struct syscall_fmt syscall_fmts[] = {
|
1387 | 1392 | .arg = { [2] = { .scnprintf = SCA_WAITID_OPTIONS, /* options */ }, }, },
|
1388 | 1393 | { .name = "waitid", .errpid = true,
|
1389 | 1394 | .arg = { [3] = { .scnprintf = SCA_WAITID_OPTIONS, /* options */ }, }, },
|
| 1395 | + { .name = "write", .errpid = true, |
| 1396 | + .arg = { [1] = { .scnprintf = SCA_BUF /* buf */, .from_user = true, }, }, }, |
1390 | 1397 | };
|
1391 | 1398 |
|
1392 | 1399 | static int syscall_fmt__cmp(const void *name, const void *fmtp)
|
@@ -1758,6 +1765,32 @@ static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
|
1758 | 1765 | return 0;
|
1759 | 1766 | }
|
1760 | 1767 |
|
| 1768 | +#define MAX_CONTROL_CHAR 31 |
| 1769 | +#define MAX_ASCII 127 |
| 1770 | + |
| 1771 | +static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_arg *arg) |
| 1772 | +{ |
| 1773 | + struct augmented_arg *augmented_arg = arg->augmented.args; |
| 1774 | + unsigned char *orig = (unsigned char *)augmented_arg->value; |
| 1775 | + size_t printed = 0; |
| 1776 | + int consumed; |
| 1777 | + |
| 1778 | + if (augmented_arg == NULL) |
| 1779 | + return 0; |
| 1780 | + |
| 1781 | + for (int j = 0; j < augmented_arg->size; ++j) { |
| 1782 | + bool control_char = orig[j] <= MAX_CONTROL_CHAR || orig[j] >= MAX_ASCII; |
| 1783 | + /* print control characters (0~31 and 127), and non-ascii characters in \(digits) */ |
| 1784 | + printed += scnprintf(bf + printed, size - printed, control_char ? "\\%d" : "%c", (int)orig[j]); |
| 1785 | + } |
| 1786 | + |
| 1787 | + consumed = sizeof(*augmented_arg) + augmented_arg->size; |
| 1788 | + arg->augmented.args = ((void *)arg->augmented.args) + consumed; |
| 1789 | + arg->augmented.size -= consumed; |
| 1790 | + |
| 1791 | + return printed; |
| 1792 | +} |
| 1793 | + |
1761 | 1794 | static bool trace__filter_duration(struct trace *trace, double t)
|
1762 | 1795 | {
|
1763 | 1796 | return t < (trace->duration_filter * NSEC_PER_MSEC);
|
|
0 commit comments