debug.c 877 Bytes
Newer Older
1
2
3
4
/* debug.c
 *
 */

Niels Möller's avatar
Niels Möller committed
5
6
7
#include "debug.h"
#include "xalloc.h"

8
9
10
11
12
13
static int do_debug(struct debug_processor *closure,
		    struct simple_packet *packet)
{
  UINT32 i;
  
  fprintf(closure->output, "DEBUG: (packet size %d = 0x%x)\n",
Niels Möller's avatar
Niels Möller committed
14
	  packet->length, packet->length);
15
16
17
18
19
20
21
22
23
24
25

  for(i=0; i<packet->length; i++)
  {
    if (! i%16)
      fprintf(closure->output, "\n%08x: ", i);
    
    fprintf(closure->output, "%02x ", packet->data[i]);
  }

  fprintf(closure->output, "\n");

Niels Möller's avatar
Niels Möller committed
26
  return apply_processor(closure->c.next, packet);
27
28
29
}

struct packet_processor *make_debug_processor(FILE *output,
Niels Möller's avatar
Niels Möller committed
30
					      struct packet_processor *continuation)
31
32
33
{
  struct debug_processor *closure = xalloc(sizeof(struct debug_processor));

Niels Möller's avatar
Niels Möller committed
34
35
  closure->c.p.f = (raw_processor_function) do_debug;
  closure->c.next = continuation;
36
37
  closure->output = output;

Niels Möller's avatar
Niels Möller committed
38
  return (struct packet_processor *) closure;
39
40
41
}