Release 960712
[wine/multimedia.git] / debugger / memory.c
blob62d33060c096503f9cdd653418dc1fce84013349
1 /*
2 * Debugger memory handling
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "windows.h"
11 #include "debugger.h"
14 /***********************************************************************
15 * DEBUG_IsBadReadPtr
17 * Check if we are allowed to read memory at 'address'.
19 BOOL32 DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size )
21 if (address->seg) /* segmented addr */
22 return IsBadReadPtr( (SEGPTR)MAKELONG( (WORD)address->off,
23 (WORD)address->seg ), size );
24 /* FIXME: should check if resulting linear addr is readable */
25 else /* linear address */
26 return FALSE; /* FIXME: should do some checks here */
30 /***********************************************************************
31 * DEBUG_IsBadWritePtr
33 * Check if we are allowed to write memory at 'address'.
35 BOOL32 DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size )
37 if (address->seg) /* segmented addr */
38 /* Note: we use IsBadReadPtr here because we are */
39 /* always allowed to write to read-only segments */
40 return IsBadReadPtr( (SEGPTR)MAKELONG( (WORD)address->off,
41 (WORD)address->seg ), size );
42 /* FIXME: should check if resulting linear addr is writable */
43 else /* linear address */
44 return FALSE; /* FIXME: should do some checks here */
48 /***********************************************************************
49 * DEBUG_ReadMemory
51 * Read a memory value.
53 int DEBUG_ReadMemory( const DBG_ADDR *address )
55 DBG_ADDR addr = *address;
57 DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
58 if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return 0;
59 return *(int *)DBG_ADDR_TO_LIN( &addr );
63 /***********************************************************************
64 * DEBUG_WriteMemory
66 * Store a value in memory.
68 void DEBUG_WriteMemory( const DBG_ADDR *address, int value )
70 DBG_ADDR addr = *address;
72 DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
73 if (!DBG_CHECK_WRITE_PTR( &addr, sizeof(int) )) return;
74 *(int *)DBG_ADDR_TO_LIN( &addr ) = value;
78 /***********************************************************************
79 * DEBUG_ExamineMemory
81 * Implementation of the 'x' command.
83 void DEBUG_ExamineMemory( const DBG_ADDR *address, int count, char format )
85 DBG_ADDR addr = *address;
86 unsigned char * pnt;
87 unsigned int * dump;
88 unsigned short int * wdump;
89 int i;
91 DBG_FIX_ADDR_SEG( &addr, (format == 'i') ?
92 CS_reg(DEBUG_context) : DS_reg(DEBUG_context) );
94 if (format != 'i' && count > 1)
96 DEBUG_PrintAddress( &addr, dbg_mode );
97 fprintf(stderr,": ");
100 pnt = DBG_ADDR_TO_LIN( &addr );
102 switch(format)
104 case 's':
105 if (count == 1) count = 256;
106 while (count--)
108 if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
109 if (!*pnt) break;
110 addr.off++;
111 fputc( *pnt++, stderr );
113 fprintf(stderr,"\n");
114 return;
116 case 'i':
117 while (count--)
119 DEBUG_PrintAddress( &addr, dbg_mode );
120 fprintf(stderr,": ");
121 if (!DBG_CHECK_READ_PTR( &addr, 1 )) return;
122 DEBUG_Disasm( &addr );
123 fprintf(stderr,"\n");
125 return;
126 case 'x':
127 dump = (unsigned int *)pnt;
128 for(i=0; i<count; i++)
130 if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return;
131 fprintf(stderr," %8.8x", *dump++);
132 addr.off += sizeof(int);
133 if ((i % 8) == 7)
135 fprintf(stderr,"\n");
136 DEBUG_PrintAddress( &addr, dbg_mode );
137 fprintf(stderr,": ");
140 fprintf(stderr,"\n");
141 return;
143 case 'd':
144 dump = (unsigned int *)pnt;
145 for(i=0; i<count; i++)
147 if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return;
148 fprintf(stderr," %d", *dump++);
149 addr.off += sizeof(int);
150 if ((i % 8) == 7)
152 fprintf(stderr,"\n");
153 DEBUG_PrintAddress( &addr, dbg_mode );
154 fprintf(stderr,": ");
157 fprintf(stderr,"\n");
158 return;
160 case 'w':
161 wdump = (unsigned short *)pnt;
162 for(i=0; i<count; i++)
164 if (!DBG_CHECK_READ_PTR( &addr, sizeof(short) )) return;
165 fprintf(stderr," %04x", *wdump++);
166 addr.off += sizeof(short);
167 if ((i % 8) == 7)
169 fprintf(stderr,"\n");
170 DEBUG_PrintAddress( &addr, dbg_mode );
171 fprintf(stderr,": ");
174 fprintf(stderr,"\n");
175 return;
177 case 'c':
178 for(i=0; i<count; i++)
180 if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
181 if(*pnt < 0x20)
183 fprintf(stderr," ");
184 pnt++;
186 else fprintf(stderr," %c", *pnt++);
187 addr.off++;
188 if ((i % 32) == 31)
190 fprintf(stderr,"\n");
191 DEBUG_PrintAddress( &addr, dbg_mode );
192 fprintf(stderr,": ");
195 fprintf(stderr,"\n");
196 return;
198 case 'b':
199 for(i=0; i<count; i++)
201 if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
202 fprintf(stderr," %02x", (*pnt++) & 0xff);
203 addr.off++;
204 if ((i % 16) == 15)
206 fprintf(stderr,"\n");
207 DEBUG_PrintAddress( &addr, dbg_mode );
208 fprintf(stderr,": ");
211 fprintf(stderr,"\n");
212 return;