diff options
author | Franck Bui-Huu <fbuihuu@gmail.com> | 2010-12-20 09:18:04 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-12-21 13:20:12 -0500 |
commit | fde52dbd7f71934aba4e150f3d1d51e826a08850 (patch) | |
tree | 1b96f7055ad29b37a25e2de748f128ae5d44fb77 /tools | |
parent | 9d95b580a8d64ef4d1660a21a9de0658fe29f041 (diff) |
perf probe: Don't always consider EOF as an error when listing source code
When listing a whole file or a function which is located at the end,
perf-probe -L output wrongly: "Source file is shorter than expected.".
This is because show_one_line() always consider EOF as an error.
This patch fixes this by not considering EOF as an error when dumping
the trailing lines. Otherwise it's still an error and perf-probe still
outputs its warning.
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
LKML-Reference: <1292854685-8230-6-git-send-email-fbuihuu@gmail.com>
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-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: |