diff options
Diffstat (limited to 'lib/Core')
-rw-r--r-- | lib/Core/Common.cpp | 72 | ||||
-rw-r--r-- | lib/Core/Executor.cpp | 38 | ||||
-rw-r--r-- | lib/Core/Executor.h | 4 | ||||
-rw-r--r-- | lib/Core/ExecutorUtil.cpp | 3 | ||||
-rw-r--r-- | lib/Core/ExternalDispatcher.cpp | 9 | ||||
-rw-r--r-- | lib/Core/Searcher.cpp | 8 | ||||
-rw-r--r-- | lib/Core/StatsTracker.cpp | 23 |
7 files changed, 112 insertions, 45 deletions
diff --git a/lib/Core/Common.cpp b/lib/Core/Common.cpp index 575a1f1b..c58e121a 100644 --- a/lib/Core/Common.cpp +++ b/lib/Core/Common.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "Common.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" #include <stdlib.h> #include <stdio.h> @@ -22,16 +24,72 @@ using namespace klee; FILE* klee::klee_warning_file = NULL; FILE* klee::klee_message_file = NULL; -static void klee_vfmessage(FILE *fp, const char *pfx, const char *msg, +static const char* warningPrefix = "WARNING"; +static const char* warningOncePrefix = "WARNING ONCE"; +static const char* errorPrefix = "ERROR"; +static const char* notePrefix = "NOTE"; + +static bool shouldSetColor(const char* pfx, const char* msg, const char* prefixToSearchFor) +{ + if (pfx && strcmp(pfx, prefixToSearchFor) == 0) + return true; + + if (llvm::StringRef(msg).startswith(prefixToSearchFor)) + return true; + + return false; +} + +static void klee_vfmessage(FILE *fp, const char *pfx, const char *msg, va_list ap) { if (!fp) return; - fprintf(fp, "KLEE: "); - if (pfx) fprintf(fp, "%s: ", pfx); + llvm::raw_fd_ostream fdos(fileno(fp), /*shouldClose=*/false, /*unbuffered=*/ true); + bool modifyConsoleColor = fdos.is_displayed() && (fp == stderr); + + if (modifyConsoleColor) { + + // Warnings + if (shouldSetColor(pfx, msg, warningPrefix)) + fdos.changeColor(llvm::raw_ostream::MAGENTA, + /*bold=*/ false, + /*bg=*/ false); + + // Once warning + if (shouldSetColor(pfx, msg, warningOncePrefix)) + fdos.changeColor(llvm::raw_ostream::MAGENTA, + /*bold=*/ true, + /*bg=*/ false); + + // Errors + if (shouldSetColor(pfx, msg, errorPrefix)) + fdos.changeColor(llvm::raw_ostream::RED, + /*bold=*/ true, + /*bg=*/ false); + + // Notes + if (shouldSetColor(pfx, msg, notePrefix)) + fdos.changeColor(llvm::raw_ostream::WHITE, + /*bold=*/ true, + /*bg=*/ false); + + } + + fdos << "KLEE: "; + if (pfx) fdos << pfx << ": "; + + // FIXME: Can't use fdos here because we need to print + // a variable number of arguments and do substitution vfprintf(fp, msg, ap); - fprintf(fp, "\n"); fflush(fp); + + fdos << "\n"; + + if (modifyConsoleColor) + fdos.resetColor(); + + fdos.flush(); } /* Prints a message/warning. @@ -73,7 +131,7 @@ void klee::klee_message_to_file(const char *msg, ...) { void klee::klee_error(const char *msg, ...) { va_list ap; va_start(ap, msg); - klee_vmessage("ERROR", false, msg, ap); + klee_vmessage(errorPrefix, false, msg, ap); va_end(ap); exit(1); } @@ -81,7 +139,7 @@ void klee::klee_error(const char *msg, ...) { void klee::klee_warning(const char *msg, ...) { va_list ap; va_start(ap, msg); - klee_vmessage("WARNING", false, msg, ap); + klee_vmessage(warningPrefix, false, msg, ap); va_end(ap); } @@ -104,7 +162,7 @@ void klee::klee_warning_once(const void *id, const char *msg, ...) { va_list ap; va_start(ap, msg); - klee_vmessage("WARNING ONCE", false, msg, ap); + klee_vmessage(warningOncePrefix, false, msg, ap); va_end(ap); } } diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index d2978642..314e5b82 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -78,12 +78,17 @@ #endif #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/CallSite.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <cassert> #include <algorithm> #include <iomanip> @@ -139,10 +144,6 @@ namespace { cl::init(false)); cl::opt<bool> - UseAsmAddresses("use-asm-addresses", - cl::init(false)); - - cl::opt<bool> RandomizeFork("randomize-fork", cl::init(false), cl::desc("Randomly swap the true and false states on a fork (default=off)")); @@ -580,32 +581,9 @@ void Executor::initializeGlobals(ExecutionState &state) { } else { LLVM_TYPE_Q Type *ty = i->getType()->getElementType(); uint64_t size = kmodule->targetData->getTypeStoreSize(ty); - MemoryObject *mo = 0; - -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 3) - if (UseAsmAddresses && i->getName()[0]=='\01') { -#else - if (UseAsmAddresses && !i->getName().empty()) { -#endif - char *end; -#if LLVM_VERSION_CODE < LLVM_VERSION(3, 3) - uint64_t address = ::strtoll(i->getName().str().c_str()+1, &end, 0); -#else - uint64_t address = ::strtoll(i->getName().str().c_str(), &end, 0); -#endif - - if (end && *end == '\0') { - klee_message("NOTE: allocated global at asm specified address: %#08llx" - " (%llu bytes)", - (long long) address, (unsigned long long) size); - mo = memory->allocateFixed(address, size, &*i); - mo->isUserSpecified = true; // XXX hack; - } - } - + MemoryObject *mo = memory->allocate(size, false, true, &*i); if (!mo) - mo = memory->allocate(size, false, true, &*i); - assert(mo && "out of memory"); + llvm::report_fatal_error("out of memory"); ObjectState *os = bindObjectInState(state, mo, false); globalObjects.insert(std::make_pair(i, mo)); globalAddresses.insert(std::make_pair(i, mo->getBaseExpr())); diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h index 7d82332c..523b3648 100644 --- a/lib/Core/Executor.h +++ b/lib/Core/Executor.h @@ -20,7 +20,9 @@ #include "klee/Internal/Module/Cell.h" #include "klee/Internal/Module/KInstruction.h" #include "klee/Internal/Module/KModule.h" -#include "llvm/Support/CallSite.h" + +#include "llvm/ADT/Twine.h" + #include <vector> #include <string> #include <map> diff --git a/lib/Core/ExecutorUtil.cpp b/lib/Core/ExecutorUtil.cpp index f6b3dd5e..56f18e6b 100644 --- a/lib/Core/ExecutorUtil.cpp +++ b/lib/Core/ExecutorUtil.cpp @@ -38,9 +38,6 @@ #endif #endif -#include "llvm/Support/CallSite.h" - - #include <cassert> using namespace klee; diff --git a/lib/Core/ExternalDispatcher.cpp b/lib/Core/ExternalDispatcher.cpp index 4c1e2b86..5f9f8dc6 100644 --- a/lib/Core/ExternalDispatcher.cpp +++ b/lib/Core/ExternalDispatcher.cpp @@ -32,14 +32,21 @@ #endif #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/GenericValue.h" -#include "llvm/Support/CallSite.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/raw_ostream.h" + #if LLVM_VERSION_CODE < LLVM_VERSION(3, 0) #include "llvm/Target/TargetSelect.h" #else #include "llvm/Support/TargetSelect.h" #endif + +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <setjmp.h> #include <signal.h> diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp index 2610f17e..e33d2a56 100644 --- a/lib/Core/Searcher.cpp +++ b/lib/Core/Searcher.cpp @@ -34,10 +34,14 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #endif -#include "llvm/Support/CallSite.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/CommandLine.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#else +#include "llvm/IR/CallSite.h" +#endif + #include <cassert> #include <fstream> #include <climits> diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index e664d1ae..0e564fe5 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -52,11 +52,18 @@ #include "llvm/Type.h" #endif #include "llvm/Support/CommandLine.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/Process.h" #include "llvm/Support/Path.h" #include "llvm/Support/FileSystem.h" +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) +#include "llvm/Support/CallSite.h" +#include "llvm/Support/CFG.h" +#else +#include "llvm/IR/CallSite.h" +#include "llvm/IR/CFG.h" +#endif + #include <fstream> #include <unistd.h> @@ -190,8 +197,13 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename, SmallString<128> current(objectFilename); if(sys::fs::make_absolute(current)) { bool exists = false; + +#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5) error_code ec = sys::fs::exists(current.str(), exists); if (ec == errc::success && exists) { +#else + if (!sys::fs::exists(current.str(), exists)) { +#endif objectFilename = current.c_str(); } } @@ -501,6 +513,15 @@ void StatsTracker::writeIStats() { for (Module::iterator fnIt = m->begin(), fn_ie = m->end(); fnIt != fn_ie; ++fnIt) { if (!fnIt->isDeclaration()) { + // Always try to write the filename before the function name, as otherwise + // KCachegrind can create two entries for the function, one with an + // unnamed file and one without. + const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fnIt); + if (ii.file != sourceFile) { + of << "fl=" << ii.file << "\n"; + sourceFile = ii.file; + } + of << "fn=" << fnIt->getName().str() << "\n"; for (Function::iterator bbIt = fnIt->begin(), bb_ie = fnIt->end(); bbIt != bb_ie; ++bbIt) { |