Merge branch 'inspector' into 'master'
Updated Makefile and mallocanalysis.c See merge request cs3214-staff/malloclab!28
This commit is contained in:
commit
36b8b0e78f
16
Makefile
16
Makefile
@ -25,11 +25,23 @@ all: mdriver libMallocInstrumented.so
|
|||||||
mdriver: $(OBJS)
|
mdriver: $(OBJS)
|
||||||
$(CC) $(CFLAGS) -o mdriver $(OBJS)
|
$(CC) $(CFLAGS) -o mdriver $(OBJS)
|
||||||
|
|
||||||
libMallocInstrumented.so: mm.c
|
libMallocInstrumented.so: mm.c list.c memlib.c mallocanalysis.c
|
||||||
|
# This compiles and instruments mm.c
|
||||||
clang $(CLANGFLAGS) mm.c -o mm.bc
|
clang $(CLANGFLAGS) mm.c -o mm.bc
|
||||||
LD_LIBRARY_PATH=$(INST_BUILD_LOC)/lib opt -load libLLVMMallocInjectorPass.so -mallocinjector mm.bc -o mm-instrumented.bc
|
LD_LIBRARY_PATH=$(INST_BUILD_LOC)/lib opt -load libLLVMMallocInjectorPass.so -mallocinjector mm.bc -o mm-instrumented.bc
|
||||||
llc $(LLCFLAGS) mm-instrumented.bc -o mm-instrumented.o
|
llc $(LLCFLAGS) mm-instrumented.bc -o mm-instrumented.o
|
||||||
clang -shared mm-instrumented.o $(INST_BUILD_LOC)/build-instrumentation/list-instrumented.o -o libMallocInstrumented.so
|
|
||||||
|
# This compiles and instruments list.c
|
||||||
|
clang $(CLANGFLAGS) list.c -o list.bc
|
||||||
|
LD_LIBRARY_PATH=$(INST_BUILD_LOC)/lib opt -load libLLVMMallocInjectorPass.so -mallocinjector list.bc -o list-instrumented.bc
|
||||||
|
llc $(LLCFLAGS) list-instrumented.bc -o list-instrumented.o
|
||||||
|
|
||||||
|
# Now, simply build memlib and mallocanalysis
|
||||||
|
clang -ggdb3 -c -fPIC memlib.c -o memlib-instrumented.o
|
||||||
|
clang -ggdb3 -c -fPIC mallocanalysis.c -o mallocanalysis.o
|
||||||
|
|
||||||
|
# Link it all together
|
||||||
|
clang -shared mm-instrumented.o list-instrumented.o memlib-instrumented.o mallocanalysis.o -o libMallocInstrumented.so
|
||||||
|
|
||||||
# if multi-threaded implementation is attempted
|
# if multi-threaded implementation is attempted
|
||||||
mdriver-ts: $(MTOBJS)
|
mdriver-ts: $(MTOBJS)
|
||||||
|
53
mallocanalysis.c
Normal file
53
mallocanalysis.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/* This file aids in the dynamic instrumentation of the heap visualizer.
|
||||||
|
* Do not make changes to this file unless you know what you're doing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Create typedef for our callback function */
|
||||||
|
typedef void (*memory_analyzer_callback_t)(void *, void *, long long, int, char *, char *);
|
||||||
|
|
||||||
|
|
||||||
|
/* Create typedef for the list callback */
|
||||||
|
typedef void (*memory_analyzer_list_init_callback_t)(void *);
|
||||||
|
|
||||||
|
/* Create typedef for the list callback */
|
||||||
|
typedef void (*memory_analyzer_list_integrity_callback_t)(void);
|
||||||
|
|
||||||
|
/* Function signatures */
|
||||||
|
void __memory_write_detected(void *, void *, long long, int, char *, char *);
|
||||||
|
void __list_integrity_check(void);
|
||||||
|
void __list_init_detected(void *);
|
||||||
|
|
||||||
|
/* Create file-scope variables for our analyzer */
|
||||||
|
static bool __memory_analyzer_initialized = false;
|
||||||
|
static memory_analyzer_callback_t __memory_analyzer_function_callback = NULL;
|
||||||
|
static memory_analyzer_list_init_callback_t __memory_analyzer_list_callback = NULL;
|
||||||
|
static memory_analyzer_list_integrity_callback_t __memory_analyzer_list_integrity_callback = NULL;
|
||||||
|
|
||||||
|
void initialize_memory_analyzer(memory_analyzer_callback_t callback, memory_analyzer_list_init_callback_t list_callback, memory_analyzer_list_integrity_callback_t list_integrity_callback) {
|
||||||
|
__memory_analyzer_function_callback = callback;
|
||||||
|
__memory_analyzer_list_callback = list_callback;
|
||||||
|
__memory_analyzer_list_integrity_callback = list_integrity_callback;
|
||||||
|
__memory_analyzer_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __memory_write_detected(void * pointer, void * value, long long size, int line_number, char * filename, char * structname) {
|
||||||
|
/* If the memory analyzer is initialized, create a function call to our callback */
|
||||||
|
if (__memory_analyzer_initialized) {
|
||||||
|
__memory_analyzer_function_callback(pointer, value, size, line_number, filename, structname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __list_init_detected(void * list) {
|
||||||
|
if (__memory_analyzer_initialized) {
|
||||||
|
__memory_analyzer_list_callback(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __list_integrity_check(void) {
|
||||||
|
if (__memory_analyzer_initialized) {
|
||||||
|
__memory_analyzer_list_integrity_callback();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user