citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 74d8ef602fcccb9e014f812b75178162b6e8508b
parent 5f4a2177d40dac6e12ab9161cb9026f6dbcb89bb
Author: Kyle Milz <kyle@0x30.net>
Date:   Mon,  8 Aug 2016 19:00:25 -0600

src: fix off by one in line buffers

Diffstat:
Msrc/inst_ast_visitor.cc | 4++--
Mt/inst_for.t | 4++--
Mt/inst_if.t | 18+++++++++---------
Mt/inst_return.t | 12++++++------
Mt/inst_switch.t | 6+++---
Mt/inst_while.t | 8++++----
Mt/rt_counters_increase.t | 2+-
Mt/rt_dynamic.t | 29+++++++++++++++--------------
8 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/src/inst_ast_visitor.cc b/src/inst_ast_visitor.cc @@ -85,7 +85,7 @@ RewriteASTVisitor::modify_stmt(clang::Stmt *s) std::stringstream ss; ss << "(++_citrun_lines[" - << m_SM.getPresumedLineNumber(s->getLocStart()) + << m_SM.getPresumedLineNumber(s->getLocStart()) - 1 << "], "; if (m_TheRewriter.InsertTextBefore(s->getLocStart(), ss.str())) // writing failed, don't attempt to add ")" @@ -118,7 +118,7 @@ RewriteASTVisitor::VisitFunctionDecl(clang::FunctionDecl *f) int decl_start = m_SM.getPresumedLineNumber(f->getLocStart()); int decl_end = m_SM.getPresumedLineNumber(curly_brace); for (int i = decl_start; i <= decl_end; i++) - rewrite_text << "++_citrun_lines[" << i << "];"; + rewrite_text << "++_citrun_lines[" << i - 1 << "];"; // Rewrite the function source right after the beginning curly brace. m_TheRewriter.InsertTextBefore(curly_brace, rewrite_text.str()); diff --git a/t/inst_for.t b/t/inst_for.t @@ -22,10 +22,10 @@ cat <<EOF > for.c.inst_good int main(int argc, char *argv[]) -{citrun_start();++_citrun_lines[3];++_citrun_lines[4];++_citrun_lines[5]; +{citrun_start();++_citrun_lines[2];++_citrun_lines[3];++_citrun_lines[4]; for (;;); - for (argc = 0; (++_citrun_lines[8], argc < 10); argc++) + for (argc = 0; (++_citrun_lines[7], argc < 10); argc++) argv++; } EOF diff --git a/t/inst_if.t b/t/inst_if.t @@ -29,18 +29,18 @@ cat <<EOF > if.c.inst_good int main(int argc, char *argv[]) -{citrun_start();++_citrun_lines[3];++_citrun_lines[4];++_citrun_lines[5]; - if ((++_citrun_lines[6], argc == 1)) - return (++_citrun_lines[7], 1); +{citrun_start();++_citrun_lines[2];++_citrun_lines[3];++_citrun_lines[4]; + if ((++_citrun_lines[5], argc == 1)) + return (++_citrun_lines[6], 1); else - (++_citrun_lines[9], exit(14)); + (++_citrun_lines[8], exit(14)); - if ((++_citrun_lines[11], (argc = 2))) - return (++_citrun_lines[12], 5); - if ((++_citrun_lines[13], argc && argc + 1)) - return (++_citrun_lines[14], 0); + if ((++_citrun_lines[10], (argc = 2))) + return (++_citrun_lines[11], 5); + if ((++_citrun_lines[12], argc && argc + 1)) + return (++_citrun_lines[13], 0); else - (++_citrun_lines[16], exit(0)); + (++_citrun_lines[15], exit(0)); } EOF diff --git a/t/inst_return.t b/t/inst_return.t @@ -19,16 +19,16 @@ int main(void) { EOF cat <<EOF > return.c.inst_good -int foo() {++_citrun_lines[1]; - return (++_citrun_lines[2], 0); +int foo() {++_citrun_lines[0]; + return (++_citrun_lines[1], 0); } -int main(void) {citrun_start();++_citrun_lines[5]; - return (++_citrun_lines[6], 10); +int main(void) {citrun_start();++_citrun_lines[4]; + return (++_citrun_lines[5], 10); - return (++_citrun_lines[8], 10 + 10); + return (++_citrun_lines[7], 10 + 10); - return (++_citrun_lines[10], (++_citrun_lines[10], foo())); + return (++_citrun_lines[9], (++_citrun_lines[9], foo())); } EOF diff --git a/t/inst_switch.t b/t/inst_switch.t @@ -24,17 +24,17 @@ EOF cat <<EOF > switch.c.inst_good int main(void) -{citrun_start();++_citrun_lines[1];++_citrun_lines[2];++_citrun_lines[3]; +{citrun_start();++_citrun_lines[0];++_citrun_lines[1];++_citrun_lines[2]; int i; - switch ((++_citrun_lines[6], i)) { + switch ((++_citrun_lines[5], i)) { case 0: break; case 1: break; } - return (++_citrun_lines[13], 0); + return (++_citrun_lines[12], 0); } EOF diff --git a/t/inst_while.t b/t/inst_while.t @@ -19,12 +19,12 @@ EOF cat <<EOF > while.c.inst_good int main(int argc, char *argv[]) -{citrun_start();++_citrun_lines[1];++_citrun_lines[2];++_citrun_lines[3]; - while ((++_citrun_lines[4], argc < 17)) +{citrun_start();++_citrun_lines[0];++_citrun_lines[1];++_citrun_lines[2]; + while ((++_citrun_lines[3], argc < 17)) argc++; - while ((++_citrun_lines[7], (argc && argv))); - return (++_citrun_lines[8], 0); + while ((++_citrun_lines[6], (argc && argv))); + return (++_citrun_lines[7], 0); } EOF diff --git a/t/rt_counters_increase.t b/t/rt_counters_increase.t @@ -49,7 +49,7 @@ ok( keys %$data == 1, "single dynamic data key" ); my ($exec_lines1) = values %$data; # Only lines 8 - 12 in the source code above are executing -for (8..12) { +for (7..11) { # Runtime sends execution differences. cmp_ok( $exec_lines1->[$_], ">", 0, "line $_ executed nonzero times" ); } diff --git a/t/rt_dynamic.t b/t/rt_dynamic.t @@ -1,5 +1,5 @@ use strict; -use Test::More tests => 106; +use Test::More tests => 107; use Test::Project; use Test::Viewer; use Time::HiRes qw( usleep ); @@ -69,21 +69,22 @@ my $data = $viewer->get_dynamic_data(); my ($s0, $s1, $s2) = sort keys %$data; my @lines = @{ $data->{$s0} }; -is( $lines[$_], 0, "src 0 line $_ check" ) for (1..6); -is( $lines[$_], 1, "src 0 line $_ check" ) for (7..9); -is( $lines[$_], 0, "src 0 line $_ check" ) for (10..11); -is( $lines[12], 1, "src 0 line 14 check" ); -is( $lines[$_], 0, "src 0 line $_ check" ) for (13..14); -is( $lines[15], 1, "src 0 line 15 check" ); -is( $lines[16], 0, "src 0 line 16 check" ); -is( $lines[17], 2, "src 0 line 17 check" ); -is( $lines[$_], 0, "src 0 line $_ check" ) for (18..19); +is( $lines[$_], 0, "src 0 line $_ check" ) for (0..5); +is( $lines[$_], 1, "src 0 line $_ check" ) for (6..8); +is( $lines[$_], 0, "src 0 line $_ check" ) for (9..10); +is( $lines[11], 1, "src 0 line 11 check" ); +is( $lines[$_], 0, "src 0 line $_ check" ) for (12..13); +is( $lines[14], 1, "src 0 line 14 check" ); +is( $lines[15], 0, "src 0 line 15 check" ); +is( $lines[16], 2, "src 0 line 16 check" ); +is( $lines[$_], 0, "src 0 line $_ check" ) for (17..18); my @lines = @{ $data->{$s1} }; -is( $lines[0], 0, "src 1 line 0 check" ); -cmp_ok ( $lines[$_], ">", 1, "src 1 line $_ check" ) for (1..3); -cmp_ok ( $lines[$_], ">", 10, "src 1 line $_ check" ) for (4..7); -is( $lines[8], 0, "src 1 line 8 check" ); +cmp_ok ( $lines[$_], ">", 1, "src 1 line $_ check" ) for (0..2); +cmp_ok ( $lines[$_], ">", 10, "src 1 line $_ check" ) for (3..6); +is( $lines[7], 0, "src 1 line 7 check" ); +cmp_ok( $lines[8], ">", 10, "src 1 line 8 check" ); +is( $lines[9], 0, "src 1 line 9 check" ); my @lines = @{ $data->{$s2} }; is( $lines[$_], 0, "src 2 line $_ check" ) for (0..8);