citrun

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

commit b780485691980822639602837cde41e59b61bd89
parent b42620fdfa61e6ae920027d8e4dacf35a08c73f3
Author: Kyle Milz <kyle@0x30.net>
Date:   Sun, 14 Aug 2016 14:08:09 -0600

src: try compiling unmodified source if modified source compile fails

Diffstat:
Msrc/check.in | 42+++++++++++++++++++++++-------------------
Msrc/inst_frontend.cc | 20++++----------------
Msrc/inst_frontend.h | 7+++----
Msrc/inst_main.cc | 21++++++++++++++++-----
4 files changed, 46 insertions(+), 44 deletions(-)

diff --git a/src/check.in b/src/check.in @@ -14,29 +14,33 @@ if [ $# -eq 1 ]; then fi [ -d $dir ] || err "citrun-check: $dir: no such directory" -GREP[0]="Found source file" -GREP[1]="Tool called as " -GREP[2]="Forked " -GREP[3]="Instrumentation successful" -GREP[4]="And the native compile failed" -GREP[5]="But the native compile succeeded" -GREP[6]="Link detected" -GREP[7]="warning: " -GREP[8]="error: " +GREP[0]="Tool called as " +GREP[1]="Link detected" +GREP[2]="Found source file" +GREP[3]="warning: " +GREP[4]="error: " +GREP[5]="Rewriting successful" +GREP[6]="And the native compile failed" +GREP[7]="But the native compile succeeded" +GREP[8]="Rewritten source compile successful" +GREP[9]="And the unrewritten source compile failed" +GREP[10]="But the unrewritten source compile succeeded" -DESC[0]="Source files input" -DESC[1]="Calls to the instrumentation tool" -DESC[2]="Forked compilers" -DESC[3]="Instrument successes" -DESC[4]="Both instrument and native compile failed (FP)" -DESC[5]="Instrument failed but native compile succeeded (TP)!" -DESC[6]="Application link commands" -DESC[7]="Warnings during source parsing" -DESC[8]="Errors during source parsing" +DESC[0]="Calls to the rewrite tool" +DESC[1]="Application link commands" +DESC[2]="Source files used as input" +DESC[3]="Rewrite parse warnings" +DESC[4]="Rewrite parse errors" +DESC[5]="Rewrite successes" +DESC[6]="Rewrite failures (False Positive)" +DESC[7]="Rewrite failures (True Positive!)" +DESC[8]="Rewritten source compile successes" +DESC[9]="Rewritten source compile failures (False Positive)" +DESC[10]="Rewritten source compile failures (True Positive!)" desc_len=${#DESC[@]} FINE[0]="Lines of source code" -FINE[1]="Milliseconds spent transforming source" +FINE[1]="Milliseconds spent rewriting source" FINE[2]="Functions called 'main'" FINE[3]="Function definitions" FINE[4]="If statements" diff --git a/src/inst_frontend.cc b/src/inst_frontend.cc @@ -208,17 +208,16 @@ InstrumentFrontend::instrument() } int -InstrumentFrontend::try_unmodified_compile() +InstrumentFrontend::try_compile(std::string const &variant) { - restore_original_src(); int ret = fork_compiler(); if (ret == 0) { - *m_log << "But the native compile succeeded!\n"; - return 1; + *m_log << "But " << variant << " succeeded!\n"; + return 0; } - *m_log << "And the native compile failed.\n"; + *m_log << "And " << variant << " failed.\n"; return ret; } @@ -278,14 +277,3 @@ InstrumentFrontend::fork_compiler() *m_log << "'" << child_pid << "' exited " << exit << ".\n"; return exit; } - -int -InstrumentFrontend::compile_modified() -{ - *m_log << "Running native compiler on modified source code.\n"; - - int ret = fork_compiler(); - restore_original_src(); - - return ret; -} diff --git a/src/inst_frontend.h b/src/inst_frontend.h @@ -9,13 +9,12 @@ public: void process_cmdline(); int instrument(); - int try_unmodified_compile(); - int compile_modified(); + int try_compile(std::string const &); + int fork_compiler(); + void restore_original_src(); private: void exec_compiler(); - int fork_compiler(); - void restore_original_src(); void save_if_srcfile(char *); void if_link_add_runtime(bool, bool); diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -123,17 +123,28 @@ main(int argc, char *argv[]) main.process_cmdline(); int ret = main.instrument(); - llog << "Instrumentation " << (ret ? "failed.\n" : "successful.\n"); + llog << "Rewriting " << (ret ? "failed.\n" : "successful.\n"); std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now(); llog << std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start_time).count() - << " Milliseconds spent transforming source.\n"; + << " Milliseconds spent rewriting source.\n"; if (is_citruninst) return ret; - if (ret) - return main.try_unmodified_compile(); + if (ret) { + main.restore_original_src(); + return main.try_compile("the native compile"); + } + + ret = main.fork_compiler(); + llog << "Rewritten source compile " + << (ret ? "failed.\n" : "successful.\n"); + + main.restore_original_src(); + + if (ret == 0) + return 0; - return main.compile_modified(); + return main.try_compile("the unrewritten source compile"); }