citrun

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

commit 955be042ff8a24181fbede3471ae8f873674b3aa
parent ff95de310a656ea68fe4e4bb5497fc968395bbbd
Author: Kyle Milz <kyle@0x30.net>
Date:   Tue,  9 Aug 2016 22:54:02 -0600

src: add do/while loop support

Diffstat:
Msrc/check.in | 9+++++----
Msrc/inst_visitor.cc | 6++++++
Msrc/inst_visitor.h | 2++
At/inst_dowhile.t | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/src/check.in b/src/check.in @@ -37,10 +37,11 @@ FINE[3]="Function definitions" FINE[4]="If statements" FINE[5]="For statements" FINE[6]="While statements" -FINE[7]="Switch statements" -FINE[8]="Return statement values" -FINE[9]="Call expressions" -FINE[10]="Total statements" +FINE[7]="Do while statements" +FINE[8]="Switch statements" +FINE[9]="Return statement values" +FINE[10]="Call expressions" +FINE[11]="Total statements" fine_len=${#FINE[@]} echo -n Checking \'$dir\' '' diff --git a/src/inst_visitor.cc b/src/inst_visitor.cc @@ -49,6 +49,12 @@ RewriteASTVisitor::VisitStmt(clang::Stmt *s) return true; m_counters[WHILE_STMT]++; } + else if (clang::isa<clang::DoStmt>(s)) { + s = clang::cast<clang::DoStmt>(s)->getCond(); + if (modify_stmt(s) == false) + return true; + m_counters[DOWHILE_STMT]++; + } else if (clang::isa<clang::SwitchStmt>(s)) { s = clang::cast<clang::SwitchStmt>(s)->getCond(); if (modify_stmt(s) == false) diff --git a/src/inst_visitor.h b/src/inst_visitor.h @@ -8,6 +8,7 @@ enum counters { IF_STMT, FOR_STMT, WHILE_STMT, + DOWHILE_STMT, SWITCH_STMT, RET_STMT_VAL, CALL_EXPR, @@ -25,6 +26,7 @@ public: "If statements", "For statements", "While statements", + "Do while statements", "Switch statements", "Return statement values", "Call expressions", diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t @@ -0,0 +1,55 @@ +#!/bin/sh -e +echo 1..3 + +. test/utils.sh +setup + +cat <<EOF > while.c +int +main(int argc, char *argv[]) +{ + do { + argc++; + } while (argc != 10); + return 0; +} +EOF + +cat <<EOF > while.c.inst_good +int +main(int argc, char *argv[]) +{citrun_start();++_citrun_lines[0];++_citrun_lines[1];++_citrun_lines[2]; + do { + argc++; + } while ((++_citrun_lines[5], argc != 10)); + return (++_citrun_lines[6], 0); +} +EOF + +cat <<EOF > citrun.log.good + +citrun-inst v0.0 () called as ''. +Resource directory is '' +Command line is ''. +Found source file ''. +Object arg = 0, compile arg = 1 +Added clangtool argument ''. +Instrumentation of '' finished: + 9 Lines of source code + 32 Lines of instrumentation header + 1 Functions called '' + 1 Function definitions + 1 Do while statements + 1 Return statement values + 11 Total statements +Writing modified source to ''. +Modified source written successfully. +Instrumentation successful. +EOF + +citrun-inst -c while.c + +diff -u while.c.inst_good while.c.citrun && echo "ok 2 - instrumented source diff" + +process_citrun_log +diff -u citrun.log.good citrun.log.proc && echo "ok 3 - citrun.log diff"