30 #define DEBUG_TYPE "oprofile-wrapper"
45 WriteNativeCodeFunc(0),
46 WriteDebugLineInfoFunc(0),
47 UnloadNativeCodeFunc(0),
50 IsOProfileRunningFunc(0),
54 bool OProfileWrapper::initialize() {
56 using namespace llvm::sys;
61 return OpenAgentFunc != 0;
66 if (!isOProfileRunning()) {
67 DEBUG(
dbgs() <<
"OProfile daemon is not detected.\n");
74 <<
"OProfile connector library libopagent.so could not be loaded: "
79 OpenAgentFunc = (op_open_agent_ptr_t)(
intptr_t)
81 CloseAgentFunc = (op_close_agent_ptr_t)(
intptr_t)
83 WriteNativeCodeFunc = (op_write_native_code_ptr_t)(
intptr_t)
85 WriteDebugLineInfoFunc = (op_write_debug_line_info_ptr_t)(
intptr_t)
87 UnloadNativeCodeFunc = (op_unload_native_code_ptr_t)(
intptr_t)
89 MajorVersionFunc = (op_major_version_ptr_t)(
intptr_t)
91 MinorVersionFunc = (op_major_version_ptr_t)(
intptr_t)
97 || !WriteNativeCodeFunc
98 || !WriteDebugLineInfoFunc
99 || !UnloadNativeCodeFunc) {
102 WriteNativeCodeFunc = 0;
103 WriteDebugLineInfoFunc = 0;
104 UnloadNativeCodeFunc = 0;
111 bool OProfileWrapper::isOProfileRunning() {
112 if (IsOProfileRunningFunc != 0)
113 return IsOProfileRunningFunc();
114 return checkForOProfileProcEntry();
117 bool OProfileWrapper::checkForOProfileProcEntry() {
120 ProcDir = opendir(
"/proc");
125 struct dirent* Entry;
126 while (0 != (Entry = readdir(ProcDir))) {
127 if (Entry->d_type == DT_DIR) {
134 int CmdLineFD = open(CmdLineFName.
c_str(), S_IRUSR);
135 if (CmdLineFD != -1) {
136 char ExeName[PATH_MAX+1];
140 ssize_t NumRead =
read(CmdLineFD, ExeName, PATH_MAX+1);
144 if (ExeName[0] !=
'/') {
149 while (Idx < NumRead-1 && ExeName[Idx] != 0) {
158 if (ExeName[Idx] ==
'/') {
159 BaseName = ExeName + Idx + 1;
166 if (BaseName != 0 && (!
strcmp(
"oprofiled", BaseName) ||
167 !
strcmp(
"operf", BaseName))) {
185 if (OpenAgentFunc != 0) {
186 Agent = OpenAgentFunc();
198 if (Agent && CloseAgentFunc) {
199 ret = CloseAgentFunc(Agent);
214 const unsigned int Size) {
218 if (Agent && WriteNativeCodeFunc)
219 return WriteNativeCodeFunc(Agent, Name, Addr, Code, Size);
227 struct debug_line_info
const* Info) {
231 if (Agent && WriteDebugLineInfoFunc)
232 return WriteDebugLineInfoFunc(Agent, Code, NumEntries, Info);
241 if (Agent && MajorVersionFunc)
242 return MajorVersionFunc();
251 if (Agent && MinorVersionFunc)
252 return MinorVersionFunc();
261 if (Agent && UnloadNativeCodeFunc)
262 return UnloadNativeCodeFunc(Agent, Addr);
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName...
value_type read(const void *memory)
Read a value of a particular endianness from memory.
A raw_ostream that writes to an SmallVector or SmallString.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with strcmp
int op_write_debug_line_info(void const *code, size_t num_entries, struct debug_line_info const *info)
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
Function Alias Analysis false
Instances of this class acquire a given Mutex Lock when constructed and hold that lock until destruct...
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 - Initialize the set of available library functions based on the specified target triple...
int op_write_native_code(const char *name, uint64_t addr, void const *code, const unsigned int size)
int op_unload_native_code(uint64_t addr)