diff options
| -rw-r--r-- | tools/perf/util/trace-event-read.c | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index 22ded8000ef6..877706bd454f 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c | |||
| @@ -46,7 +46,7 @@ static int long_size; | |||
| 46 | static ssize_t calc_data_size; | 46 | static ssize_t calc_data_size; |
| 47 | static bool repipe; | 47 | static bool repipe; |
| 48 | 48 | ||
| 49 | static int do_read(int fd, void *buf, int size) | 49 | static int __do_read(int fd, void *buf, int size) |
| 50 | { | 50 | { |
| 51 | int rsize = size; | 51 | int rsize = size; |
| 52 | 52 | ||
| @@ -59,8 +59,10 @@ static int do_read(int fd, void *buf, int size) | |||
| 59 | if (repipe) { | 59 | if (repipe) { |
| 60 | int retw = write(STDOUT_FILENO, buf, ret); | 60 | int retw = write(STDOUT_FILENO, buf, ret); |
| 61 | 61 | ||
| 62 | if (retw <= 0 || retw != ret) | 62 | if (retw <= 0 || retw != ret) { |
| 63 | die("repiping input file"); | 63 | pr_debug("repiping input file"); |
| 64 | return -1; | ||
| 65 | } | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | size -= ret; | 68 | size -= ret; |
| @@ -70,14 +72,16 @@ static int do_read(int fd, void *buf, int size) | |||
| 70 | return rsize; | 72 | return rsize; |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | static int read_or_die(void *data, int size) | 75 | static int do_read(void *data, int size) |
| 74 | { | 76 | { |
| 75 | int r; | 77 | int r; |
| 76 | 78 | ||
| 77 | r = do_read(input_fd, data, size); | 79 | r = __do_read(input_fd, data, size); |
| 78 | if (r <= 0) | 80 | if (r <= 0) { |
| 79 | die("reading input file (size expected=%d received=%d)", | 81 | pr_debug("reading input file (size expected=%d received=%d)", |
| 80 | size, r); | 82 | size, r); |
| 83 | return -1; | ||
| 84 | } | ||
| 81 | 85 | ||
| 82 | if (calc_data_size) | 86 | if (calc_data_size) |
| 83 | calc_data_size += r; | 87 | calc_data_size += r; |
| @@ -93,7 +97,7 @@ static void skip(int size) | |||
| 93 | 97 | ||
| 94 | while (size) { | 98 | while (size) { |
| 95 | r = size > BUFSIZ ? BUFSIZ : size; | 99 | r = size > BUFSIZ ? BUFSIZ : size; |
| 96 | read_or_die(buf, r); | 100 | do_read(buf, r); |
| 97 | size -= r; | 101 | size -= r; |
| 98 | }; | 102 | }; |
| 99 | } | 103 | } |
| @@ -102,7 +106,8 @@ static unsigned int read4(struct pevent *pevent) | |||
| 102 | { | 106 | { |
| 103 | unsigned int data; | 107 | unsigned int data; |
| 104 | 108 | ||
| 105 | read_or_die(&data, 4); | 109 | if (do_read(&data, 4) < 0) |
| 110 | return 0; | ||
| 106 | return __data2host4(pevent, data); | 111 | return __data2host4(pevent, data); |
| 107 | } | 112 | } |
| 108 | 113 | ||
| @@ -110,7 +115,8 @@ static unsigned long long read8(struct pevent *pevent) | |||
| 110 | { | 115 | { |
| 111 | unsigned long long data; | 116 | unsigned long long data; |
| 112 | 117 | ||
| 113 | read_or_die(&data, 8); | 118 | if (do_read(&data, 8) < 0) |
| 119 | return 0; | ||
| 114 | return __data2host8(pevent, data); | 120 | return __data2host8(pevent, data); |
| 115 | } | 121 | } |
| 116 | 122 | ||
| @@ -166,7 +172,10 @@ static int read_proc_kallsyms(struct pevent *pevent) | |||
| 166 | if (buf == NULL) | 172 | if (buf == NULL) |
| 167 | return -1; | 173 | return -1; |
| 168 | 174 | ||
| 169 | read_or_die(buf, size); | 175 | if (do_read(buf, size) < 0) { |
| 176 | free(buf); | ||
| 177 | return -1; | ||
| 178 | } | ||
| 170 | buf[size] = '\0'; | 179 | buf[size] = '\0'; |
| 171 | 180 | ||
| 172 | parse_proc_kallsyms(pevent, buf, size); | 181 | parse_proc_kallsyms(pevent, buf, size); |
| @@ -180,6 +189,7 @@ static int read_ftrace_printk(struct pevent *pevent) | |||
| 180 | unsigned int size; | 189 | unsigned int size; |
| 181 | char *buf; | 190 | char *buf; |
| 182 | 191 | ||
| 192 | /* it can have 0 size */ | ||
| 183 | size = read4(pevent); | 193 | size = read4(pevent); |
| 184 | if (!size) | 194 | if (!size) |
| 185 | return 0; | 195 | return 0; |
| @@ -188,7 +198,10 @@ static int read_ftrace_printk(struct pevent *pevent) | |||
| 188 | if (buf == NULL) | 198 | if (buf == NULL) |
| 189 | return -1; | 199 | return -1; |
| 190 | 200 | ||
| 191 | read_or_die(buf, size); | 201 | if (do_read(buf, size) < 0) { |
| 202 | free(buf); | ||
| 203 | return -1; | ||
| 204 | } | ||
| 192 | 205 | ||
| 193 | parse_ftrace_printk(pevent, buf, size); | 206 | parse_ftrace_printk(pevent, buf, size); |
| 194 | 207 | ||
| @@ -201,8 +214,10 @@ static int read_header_files(struct pevent *pevent) | |||
| 201 | unsigned long long size; | 214 | unsigned long long size; |
| 202 | char *header_event; | 215 | char *header_event; |
| 203 | char buf[BUFSIZ]; | 216 | char buf[BUFSIZ]; |
| 217 | int ret = 0; | ||
| 204 | 218 | ||
| 205 | read_or_die(buf, 12); | 219 | if (do_read(buf, 12) < 0) |
| 220 | return -1; | ||
| 206 | 221 | ||
| 207 | if (memcmp(buf, "header_page", 12) != 0) | 222 | if (memcmp(buf, "header_page", 12) != 0) |
| 208 | die("did not read header page"); | 223 | die("did not read header page"); |
| @@ -216,7 +231,9 @@ static int read_header_files(struct pevent *pevent) | |||
| 216 | */ | 231 | */ |
| 217 | long_size = header_page_size_size; | 232 | long_size = header_page_size_size; |
| 218 | 233 | ||
| 219 | read_or_die(buf, 13); | 234 | if (do_read(buf, 13) < 0) |
| 235 | return -1; | ||
| 236 | |||
| 220 | if (memcmp(buf, "header_event", 13) != 0) | 237 | if (memcmp(buf, "header_event", 13) != 0) |
| 221 | die("did not read header event"); | 238 | die("did not read header event"); |
| 222 | 239 | ||
| @@ -225,9 +242,11 @@ static int read_header_files(struct pevent *pevent) | |||
| 225 | if (header_event == NULL) | 242 | if (header_event == NULL) |
| 226 | return -1; | 243 | return -1; |
| 227 | 244 | ||
| 228 | read_or_die(header_event, size); | 245 | if (do_read(header_event, size) < 0) |
| 246 | ret = -1; | ||
| 247 | |||
| 229 | free(header_event); | 248 | free(header_event); |
| 230 | return 0; | 249 | return ret; |
| 231 | } | 250 | } |
| 232 | 251 | ||
| 233 | static int read_ftrace_file(struct pevent *pevent, unsigned long long size) | 252 | static int read_ftrace_file(struct pevent *pevent, unsigned long long size) |
| @@ -238,7 +257,11 @@ static int read_ftrace_file(struct pevent *pevent, unsigned long long size) | |||
| 238 | if (buf == NULL) | 257 | if (buf == NULL) |
| 239 | return -1; | 258 | return -1; |
| 240 | 259 | ||
| 241 | read_or_die(buf, size); | 260 | if (do_read(buf, size) < 0) { |
| 261 | free(buf); | ||
| 262 | return -1; | ||
| 263 | } | ||
| 264 | |||
| 242 | parse_ftrace_file(pevent, buf, size); | 265 | parse_ftrace_file(pevent, buf, size); |
| 243 | free(buf); | 266 | free(buf); |
| 244 | return 0; | 267 | return 0; |
| @@ -253,7 +276,11 @@ static int read_event_file(struct pevent *pevent, char *sys, | |||
| 253 | if (buf == NULL) | 276 | if (buf == NULL) |
| 254 | return -1; | 277 | return -1; |
| 255 | 278 | ||
| 256 | read_or_die(buf, size); | 279 | if (do_read(buf, size) < 0) { |
| 280 | free(buf); | ||
| 281 | return -1; | ||
| 282 | } | ||
| 283 | |||
| 257 | parse_event_file(pevent, buf, size, sys); | 284 | parse_event_file(pevent, buf, size, sys); |
| 258 | free(buf); | 285 | free(buf); |
| 259 | return 0; | 286 | return 0; |
| @@ -294,6 +321,7 @@ static int read_event_files(struct pevent *pevent) | |||
| 294 | return -1; | 321 | return -1; |
| 295 | 322 | ||
| 296 | count = read4(pevent); | 323 | count = read4(pevent); |
| 324 | |||
| 297 | for (x=0; x < count; x++) { | 325 | for (x=0; x < count; x++) { |
| 298 | size = read8(pevent); | 326 | size = read8(pevent); |
| 299 | ret = read_event_file(pevent, sys, size); | 327 | ret = read_event_file(pevent, sys, size); |
| @@ -323,11 +351,13 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) | |||
| 323 | 351 | ||
| 324 | input_fd = fd; | 352 | input_fd = fd; |
| 325 | 353 | ||
| 326 | read_or_die(buf, 3); | 354 | if (do_read(buf, 3) < 0) |
| 355 | return -1; | ||
| 327 | if (memcmp(buf, test, 3) != 0) | 356 | if (memcmp(buf, test, 3) != 0) |
| 328 | die("no trace data in the file"); | 357 | die("no trace data in the file"); |
| 329 | 358 | ||
| 330 | read_or_die(buf, 7); | 359 | if (do_read(buf, 7) < 0) |
| 360 | return -1; | ||
| 331 | if (memcmp(buf, "tracing", 7) != 0) | 361 | if (memcmp(buf, "tracing", 7) != 0) |
| 332 | die("not a trace file (missing 'tracing' tag)"); | 362 | die("not a trace file (missing 'tracing' tag)"); |
| 333 | 363 | ||
| @@ -338,7 +368,8 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) | |||
| 338 | printf("version = %s\n", version); | 368 | printf("version = %s\n", version); |
| 339 | free(version); | 369 | free(version); |
| 340 | 370 | ||
| 341 | read_or_die(buf, 1); | 371 | if (do_read(buf, 1) < 0) |
| 372 | return -1; | ||
| 342 | file_bigendian = buf[0]; | 373 | file_bigendian = buf[0]; |
| 343 | host_bigendian = bigendian(); | 374 | host_bigendian = bigendian(); |
| 344 | 375 | ||
| @@ -348,10 +379,13 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe) | |||
| 348 | goto out; | 379 | goto out; |
| 349 | } | 380 | } |
| 350 | 381 | ||
| 351 | read_or_die(buf, 1); | 382 | if (do_read(buf, 1) < 0) |
| 383 | goto out; | ||
| 352 | long_size = buf[0]; | 384 | long_size = buf[0]; |
| 353 | 385 | ||
| 354 | page_size = read4(pevent); | 386 | page_size = read4(pevent); |
| 387 | if (!page_size) | ||
| 388 | goto out; | ||
| 355 | 389 | ||
| 356 | err = read_header_files(pevent); | 390 | err = read_header_files(pevent); |
| 357 | if (err) | 391 | if (err) |
