Created
May 17, 2013 15:20
-
-
Save anonymous/5599765 to your computer and use it in GitHub Desktop.
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
#define TRACEPOINT_DEFINE | |
#define TRACEPOINT_CREATE_PROBES | |
#include "ust_test.h" | |
void tptest(void) | |
{ | |
tracepoint(ust_test, tptest); | |
} |
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
all: dyntp.so mutator mutatee | |
dyntp.so: dyntp.o | |
gcc -shared -fPIC -DPIC $^ -ldl -llttng-ust -O2 -o $@ | |
dyntp.o: dyntp.c ust_test.h | |
gcc -I. -fno-strict-aliasing -Wall -g -O2 -c $< -fPIC -DPIC -o $@ | |
mutator: mutator.o | |
g++ $^ -L/usr/lib/dyninst -ldyninstAPI -o $@ | |
mutatee: mutatee.o | |
gcc $^ -std=gnu99 -lrt -o $@ | |
mutatee.o: mutatee.c | |
gcc $< -std=gnu99 -c -o $@ | |
.PHONY: clean | |
clean: | |
rm -f *.o *.so mutator mutatee |
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
#include <stdio.h> | |
void foo() { | |
printf("I am foo()\n"); | |
return; | |
} | |
void bar() { | |
printf("I am bar()\n"); | |
return; | |
} | |
int main() | |
{ | |
printf("Hello World!\n"); | |
foo(); | |
return 0; | |
} |
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
#include <dyninst/BPatch.h> | |
#include <dyninst/BPatch_point.h> | |
#include <dyninst/BPatch_function.h> | |
#include <vector> | |
int main (int argc, const char* argv[]) { | |
BPatch bpatch; | |
BPatch_process *proc = bpatch.processCreate(argv[2], argv + 3); | |
//bpatch.setTrampRecursive(true); | |
//bpatch.setSaveFPR(false); | |
//bpatch.setInstrStackFrames(false); | |
//BPatch_process *proc = bpatch.processAttach(argv[1], atoi(argv[2])); | |
BPatch_object *ipa = proc->loadLibrary(argv[1]); | |
BPatch_image *image = proc->getImage(); | |
std::vector<BPatch_function *> foo_fns, ipa_fns; | |
image->findFunction("foo", foo_fns); | |
image->findFunction("tptest", ipa_fns); | |
std::vector<BPatch_snippet*> args; | |
BPatch_funcCallExpr call_ipa(*ipa_fns[0], args); | |
proc->insertSnippet(call_ipa, (foo_fns[0]->findPoint(BPatch_entry))[0]); | |
proc->continueExecution(); | |
while (!proc->isTerminated()) { | |
bpatch.waitForStatusChange(); | |
} | |
return 0; | |
} |
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
#!/bin/sh | |
lttng create; lttng enable-event -a -u; lttng start | |
DYNINSTAPI_RT_LIB=/usr/lib/dyninst/libdyninstAPI_RT.so ./mutator ./dyntp.so ./mutatee | |
lttng stop | |
sleep 1 | |
lttng view |
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
#undef TRACEPOINT_PROVIDER | |
#define TRACEPOINT_PROVIDER ust_test | |
#if !defined(_TRACEPOINT_UST_TEST_H) || defined(TRACEPOINT_HEADER_MULTI_READ) | |
#define _TRACEPOINT_UST_TEST_H | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
#include <lttng/tracepoint.h> | |
TRACEPOINT_EVENT(ust_test, tptest, | |
TP_ARGS(), | |
TP_FIELDS() | |
) | |
#endif /* _TRACEPOINT_UST_TEST_H */ | |
#undef TRACEPOINT_INCLUDE | |
#define TRACEPOINT_INCLUDE "./ust_test.h" | |
/* This part must be outside ifdef protection */ | |
#include <lttng/tracepoint-event.h> | |
#ifdef __cplusplus | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment