aboutsummaryrefslogtreecommitdiff
path: root/trace.c
blob: 31d01f7ce715924c27dd19144dc0f9a973396f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* $Id$ */
/********************************************************************
 * File: trace.c
 *
 * main function for the pvtrace utility.
 *
 * Author: M. Tim Jones <mtj@mtjones.com>
 *
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "symbols.h"
#include "stack.h"

int
main(int argc, char *argv[])
{
	FILE *tracef;
	char type;
	unsigned int address;

	if (argc != 2) {
		printf("Usage: pvtrace <image>\n\n");
		exit(-1);
	}
	initSymbol(argv[1]);
	stackInit();

	tracef = fopen("trace.txt", "r");

	if (tracef == NULL) {
		printf("Can't open trace.txt\n");
		exit(-1);
	}
	while (!feof(tracef)) {
		fscanf(tracef, "%c0x%x\n", &type, &address);
		switch (type) {
		case 'E':
			/* Function Entry */
			addSymbol(address);
			addCallTrace(address);
			stackPush(address);
			break;
		case 'X':
			/* Function Exit */
			(void) stackPop();
			break;
		}
	}

	emitSymbols();
	fclose(tracef);

	return 0;
}