Added dynamic tracing capability to vm

This commit is contained in:
Jeremiah Orians 2016-09-03 17:35:06 -04:00
parent 43340d8579
commit 7fc352944d
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
3 changed files with 457 additions and 0 deletions

84
dynamic_execution_trace.c Normal file
View File

@ -0,0 +1,84 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
/* Unique instruction type */
struct instruction_trace
{
uint64_t count;
char name[255];
struct instruction_trace* next;
struct instruction_trace* prev;
};
static struct instruction_trace* traces;
struct instruction_trace* create_trace(char* c)
{
struct instruction_trace* p;
p = calloc(1, sizeof(struct instruction_trace));
strncpy(p->name, c, 255);
p->count = 1;
return p;
}
struct instruction_trace* add_trace(struct instruction_trace* head, struct instruction_trace* p)
{
if(NULL == head)
{
return p;
}
if(NULL == head->next)
{
head->next = p;
p->prev = head;
}
else
{
add_trace(head->next, p);
}
return head;
}
bool update_trace(struct instruction_trace* p, char* c)
{
if(0 == strncmp(p->name, c, 255))
{
p->count = p->count + 1;
return true;
}
if(NULL != p->next)
{
return update_trace(p->next, c);
}
return false;
}
void record_trace(char* c)
{
if((NULL != traces) && (update_trace(traces, c)))
{
return;
}
traces = add_trace(traces, create_trace(c));
}
struct instruction_trace* print_trace(struct instruction_trace* p)
{
printf("%s\t%u\n", p->name, (unsigned int)p->count);
return p->next;
}
void print_traces()
{
struct instruction_trace* i = traces;
while(NULL != i)
{
i = print_trace(i);
}
}

View File

@ -6,6 +6,9 @@ libvm: wrapper.c vm_instructions.c vm_decode.c vm.h tty.c
vm: vm.h vm.c vm_instructions.c vm_decode.c tty.c
gcc -ggdb -Dtty_lib=true vm.h vm.c vm_instructions.c vm_decode.c tty.c -o bin/vm
vm-trace: vm.h vm.c vm_instructions.c vm_decode.c tty.c dynamic_execution_trace.c
gcc -ggdb -Dtty_lib=true -DTRACE=true vm.h vm.c vm_instructions.c vm_decode.c tty.c dynamic_execution_trace.c -o bin/vm
production: libvm-production vm-production asm dis
libvm-production: wrapper.c vm_instructions.c vm_decode.c vm.h

File diff suppressed because it is too large Load Diff