Created
May 17, 2013 21:16
-
-
Save tuxology/5602019 to your computer and use it in GitHub Desktop.
Tracepoint to get integer values from mutatee + modifications for x86_64 libs
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); | |
} | |
void tpint(int a){ | |
tracepoint(ust_test, int_1, a); | |
} |
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 -O0 -o $@ | |
dyntp.o: dyntp.c ust_test.h | |
gcc -I. -fno-strict-aliasing -Wall -g -O0 -c $< -fPIC -DPIC -o $@ | |
mutator: mutator.o | |
g++ $^ -L/usr/lib64/dyninst -ldyninstAPI -o $@ | |
mutatee: mutatee.o | |
gcc $^ -std=gnu99 -lrt -O0 -o $@ | |
mutatee.o: mutatee.c | |
gcc $< -std=gnu99 -c -O0 -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> | |
int a=42; | |
void foo() { | |
printf("I am foo()\n"); | |
return; | |
} | |
void bar() { | |
printf("I am bar()\n"); | |
return; | |
} | |
int main() | |
{ | |
printf("Hello World!\n"); | |
foo(); | |
bar(); | |
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, ipb_fns, bar_fns; | |
image->findFunction("foo", foo_fns); | |
image->findFunction("bar", bar_fns); | |
image->findFunction("tptest", ipa_fns); | |
image->findFunction("tpint", ipb_fns); | |
//get var from the mutator | |
BPatch_variableExpr *a; | |
a=image->findVariable("a"); | |
std::vector<BPatch_snippet*> args; | |
BPatch_funcCallExpr call_ipa(*ipa_fns[0], args); | |
proc->insertSnippet(call_ipa, (foo_fns[0]->findPoint(BPatch_entry))[0]); | |
std::vector<BPatch_snippet*> tpintArgs; | |
BPatch_snippet *var = a; | |
tpintArgs.push_back(var); | |
BPatch_funcCallExpr call_ipb(*ipb_fns[0], tpintArgs); | |
proc->insertSnippet(call_ipb, (bar_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/bash | |
lttng create; lttng enable-event -a -u; lttng start | |
DYNINSTAPI_RT_LIB=/usr/lib64/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() | |
) | |
TRACEPOINT_EVENT( | |
ust_test, | |
int_1, | |
TP_ARGS(double, int_1), | |
TP_FIELDS(ctf_float(double, integer_val, int_1)) | |
) | |
#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