diff options
Diffstat (limited to 'tools/perf/util/probe-event.c')
-rw-r--r-- | tools/perf/util/probe-event.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 3ba9c5393775..80cc0bc284fd 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -287,7 +287,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir, | |||
287 | #define LINEBUF_SIZE 256 | 287 | #define LINEBUF_SIZE 256 |
288 | #define NR_ADDITIONAL_LINES 2 | 288 | #define NR_ADDITIONAL_LINES 2 |
289 | 289 | ||
290 | static int show_one_line(FILE *fp, int l, bool skip, bool show_num) | 290 | static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) |
291 | { | 291 | { |
292 | char buf[LINEBUF_SIZE]; | 292 | char buf[LINEBUF_SIZE]; |
293 | const char *color = show_num ? "" : PERF_COLOR_BLUE; | 293 | const char *color = show_num ? "" : PERF_COLOR_BLUE; |
@@ -306,16 +306,30 @@ static int show_one_line(FILE *fp, int l, bool skip, bool show_num) | |||
306 | 306 | ||
307 | } while (strchr(buf, '\n') == NULL); | 307 | } while (strchr(buf, '\n') == NULL); |
308 | 308 | ||
309 | return 0; | 309 | return 1; |
310 | error: | 310 | error: |
311 | if (feof(fp)) | 311 | if (ferror(fp)) { |
312 | pr_warning("Source file is shorter than expected.\n"); | 312 | pr_warning("Source file is shorter than expected.\n"); |
313 | else | 313 | return -1; |
314 | pr_warning("File read error: %s\n", strerror(errno)); | 314 | } |
315 | return 0; | ||
316 | } | ||
315 | 317 | ||
316 | return -1; | 318 | static int _show_one_line(FILE *fp, int l, bool skip, bool show_num) |
319 | { | ||
320 | int rv = __show_one_line(fp, l, skip, show_num); | ||
321 | if (rv == 0) { | ||
322 | pr_warning("Source file is shorter than expected.\n"); | ||
323 | rv = -1; | ||
324 | } | ||
325 | return rv; | ||
317 | } | 326 | } |
318 | 327 | ||
328 | #define show_one_line_with_num(f,l) _show_one_line(f,l,false,true) | ||
329 | #define show_one_line(f,l) _show_one_line(f,l,false,false) | ||
330 | #define skip_one_line(f,l) _show_one_line(f,l,true,false) | ||
331 | #define show_one_line_or_eof(f,l) __show_one_line(f,l,false,false) | ||
332 | |||
319 | /* | 333 | /* |
320 | * Show line-range always requires debuginfo to find source file and | 334 | * Show line-range always requires debuginfo to find source file and |
321 | * line number. | 335 | * line number. |
@@ -374,27 +388,27 @@ int show_line_range(struct line_range *lr, const char *module) | |||
374 | } | 388 | } |
375 | /* Skip to starting line number */ | 389 | /* Skip to starting line number */ |
376 | while (l < lr->start) { | 390 | while (l < lr->start) { |
377 | ret = show_one_line(fp, l++, true, false); | 391 | ret = skip_one_line(fp, l++); |
378 | if (ret < 0) | 392 | if (ret < 0) |
379 | goto end; | 393 | goto end; |
380 | } | 394 | } |
381 | 395 | ||
382 | list_for_each_entry(ln, &lr->line_list, list) { | 396 | list_for_each_entry(ln, &lr->line_list, list) { |
383 | for (; ln->line > l; l++) { | 397 | for (; ln->line > l; l++) { |
384 | ret = show_one_line(fp, l - lr->offset, false, false); | 398 | ret = show_one_line(fp, l - lr->offset); |
385 | if (ret < 0) | 399 | if (ret < 0) |
386 | goto end; | 400 | goto end; |
387 | } | 401 | } |
388 | ret = show_one_line(fp, l++ - lr->offset, false, true); | 402 | ret = show_one_line_with_num(fp, l++ - lr->offset); |
389 | if (ret < 0) | 403 | if (ret < 0) |
390 | goto end; | 404 | goto end; |
391 | } | 405 | } |
392 | 406 | ||
393 | if (lr->end == INT_MAX) | 407 | if (lr->end == INT_MAX) |
394 | lr->end = l + NR_ADDITIONAL_LINES; | 408 | lr->end = l + NR_ADDITIONAL_LINES; |
395 | while (l <= lr->end && !feof(fp)) { | 409 | while (l <= lr->end) { |
396 | ret = show_one_line(fp, l++ - lr->offset, false, false); | 410 | ret = show_one_line_or_eof(fp, l++ - lr->offset); |
397 | if (ret < 0) | 411 | if (ret <= 0) |
398 | break; | 412 | break; |
399 | } | 413 | } |
400 | end: | 414 | end: |