From 739b857adf5f1be1b273c247bf4e809265979017 Mon Sep 17 00:00:00 2001 From: Franck Bui-Huu Date: Mon, 20 Dec 2010 15:18:04 +0100 Subject: [PATCH] --- yaml --- r: 223935 b: refs/heads/master c: fde52dbd7f71934aba4e150f3d1d51e826a08850 h: refs/heads/master i: 223933: ea818ca0a10ef2360f995dedcae6786af77c0279 223931: 63cd62e7e6d8fe1842080060d982898a2b14458b 223927: 816366171980ea144d754a8b3df0521142d9fe2b 223919: 458bd535a44e43edf93e59e4ae447e67bd3bc3b1 223903: 1e3701e99d581d1047e0d0dc66e8dcc306dfd31f 223871: 91249362cfbe20e49aa35b514d8250e578df1144 v: v3 --- [refs] | 2 +- trunk/tools/perf/util/probe-event.c | 38 ++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/[refs] b/[refs] index 5e9cd416a646..a4721e31f03f 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 9d95b580a8d64ef4d1660a21a9de0658fe29f041 +refs/heads/master: fde52dbd7f71934aba4e150f3d1d51e826a08850 diff --git a/trunk/tools/perf/util/probe-event.c b/trunk/tools/perf/util/probe-event.c index 3ba9c5393775..80cc0bc284fd 100644 --- a/trunk/tools/perf/util/probe-event.c +++ b/trunk/tools/perf/util/probe-event.c @@ -287,7 +287,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir, #define LINEBUF_SIZE 256 #define NR_ADDITIONAL_LINES 2 -static int show_one_line(FILE *fp, int l, bool skip, bool show_num) +static int __show_one_line(FILE *fp, int l, bool skip, bool show_num) { char buf[LINEBUF_SIZE]; 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) } while (strchr(buf, '\n') == NULL); - return 0; + return 1; error: - if (feof(fp)) + if (ferror(fp)) { pr_warning("Source file is shorter than expected.\n"); - else - pr_warning("File read error: %s\n", strerror(errno)); + return -1; + } + return 0; +} - return -1; +static int _show_one_line(FILE *fp, int l, bool skip, bool show_num) +{ + int rv = __show_one_line(fp, l, skip, show_num); + if (rv == 0) { + pr_warning("Source file is shorter than expected.\n"); + rv = -1; + } + return rv; } +#define show_one_line_with_num(f,l) _show_one_line(f,l,false,true) +#define show_one_line(f,l) _show_one_line(f,l,false,false) +#define skip_one_line(f,l) _show_one_line(f,l,true,false) +#define show_one_line_or_eof(f,l) __show_one_line(f,l,false,false) + /* * Show line-range always requires debuginfo to find source file and * line number. @@ -374,27 +388,27 @@ int show_line_range(struct line_range *lr, const char *module) } /* Skip to starting line number */ while (l < lr->start) { - ret = show_one_line(fp, l++, true, false); + ret = skip_one_line(fp, l++); if (ret < 0) goto end; } list_for_each_entry(ln, &lr->line_list, list) { for (; ln->line > l; l++) { - ret = show_one_line(fp, l - lr->offset, false, false); + ret = show_one_line(fp, l - lr->offset); if (ret < 0) goto end; } - ret = show_one_line(fp, l++ - lr->offset, false, true); + ret = show_one_line_with_num(fp, l++ - lr->offset); if (ret < 0) goto end; } if (lr->end == INT_MAX) lr->end = l + NR_ADDITIONAL_LINES; - while (l <= lr->end && !feof(fp)) { - ret = show_one_line(fp, l++ - lr->offset, false, false); - if (ret < 0) + while (l <= lr->end) { + ret = show_one_line_or_eof(fp, l++ - lr->offset); + if (ret <= 0) break; } end: