citrun

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

commit 1886d93420eccd4f8093e6a65070b8be4a72c779
parent e566be1fc2acf60825a41e85bb3c7e2f7a732838
Author: Kyle Milz <kyle@0x30.net>
Date:   Fri, 19 Aug 2016 13:00:32 -0600

src: stop forking so many damned things

Diffstat:
Mman/citrun-check.1 | 20++++++++------------
Msrc/check.in | 16++++++----------
Msrc/inst_frontend.cc | 24------------------------
Msrc/inst_frontend.h | 3+--
Msrc/inst_main.cc | 13+++++++------
5 files changed, 22 insertions(+), 54 deletions(-)

diff --git a/man/citrun-check.1 b/man/citrun-check.1 @@ -87,21 +87,17 @@ The total number of parsing problems the rewriter had. .It Qq Rewrite successes The number of times the rewriter successfully transformed the entire source file. -.It Qq Rewrite failures (False Positive) -The number of times the rewriter encountered a fatal error however the native -compiler also failed to compile the same code. -.It Qq Rewrite failures (True Positive!) -The number of times the rewriter encountered a fatal error but the native -compiler succeeded on the same code. This is bad. +.It Qq Rewrite failures +Rewriting a source file failed. There are two failure cases, either native +parsing the original source file also fails, or, only citrun-inst failed parsing +the source file. .It Qq Rewritten source compile successes The number of times the rewritten source file is processed successfully by the native compiler. -.It Qq Rewritten source compile failures (False Positive) -Similar to rewrite failure false positives, the number of times the native -compiler fails on both the rewritten source and the original source. -.It Qq Rewritten source compile failures (True Positive!) -The number of times the native compiler fails on the rewritten source and -succeeds on the original source. This is bad. +.It Qq Rewritten source compile failures +Compiling the rewritten source file failed. There are two failure cases, either +compiling the original source file also fails or only compiling the +rewritten source fails. .El .Sh EXIT STATUS .Ex -std diff --git a/src/check.in b/src/check.in @@ -20,11 +20,9 @@ GREP[2]="Link detected" 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" +GREP[6]="Rewriting failed" +GREP[7]="Rewritten source compile successful" +GREP[8]="Rewritten source compile failed" DESC[0]="Calls to the rewrite tool" DESC[1]="Source files used as input" @@ -32,11 +30,9 @@ DESC[2]="Application link commands" 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[6]="Rewrite failures" +DESC[7]="Rewritten source compile successes" +DESC[8]="Rewritten source compile failures" desc_len=${#DESC[@]} FINE[0]="Lines of source code" diff --git a/src/inst_frontend.cc b/src/inst_frontend.cc @@ -53,16 +53,6 @@ ends_with(std::string const &value, std::string const &suffix) return std::equal(suffix.rbegin(), suffix.rend(), value.rbegin()); } -// Returns true if value ends with suffix, false otherwise. -static bool -starts_with(std::string const &value, std::string const &prefix) -{ - if (prefix.length() > value.length()) - return false; - - return std::equal(prefix.begin(), prefix.end(), value.begin()); -} - // Copies one file to another preserving timestamps. static void copy_file(std::string const &dst_fn, std::string const &src_fn) @@ -213,20 +203,6 @@ InstrumentFrontend::instrument() return Tool.run(f.get()); } -int -InstrumentFrontend::try_compile(std::string const &variant) -{ - int ret = fork_compiler(); - - if (ret == 0) { - *m_log << "But " << variant << " succeeded!\n"; - return 0; - } - - *m_log << "And " << variant << " failed.\n"; - return ret; -} - void InstrumentFrontend::restore_original_src() { diff --git a/src/inst_frontend.h b/src/inst_frontend.h @@ -9,12 +9,11 @@ public: void process_cmdline(); int instrument(); - int try_compile(std::string const &); int fork_compiler(); + void exec_compiler(); void restore_original_src(); private: - void exec_compiler(); void save_if_srcfile(char *); void if_link_add_runtime(bool, bool); diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -133,18 +133,19 @@ main(int argc, char *argv[]) if (is_citruninst) return ret; if (ret) { + // Rewriting failed. Original source files may be in an + // inconsistent state. main.restore_original_src(); - return main.try_compile("the native compile"); + main.exec_compiler(); } ret = main.fork_compiler(); llog << "Rewritten source compile " << (ret ? "failed.\n" : "successful.\n"); - main.restore_original_src(); - if (ret == 0) - return 0; - - return main.try_compile("the unrewritten source compile"); + if (ret) + // Rewritten compile failed. Run again without modified src. + main.exec_compiler(); + return 0; }