commit e2c8e871cd9e6f67888b26d76d51b16fc7166643
parent ebc30752442320268093f74c7ecf7f46ddd41549
Author: Kyle Milz <kyle@0x30.net>
Date: Fri, 12 Aug 2016 23:31:25 -0600
src: make logging object locally scoped
Diffstat:
2 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/src/inst_log.h b/src/inst_log.h
@@ -7,25 +7,14 @@
class InstrumentLogger {
public:
- InstrumentLogger() :
+ InstrumentLogger(const bool &is_citruninst) :
m_pid(getpid()),
m_needs_prefix(true),
m_delete(true)
- {};
- InstrumentLogger(InstrumentLogger &o) :
- m_pid(o.m_pid),
- m_output(o.m_output),
- m_needs_prefix(o.m_needs_prefix),
- m_delete(false)
- {}
- ~InstrumentLogger() { if (m_delete) delete m_output; };
-
- void set_output(const bool &is_citruninst) {
-
+ {
if (is_citruninst) {
m_output = &llvm::outs();
m_delete = false;
- return;
} else {
std::error_code ec;
m_output = new llvm::raw_fd_ostream("citrun.log", ec, llvm::sys::fs::F_Append);
@@ -34,10 +23,16 @@ public:
warnx("citrun.log: %s", ec.message().c_str());
m_output = &llvm::nulls();
m_delete = false;
- return;
}
}
};
+ InstrumentLogger(InstrumentLogger &o) :
+ m_pid(o.m_pid),
+ m_output(o.m_output),
+ m_needs_prefix(o.m_needs_prefix),
+ m_delete(false)
+ {}
+ ~InstrumentLogger() { if (m_delete) delete m_output; };
template <typename T>
friend InstrumentLogger& operator<<(InstrumentLogger& out, const T &rhs)
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -39,10 +39,8 @@
static llvm::cl::OptionCategory ToolingCategory("citrun-inst options");
-InstrumentLogger llog;
-
int
-clean_PATH()
+clean_PATH(InstrumentLogger &llog)
{
char *path;
if ((path = std::getenv("PATH")) == NULL) {
@@ -86,7 +84,7 @@ clean_PATH()
}
void
-print_toolinfo(const char *argv0)
+print_toolinfo(InstrumentLogger &llog, const char *argv0)
{
struct utsname utsname;
@@ -116,9 +114,8 @@ main(int argc, char *argv[])
if (std::strcmp(base_name, "citrun-inst") == 0)
is_citruninst = true;
- llog.set_output(is_citruninst);
-
- print_toolinfo(argv[0]);
+ InstrumentLogger llog(is_citruninst);
+ print_toolinfo(llog, argv[0]);
if (std::strcmp(base_name, argv[0]) != 0) {
llog << "Changing '" << argv[0] << "' to '" << base_name << "'.\n";
@@ -127,7 +124,7 @@ main(int argc, char *argv[])
setprogname("citrun-inst");
- if (is_citruninst == false && clean_PATH() != 0)
+ if (is_citruninst == false && clean_PATH(llog) != 0)
// We were not called as citrun-inst and path cleaning failed.
return 1;