OpenCBM
dbghelp.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2005 Spiro Trikaliotis
8  *
9 */
10 
20 #define DBG_USERMODE
21 
23 #define DBG_PROGNAME "ARCH.LIB"
24 
25 #include "debug.h"
26 
27 #include "arch.h"
28 
29 #include <windows.h>
30 
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <ctype.h>
34 
35 // #define DBG_DUMP_RAW_READ
36 // #define DBG_DUMP_RAW_WRITE
37 
38 /*-------------------------------------------------------------------*/
39 /*--------- DEBUGGING FUNCTIONS -------------------------------------*/
40 
41 #if DBG
42 
63 void
64 dbg_memdump(const char *Where, const unsigned char *InputBuffer, const unsigned int Count)
65 {
66  unsigned i;
67  char outputBufferChars[17];
68  char outputBuffer[100];
69  char *p;
70 
71  p = outputBuffer;
72 
73  DBG_PRINT((DBG_PREFIX "%s: (0x%04x)", Where, Count));
74 
75  for (i=0; i<Count; i++)
76  {
77  p += sprintf(p, "%02x ", (unsigned int) InputBuffer[i]);
78 
79  if (i % 16 == 7)
80  {
81  p += sprintf(p, "- ");
82  }
83 
84  outputBufferChars[i % 16] = isprint(InputBuffer[i]) ? InputBuffer[i] : '.';
85 
86  if (i % 16 == 15)
87  {
88  outputBufferChars[(i % 16) + 1] = 0;
89  DBG_PRINT((DBG_PREFIX "%04x: %-50s %s",
90  i & 0xfff0, outputBuffer, outputBufferChars));
91  p = outputBuffer;
92  }
93  }
94 
95  if (i % 16 != 0)
96  {
97  outputBufferChars[i % 16] = 0;
98  DBG_PRINT((DBG_PREFIX "%04x: %-50s %s",
99  i & 0xfff0, outputBuffer, outputBufferChars));
100  }
101 }
102 
103 #endif // #if DBG
Define makros for debugging purposes.
void dbg_memdump(const char *Where, const unsigned char *InputBuffer, const unsigned int Count)
output a memory dump to the debugging system
Definition: dbghelp.c:64
#define DBG_PREFIX
Definition: debug.h:320
Define makros and functions which account for differences between the different architectures.
#define DBG_PRINT(_xxx)
Definition: debug.h:403