citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 661ba4e7760ab74fdd6dfbe8de21d95d6cb211a0
parent 8bfe2afb2f95caaa25e3816f6a2cf5e35192152b
Author: kyle <kyle@getaddrinfo.net>
Date:   Thu, 29 Oct 2015 02:31:25 -0600

instrument: hook up runtime to instrumented code

Diffstat:
Minstrument/instrument.cpp | 8+++++---
Mruntime/runtime.c | 6+++++-
Mtests/fibonacci/instrumented.c | 3++-
Mtests/hello_world/instrumented.c | 3++-
Mtests/if_statement/instrumented.c | 3++-
Mtests/while_loops/instrumented.c | 3++-
6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/instrument/instrument.cpp b/instrument/instrument.cpp @@ -164,9 +164,11 @@ public: SourceLocation start = sm.getLocForStartOfFile(main_fid); std::stringstream ss; - // This isn't the correct size but will always be sufficient - ss << "static unsigned int lines[" << sm.getFileIDSize(main_fid) - << "];\n"; + // This isn't the number of lines but rather bytes + int file_bytes = sm.getFileIDSize(main_fid); + ss << "unsigned int lines[" << file_bytes << "];" + << std::endl; + ss << "int size = " << file_bytes << ";" << std::endl; TheRewriter.InsertTextAfter(start, ss.str()); // Now emit the rewritten buffer. diff --git a/runtime/runtime.c b/runtime/runtime.c @@ -1,10 +1,14 @@ #include <pthread.h> #include <stdio.h> +/* these symbols are guaranteed to exist because of instrumentation */ +extern unsigned int lines[]; +extern int size; + void * control_thread(void *arg) { - // printf("control thread alive!\n"); + // printf("control thread says %i bytes!\n", size); } __attribute__((constructor)) diff --git a/tests/fibonacci/instrumented.c b/tests/fibonacci/instrumented.c @@ -1,4 +1,5 @@ -static unsigned int lines[512]; +unsigned int lines[512]; +int size = 512; #include <err.h> #include <stdio.h> #include <stdlib.h> diff --git a/tests/hello_world/instrumented.c b/tests/hello_world/instrumented.c @@ -1,4 +1,5 @@ -static unsigned int lines[77]; +unsigned int lines[77]; +int size = 77; #include <stdio.h> int diff --git a/tests/if_statement/instrumented.c b/tests/if_statement/instrumented.c @@ -1,4 +1,5 @@ -static unsigned int lines[199]; +unsigned int lines[199]; +int size = 199; #include <stdlib.h> int diff --git a/tests/while_loops/instrumented.c b/tests/while_loops/instrumented.c @@ -1,4 +1,5 @@ -static unsigned int lines[76]; +unsigned int lines[76]; +int size = 76; int main(void) {