aboutsummaryrefslogtreecommitdiff
path: root/trace.c
blob: d5975a40dbf49bd37efe56d0b0444975d73e4562 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* $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 );

    if        (type == 'E') {

      /* Function Entry */

      addSymbol( address );

      addCallTrace( address );

      stackPush( address );

    } else if (type == 'X') {

      /* Function Exit */

      (void) stackPop();

    }

  }

  emitSymbols();

  fclose( tracef );
  
  return 0;
}