citrun

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

commit c165d0647f9ee53908ef9cd25ab51b2428494dad
parent 967e2aea5d31a93e847e58331b435aa5b6e8b3cd
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 13 Aug 2016 17:23:20 -0600

src: remove bad constructor

Diffstat:
Msrc/inst_action.cc | 14+++++++-------
Msrc/inst_action.h | 4++--
Msrc/inst_frontend.cc | 50+++++++++++++++++++++++++-------------------------
Msrc/inst_frontend.h | 8++++----
Msrc/inst_log.cc | 11++---------
Msrc/inst_log.h | 3+--
Msrc/inst_main.cc | 2+-
7 files changed, 42 insertions(+), 50 deletions(-)

diff --git a/src/inst_action.cc b/src/inst_action.cc @@ -42,20 +42,20 @@ InstrumentAction::write_modified_src(clang::FileID const &fid) if (m_is_citruninst) { out_file += ".citrun"; - m_log << "Writing modified source to '" << out_file << "'.\n"; + *m_log << "Writing modified source to '" << out_file << "'.\n"; } std::error_code ec; llvm::raw_fd_ostream output(out_file, ec, llvm::sys::fs::F_None); if (ec.value()) { - m_log << "Error writing modified source '" << out_file + *m_log << "Error writing modified source '" << out_file << "': " << ec.message() << "\n"; return; } // Write the instrumented source file m_TheRewriter.getEditBuffer(fid).write(output); - m_log << "Modified source written successfully.\n"; + *m_log << "Modified source written successfully.\n"; } void @@ -95,12 +95,12 @@ InstrumentAction::EndSourceFileAction() << "#endif\n"; if (m_TheRewriter.InsertTextAfter(start, preamble.str())) { - m_log << "Failed to insert the instrumentation preabmle."; + *m_log << "Failed to insert the instrumentation preabmle."; return; } - m_log << "Instrumentation of '" << m_compiler_file_name << "' finished:\n"; - m_log << " " << num_lines << " Lines of source code\n"; + *m_log << "Instrumentation of '" << m_compiler_file_name << "' finished:\n"; + *m_log << " " << num_lines << " Lines of source code\n"; // // Write out statistics from the AST visitor. @@ -109,7 +109,7 @@ InstrumentAction::EndSourceFileAction() for (int i = 0; i < NCOUNTERS; ++i) { if (v.m_counters[i] == 0) continue; - m_log << " " << v.m_counters[i] << " " + *m_log << " " << v.m_counters[i] << " " << v.m_counter_descr[i] << "\n"; } diff --git a/src/inst_action.h b/src/inst_action.h @@ -30,7 +30,7 @@ private: // For each source file provided to the tool, a new FrontendAction is created. class InstrumentAction : public clang::ASTFrontendAction { public: - InstrumentAction(InstrumentLogger &log, bool citruninst, + InstrumentAction(InstrumentLogger *log, bool citruninst, std::string const &filename) : m_log(log), m_is_citruninst(citruninst), @@ -45,7 +45,7 @@ private: clang::Rewriter m_TheRewriter; RewriteASTConsumer *m_InstrumentASTConsumer; - InstrumentLogger m_log; + InstrumentLogger *m_log; bool m_is_citruninst; std::string m_compiler_file_name; }; diff --git a/src/inst_frontend.cc b/src/inst_frontend.cc @@ -34,7 +34,7 @@ static llvm::cl::OptionCategory ToolingCategory("citrun-inst options"); -CitrunInst::CitrunInst(int argc, char *argv[], InstrumentLogger &l, bool is_citruninst) : +CitrunInst::CitrunInst(int argc, char *argv[], InstrumentLogger *l, bool is_citruninst) : m_args(argv, argv + argc), m_log(l), m_is_citruninst(is_citruninst) @@ -87,7 +87,7 @@ CitrunInst::save_if_srcfile(char *arg) ends_with(arg, ".cpp") || ends_with(arg, ".cxx")) { m_source_files.push_back(arg); - m_log << "Found source file '" << arg << "'.\n"; + *m_log << "Found source file '" << arg << "'.\n"; if (m_is_citruninst) // In this mode the modified source file is written to a @@ -124,15 +124,15 @@ CitrunInst::process_cmdline() bool object_arg = false; bool compile_arg = false; - m_log << "Command line is '"; + *m_log << "Command line is '"; for (auto &arg : m_args) - m_log << arg << " "; - m_log << "'.\n"; + *m_log << arg << " "; + *m_log << "'.\n"; for (auto &arg : m_args) { if (std::strcmp(arg, "-E") == 0) { - m_log << "Preprocessor argument found\n"; + *m_log << "Preprocessor argument found\n"; exec_compiler(); } else if (std::strcmp(arg, "-o") == 0) @@ -143,28 +143,28 @@ CitrunInst::process_cmdline() save_if_srcfile(arg); } - m_log << "Object arg = " << object_arg << ", " + *m_log << "Object arg = " << object_arg << ", " << "compile arg = " << compile_arg << "\n"; if (is_link_cmd(object_arg, compile_arg)) { - m_log << "Link detected, adding '"; + *m_log << "Link detected, adding '"; #ifndef __APPLE__ // OSX always links this. m_args.push_back(const_cast<char *>("-pthread")); - m_log << m_args.back() << " "; + *m_log << m_args.back() << " "; #endif #ifdef CITRUN_COVERAGE // Needed because libcitrun.a will be instrumented with gcov. m_args.push_back(const_cast<char *>("-coverage")); #endif m_args.push_back(const_cast<char *>(STR(CITRUN_SHARE) "/libcitrun.a")); - m_log << m_args.back() << "' to command line.\n"; + *m_log << m_args.back() << "' to command line.\n"; } if (m_source_files.size() != 0) return; - m_log << "No source files found. Executing command line.\n"; + *m_log << "No source files found. Executing command line.\n"; exec_compiler(); } @@ -183,10 +183,10 @@ CitrunInst::instrument() clang_argv.insert(clang_argv.end(), m_args.begin(), m_args.end()); #if defined(__OpenBSD__) clang_argv.push_back("-I/usr/local/lib/clang/3.8.1/include"); - m_log << "Added clangtool argument '" << clang_argv.back() << "'.\n"; + *m_log << "Added clangtool argument '" << clang_argv.back() << "'.\n"; #elif defined(__APPLE__) clang_argv.push_back("-I/opt/local/libexec/llvm-3.8/lib/clang/3.8.1/include"); - m_log << "Added clangtool argument '" << clang_argv.back() << "'.\n"; + *m_log << "Added clangtool argument '" << clang_argv.back() << "'.\n"; #endif int clang_argc = clang_argv.size(); @@ -198,15 +198,15 @@ CitrunInst::instrument() clang::DiagnosticOptions diags; clang::TextDiagnosticPrinter *log; - log = new clang::TextDiagnosticPrinter(*m_log.m_output, &diags, false); - log->setPrefix(std::to_string(m_log.m_pid)); + log = new clang::TextDiagnosticPrinter(*m_log->m_output, &diags, false); + log->setPrefix(std::to_string(m_log->m_pid)); Tool.setDiagnosticConsumer(log); std::unique_ptr<InstrumentActionFactory> f = llvm::make_unique<InstrumentActionFactory>(m_log, m_is_citruninst, m_source_files); int ret = Tool.run(f.get()); - m_log << "Instrumentation " << (ret ? "failed.\n" : "successful.\n"); + *m_log << "Instrumentation " << (ret ? "failed.\n" : "successful.\n"); return ret; } @@ -217,11 +217,11 @@ CitrunInst::try_unmodified_compile() int ret = fork_compiler(); if (ret == 0) { - m_log << "But the native compile succeeded!\n"; + *m_log << "But the native compile succeeded!\n"; return 1; } - m_log << "And the native compile failed.\n"; + *m_log << "And the native compile failed.\n"; return ret; } @@ -229,7 +229,7 @@ void CitrunInst::restore_original_src() { for (auto &tmp_file : m_temp_file_map) { - m_log << "Restored '" << tmp_file.first << "'.\n"; + *m_log << "Restored '" << tmp_file.first << "'.\n"; copy_file(tmp_file.first, tmp_file.second); unlink(tmp_file.second.c_str()); @@ -240,10 +240,10 @@ void CitrunInst::exec_compiler() { // XXX: Need to destroy log here. - m_log.m_output->flush(); + m_log->m_output->flush(); if (m_is_citruninst) { - m_log << "Running as citrun-inst, not re-exec()'ing\n"; + *m_log << "Running as citrun-inst, not re-exec()'ing\n"; exit(0); } @@ -256,7 +256,7 @@ int CitrunInst::fork_compiler() { // Otherwise we'll get two copies of buffers after fork(). - m_log.m_output->flush(); + m_log->m_output->flush(); pid_t child_pid; if ((child_pid = fork()) < 0) @@ -266,7 +266,7 @@ CitrunInst::fork_compiler() // In child. exec_compiler(); - m_log << "Forked '" << m_args[0] << "' " + *m_log << "Forked '" << m_args[0] << "' " << "pid is '" << child_pid << "'.\n"; int status; @@ -278,14 +278,14 @@ CitrunInst::fork_compiler() if (WIFEXITED(status)) exit = WEXITSTATUS(status); - m_log << "'" << child_pid << "' exited " << exit << ".\n"; + *m_log << "'" << child_pid << "' exited " << exit << ".\n"; return exit; } int CitrunInst::compile_modified() { - m_log << "Running native compiler on modified source code.\n"; + *m_log << "Running native compiler on modified source code.\n"; int ret = fork_compiler(); restore_original_src(); diff --git a/src/inst_frontend.h b/src/inst_frontend.h @@ -5,7 +5,7 @@ class CitrunInst { public: - CitrunInst(int, char *argv[], InstrumentLogger &, bool); + CitrunInst(int, char *argv[], InstrumentLogger *, bool); void process_cmdline(); int instrument(); @@ -20,7 +20,7 @@ private: bool is_link_cmd(bool, bool); std::vector<char *> m_args; - InstrumentLogger m_log; + InstrumentLogger *m_log; bool m_is_citruninst; std::vector<std::string> m_source_files; std::map<std::string, std::string> m_temp_file_map; @@ -31,7 +31,7 @@ private: // class InstrumentActionFactory : public clang::tooling::FrontendActionFactory { public: - InstrumentActionFactory(InstrumentLogger &log, bool citruninst, + InstrumentActionFactory(InstrumentLogger *log, bool citruninst, std::vector<std::string> const &src_files) : m_log(log), m_is_citruninst(citruninst), @@ -44,7 +44,7 @@ public: } private: - InstrumentLogger m_log; + InstrumentLogger *m_log; bool m_is_citruninst; std::vector<std::string> m_source_files; int m_i; diff --git a/src/inst_log.cc b/src/inst_log.cc @@ -6,14 +6,14 @@ InstrumentLogger::InstrumentLogger(const bool &is_citruninst) : m_pid(getpid()), m_needs_prefix(true), - m_delete(true) + m_delete(false) { if (is_citruninst) { m_output = &llvm::outs(); - m_delete = false; } else { std::error_code ec; m_output = new llvm::raw_fd_ostream("citrun.log", ec, llvm::sys::fs::F_Append); + m_delete = true; if (ec.value()) { warnx("citrun.log: %s", ec.message().c_str()); @@ -23,13 +23,6 @@ InstrumentLogger::InstrumentLogger(const bool &is_citruninst) : } } -InstrumentLogger::InstrumentLogger(InstrumentLogger &o) : - m_pid(o.m_pid), - m_output(o.m_output), - m_needs_prefix(o.m_needs_prefix), - m_delete(false) -{} - InstrumentLogger::~InstrumentLogger() { if (m_delete) diff --git a/src/inst_log.h b/src/inst_log.h @@ -7,7 +7,6 @@ class InstrumentLogger { public: InstrumentLogger(const bool &); - InstrumentLogger(InstrumentLogger &o); ~InstrumentLogger(); template <typename T> @@ -21,12 +20,12 @@ public: pid_t m_pid; llvm::raw_ostream *m_output; - bool m_needs_prefix; private: void print_prefix(); void check_newline(const std::string &); + bool m_needs_prefix; bool m_delete; }; diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -115,7 +115,7 @@ main(int argc, char *argv[]) // We were not called as citrun-inst and path cleaning failed. return 1; - CitrunInst main(argc, argv, llog, is_citruninst); + CitrunInst main(argc, argv, &llog, is_citruninst); main.process_cmdline(); int ret = main.instrument();