Commit fde52dbd authored by Franck Bui-Huu's avatar Franck Bui-Huu Committed by Arnaldo Carvalho de Melo

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: default avatarMasami 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: default avatarFranck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9d95b580
...@@ -287,7 +287,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir, ...@@ -287,7 +287,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir,
#define LINEBUF_SIZE 256 #define LINEBUF_SIZE 256
#define NR_ADDITIONAL_LINES 2 #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]; char buf[LINEBUF_SIZE];
const char *color = show_num ? "" : PERF_COLOR_BLUE; 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,16 +306,30 @@ static int show_one_line(FILE *fp, int l, bool skip, bool show_num)
} while (strchr(buf, '\n') == NULL); } while (strchr(buf, '\n') == NULL);
return 0; return 1;
error: error:
if (feof(fp)) if (ferror(fp)) {
pr_warning("Source file is shorter than expected.\n"); pr_warning("Source file is shorter than expected.\n");
else return -1;
pr_warning("File read error: %s\n", strerror(errno)); }
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 * Show line-range always requires debuginfo to find source file and
* line number. * line number.
...@@ -374,27 +388,27 @@ int show_line_range(struct line_range *lr, const char *module) ...@@ -374,27 +388,27 @@ int show_line_range(struct line_range *lr, const char *module)
} }
/* Skip to starting line number */ /* Skip to starting line number */
while (l < lr->start) { while (l < lr->start) {
ret = show_one_line(fp, l++, true, false); ret = skip_one_line(fp, l++);
if (ret < 0) if (ret < 0)
goto end; goto end;
} }
list_for_each_entry(ln, &lr->line_list, list) { list_for_each_entry(ln, &lr->line_list, list) {
for (; ln->line > l; l++) { 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) if (ret < 0)
goto end; 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) if (ret < 0)
goto end; goto end;
} }
if (lr->end == INT_MAX) if (lr->end == INT_MAX)
lr->end = l + NR_ADDITIONAL_LINES; lr->end = l + NR_ADDITIONAL_LINES;
while (l <= lr->end && !feof(fp)) { while (l <= lr->end) {
ret = show_one_line(fp, l++ - lr->offset, false, false); ret = show_one_line_or_eof(fp, l++ - lr->offset);
if (ret < 0) if (ret <= 0)
break; break;
} }
end: end:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment