17 #include "llvm/Config/config.h" 35 #define DEBUG_TYPE "oprofile-jit-event-listener" 40 std::unique_ptr<OProfileWrapper>
Wrapper;
43 std::map<ObjectKey, OwningBinary<ObjectFile>> DebugObjects;
46 OProfileJITEventListener(std::unique_ptr<OProfileWrapper> LibraryWrapper)
47 :
Wrapper(std::move(LibraryWrapper)) {
51 ~OProfileJITEventListener();
56 void notifyFreeingObject(ObjectKey Key)
override;
60 if (!
Wrapper->op_open_agent()) {
62 LLVM_DEBUG(
dbgs() <<
"Failed to connect to OProfile agent: " << err_str
69 OProfileJITEventListener::~OProfileJITEventListener() {
70 if (
Wrapper->isAgentAvailable()) {
71 if (
Wrapper->op_close_agent() == -1) {
81 void OProfileJITEventListener::notifyObjectLoaded(
84 if (!
Wrapper->isAgentAvailable()) {
105 uint64_t Addr = *AddrOrErr;
106 uint64_t
Size =
P.second;
108 if (
Wrapper->op_write_native_code(Name.
data(), Addr, (
void *)Addr, Size) ==
110 LLVM_DEBUG(
dbgs() <<
"Failed to tell OProfile about native function " 111 << Name <<
" at [" << (
void *)Addr <<
"-" 112 << ((
char *)Addr + Size) <<
"]\n");
116 DILineInfoTable Lines = Context->getLineInfoForAddressRange(Addr, Size);
118 size_t num_entries = Lines.
size();
119 struct debug_line_info *debug_line;
120 debug_line = (
struct debug_line_info *)calloc(
121 num_entries,
sizeof(
struct debug_line_info));
123 for (
auto& It : Lines) {
124 debug_line[i].vma = (
unsigned long)It.first;
125 debug_line[i].lineno = It.second.Line;
126 debug_line[i].filename =
127 const_cast<char *>(Lines.front().second.FileName.c_str());
131 if (
Wrapper->op_write_debug_line_info((
void *)Addr, num_entries,
133 LLVM_DEBUG(
dbgs() <<
"Failed to tell OProfiler about debug object at [" 134 << (
void *)Addr <<
"-" << ((
char *)Addr + Size)
140 DebugObjects[
Key] = std::move(DebugObjOwner);
143 void OProfileJITEventListener::notifyFreeingObject(ObjectKey Key) {
144 if (
Wrapper->isAgentAvailable()) {
148 if (DebugObjects.find(Key) == DebugObjects.end())
161 uint64_t Addr = *AddrOrErr;
163 if (
Wrapper->op_unload_native_code(Addr) == -1) {
166 <<
"Failed to tell OProfile about unload of native function at " 167 << (
void *)Addr <<
"\n");
174 DebugObjects.erase(Key);
181 return new OProfileJITEventListener(llvm::make_unique<OProfileWrapper>());
Information about the loaded object.
This class represents lattice values for constants.
Expected< StringRef > getName() const
JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...
This class is the base class for all object file types.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
virtual basic_symbol_iterator symbol_begin() const =0
amdgpu Simplify well known AMD library false Value Value const Twine & Name
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
std::string StrError()
Returns a string representation of the errno value, using whatever thread-safe variant of strerror() ...
LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)
Tagged union holding either a T or a Error.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual basic_symbol_iterator symbol_end() const =0
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, const LoadedObjectInfo *L=nullptr, function_ref< ErrorPolicy(Error)> HandleError=defaultErrorHandler, std::string DWPName="")
virtual object::OwningBinary< object::ObjectFile > getObjectForDebug(const object::ObjectFile &Obj) const =0
Expected< SymbolRef::Type > getType() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringRef > StandardNames)
Initialize the set of available library functions based on the specified target triple.
std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)
This is a value type class that represents a single symbol in the list of symbols in the object file...
LLVMAttributeRef wrap(Attribute Attr)
struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef
StringRef - Represent a constant reference to a string, i.e.
static JITEventListener * createOProfileJITEventListener()