debug.c 864 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
static int do_debug(struct debug_processor *closure,
Niels Möller's avatar
Niels Möller committed
9
		    struct lsh_string *packet)
10
11
12
13
{
  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 A_WRITE(closure->super.next, packet);
27
28
}

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

Niels Möller's avatar
Niels Möller committed
34
35
  closure->super.super.write = (abstract_write_f) do_debug;
  closure->super.next = continuation;
36
37
  closure->output = output;

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