From: Bart Van Assche Date: Mon, 27 Jul 2009 12:03:03 +0000 (+0000) Subject: Fixed a bug in the code for reading suppression files: the line numbers X-Git-Tag: svn/VALGRIND_3_5_0~216 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2919d9219170e3d63a4d7e89851541d209f47157;p=thirdparty%2Fvalgrind.git Fixed a bug in the code for reading suppression files: the line numbers reported in error messages were not correct. As an example, the following output was produced before this patch (not correct): $ ./vg-in-place --tool=helgrind --num-callers=1 /bin/true ... FATAL: in suppressions file ".in_place/default.supp" near line 893: suppression must contain at least one location line which is not "..." exiting now. $ ./vg-in-place --tool=drd --num-callers=1 /bin/true FATAL: in suppressions file ".in_place/default.supp" near line 475: suppression must contain at least one location line which is not "..." exiting now. After having applied this patch the above commands display line numbers 1104 and 619, referring to the first suppression pattern containing three dots for the topmost stack frame, as expected. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10632 --- diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index cf0b8dff14..a92609ad38 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -964,7 +964,7 @@ static Int get_char ( Int fd, Char* out_buf ) return 1; } -Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp ) +Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp, Int* lineno ) { Char* buf = *bufpp; SizeT nBuf = *nBufp; @@ -975,6 +975,8 @@ Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp ) while (True) { n = get_char(fd, &ch); if (n == 1 && !VG_(isspace)(ch)) break; + if (n == 1 && ch == '\n' && lineno) + (*lineno)++; if (n <= 0) return True; } @@ -984,6 +986,8 @@ Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp ) while (True) { n = get_char(fd, &ch); if (n <= 0) return False; /* the next call will return True */ + if (ch == '\n' && lineno) + (*lineno)++; if (ch == '\n') break; if (i > 0 && i == nBuf-1) { *nBufp = nBuf = nBuf * 2; @@ -1103,21 +1107,18 @@ static void load_one_suppressions_file ( Char* filename ) supp->string = supp->extra = NULL; - eof = VG_(get_line) ( fd, &buf, &nBuf ); - lineno++; + eof = VG_(get_line) ( fd, &buf, &nBuf, &lineno ); if (eof) break; if (!VG_STREQ(buf, "{")) BOMB("expected '{' or end-of-file"); - eof = VG_(get_line) ( fd, &buf, &nBuf ); - lineno++; + eof = VG_(get_line) ( fd, &buf, &nBuf, &lineno ); if (eof || VG_STREQ(buf, "}")) BOMB("unexpected '}'"); supp->sname = VG_(arena_strdup)(VG_AR_CORE, "errormgr.losf.2", buf); - eof = VG_(get_line) ( fd, &buf, &nBuf ); - lineno++; + eof = VG_(get_line) ( fd, &buf, &nBuf, &lineno ); if (eof) BOMB("unexpected end-of-file"); @@ -1155,8 +1156,7 @@ static void load_one_suppressions_file ( Char* filename ) else { // Ignore rest of suppression while (True) { - eof = VG_(get_line) ( fd, &buf, &nBuf ); - lineno++; + eof = VG_(get_line) ( fd, &buf, &nBuf, &lineno ); if (eof) BOMB("unexpected end-of-file"); if (VG_STREQ(buf, "}")) break; @@ -1174,8 +1174,7 @@ static void load_one_suppressions_file ( Char* filename ) /* the main frame-descriptor reading loop */ i = 0; while (True) { - eof = VG_(get_line) ( fd, &buf, &nBuf ); - lineno++; + eof = VG_(get_line) ( fd, &buf, &nBuf, &lineno ); if (eof) BOMB("unexpected end-of-file"); if (VG_STREQ(buf, "}")) { @@ -1201,8 +1200,7 @@ static void load_one_suppressions_file ( Char* filename ) // lines and grab the '}'. if (!VG_STREQ(buf, "}")) { do { - eof = VG_(get_line) ( fd, &buf, &nBuf ); - lineno++; + eof = VG_(get_line) ( fd, &buf, &nBuf, &lineno ); } while (!eof && !VG_STREQ(buf, "}")); } diff --git a/exp-ptrcheck/pc_common.c b/exp-ptrcheck/pc_common.c index 365ffe95d1..4b6298b82b 100644 --- a/exp-ptrcheck/pc_common.c +++ b/exp-ptrcheck/pc_common.c @@ -741,7 +741,7 @@ Bool pc_read_extra_suppression_info ( Int fd, Char** bufpp, { Bool eof; if (VG_(get_supp_kind)(su) == XS_SysParam) { - eof = VG_(get_line) ( fd, bufpp, nBufp ); + eof = VG_(get_line) ( fd, bufpp, nBufp, NULL ); if (eof) return False; VG_(set_supp_string)(su, VG_(strdup)("pc.common.presi.1", *bufpp)); } diff --git a/include/pub_tool_errormgr.h b/include/pub_tool_errormgr.h index 8369cf1299..a473c6b641 100644 --- a/include/pub_tool_errormgr.h +++ b/include/pub_tool_errormgr.h @@ -92,8 +92,9 @@ extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, pointer to size_t holding its size; if the buffer is too small for the line, it will be realloc'd until big enough (updating *bufpp and *nBufp in the process). (It will bomb out if the size gets ridiculous). Skips - leading spaces on the line. Returns True if EOF was hit instead. */ -extern Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp ); + leading spaces on the line. Increments lineno with the number of lines + read if lineno is non-NULL. Returns True if EOF was hit. */ +extern Bool VG_(get_line) ( Int fd, Char** bufpp, SizeT* nBufp, Int* lineno ); /* ------------------------------------------------------------------ */ diff --git a/memcheck/mc_errors.c b/memcheck/mc_errors.c index 4e88f79889..0d54a1008b 100644 --- a/memcheck/mc_errors.c +++ b/memcheck/mc_errors.c @@ -1390,7 +1390,7 @@ Bool MC_(read_extra_suppression_info) ( Int fd, Char** bufpp, Bool eof; if (VG_(get_supp_kind)(su) == ParamSupp) { - eof = VG_(get_line) ( fd, bufpp, nBufp ); + eof = VG_(get_line) ( fd, bufpp, nBufp, NULL ); if (eof) return False; VG_(set_supp_string)(su, VG_(strdup)("mc.resi.1", *bufpp)); }