-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
505 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
#!/bin/sh -x | ||
|
||
. `dirname $0`/xtools.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
//! @file DTraceLogger.cc Definition of @ref DTraceLogger. | ||
/* | ||
* Copyright (c) 2017 Brian Kidney | ||
* All rights reserved. | ||
* | ||
* This software was developed by BAE Systems, the University of Cambridge | ||
* Computer Laboratory, and Memorial University under DARPA/AFRL contract | ||
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing | ||
* (TC) research program. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
* SUCH DAMAGE. | ||
*/ | ||
|
||
#include "DTraceLogger.hh" | ||
|
||
#include <algorithm> | ||
|
||
#include <llvm/IR/Instructions.h> | ||
#include <llvm/IR/Module.h> | ||
#include <llvm/IR/TypeBuilder.h> | ||
#include <llvm/Support/raw_ostream.h> | ||
|
||
using namespace loom; | ||
using namespace llvm; | ||
using std::vector; | ||
|
||
DTraceLogger::DTraceLogger(llvm::Module& Mod) | ||
: Logger(Mod){ }; | ||
|
||
Value* DTraceLogger::ConvertValueToPtr(IRBuilder<>& B, LLVMContext& Ctx, Value* V, Type* param_t) | ||
{ | ||
Type *T = V->getType(); | ||
if (T->isPointerTy()) { | ||
return B.CreatePtrToInt(V, param_t); | ||
} else if (T->isIntegerTy()) { | ||
return B.CreateSExt(V, param_t); | ||
} else if (T->isDoubleTy()) { | ||
return B.CreateBitCast(V, TypeBuilder<int64_t, false>::get(Ctx)); | ||
} else if (T->isFloatTy()) { | ||
auto *BC = B.CreateBitCast(V, TypeBuilder<int32_t, false>::get(Ctx)); | ||
return B.CreateSExt(BC, param_t); | ||
} | ||
return ConstantInt::get(param_t, 0); | ||
} | ||
|
||
|
||
|
||
Value* DTraceLogger::Log(Instruction *I, ArrayRef<Value*> Values, | ||
StringRef Name, StringRef Descrip, | ||
Metadata Metadata, std::vector<Transform> Transforms, | ||
bool /* SuppressUniqueness */) { | ||
|
||
if (not Metadata.isValid()) | ||
errs() << "Warning: Dtrace Logger requires the use of Metadata to function properly."; | ||
|
||
IRBuilder<> B(I); | ||
|
||
LLVMContext &Ctx = Mod.getContext(); | ||
Type* id_t = TypeBuilder<unsigned int, false>::get(Ctx); | ||
Type* param_t = TypeBuilder<uintptr_t, false>::get(Ctx); | ||
|
||
size_t n_args = std::min(Values.size(), 5ul); | ||
|
||
std::vector<Type*> params; | ||
for (int i = 0; i < n_args + 1; i++) { | ||
params.push_back(param_t); | ||
} | ||
|
||
auto *FT = FunctionType::get( TypeBuilder<int, false>::get(Ctx), params, false); | ||
|
||
Constant *F = Mod.getOrInsertFunction("dt_probe", FT); | ||
|
||
|
||
Value* args[6]; | ||
args[0] = B.CreateSExt(ConstantInt::get(id_t, Metadata.Id), param_t);; | ||
for (int i = 0; i < n_args; i++) | ||
{ | ||
Value *ptr; | ||
|
||
Transform Tf; | ||
for (auto t: Transforms) { | ||
if (t.Arg == i) | ||
Tf = t; | ||
break; | ||
} | ||
|
||
if (Tf.isValid()) { | ||
ptr = ConvertValueToPtr(B, Ctx, Tf.CreateTransform(I, Mod, Values[i]), param_t); | ||
} else { | ||
ptr = ConvertValueToPtr(B, Ctx, Values[i], param_t); | ||
} | ||
|
||
args[i + 1] = ptr; | ||
} | ||
|
||
ArrayRef<Value*> argsRef(args, n_args + 1); | ||
|
||
return B.CreateCall(F, argsRef); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//! @file DTraceLogger.hh Declaration of @ref DTraceLogger. | ||
/* | ||
* Copyright (c) 2017 Brian Kidney | ||
* All rights reserved. | ||
* | ||
* This software was developed by BAE Systems, the University of Cambridge | ||
* Computer Laboratory, and Memorial University under DARPA/AFRL contract | ||
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing | ||
* (TC) research program. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
* SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef DTRACE_LOGGER_H_ | ||
#define DTRACE_LOGGER_H_ | ||
|
||
#include "Logger.hh" | ||
|
||
namespace loom { | ||
|
||
class Serializer; | ||
|
||
/** | ||
* A logging technique that writes values to the DTrace framework using | ||
* Userland Statically Defined Traces (USDT). libusdt is used to create probes | ||
* at runtime. | ||
*/ | ||
class DTraceLogger : public loom::Logger { | ||
public: | ||
DTraceLogger(llvm::Module& Mod); | ||
|
||
|
||
virtual llvm::Value* Log(llvm::Instruction *I, llvm::ArrayRef<llvm::Value*> Values, | ||
llvm::StringRef Name, llvm::StringRef Descrip, | ||
Metadata Metadata, std::vector<Transform> Transforms, | ||
bool /* SuppressUniqueness */) override; | ||
private: | ||
llvm::Value* ConvertValueToPtr(llvm::IRBuilder<>&, llvm::LLVMContext&, llvm::Value*, llvm::Type*); | ||
|
||
}; | ||
|
||
} // namespace loom | ||
|
||
#endif // !DTRACE_LOGGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.