Release 960225
[wine.git] / debugger / memory.c
blob49108c29de7dbc848cbe79c2310f3b338e11f505
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 "debugger.h"
13 /***********************************************************************
14 * DEBUG_IsBadReadPtr
16 * Check if we are allowed to read memory at 'address'.
18 BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size )
20 if (address->seg) /* segmented addr */
21 return IsBadReadPtr( (SEGPTR)MAKELONG( (WORD)address->off,
22 (WORD)address->seg ), size );
23 /* FIXME: should check if resulting linear addr is readable */
24 else /* linear address */
25 return FALSE; /* FIXME: should do some checks here */
29 /***********************************************************************
30 * DEBUG_IsBadWritePtr
32 * Check if we are allowed to write memory at 'address'.
34 BOOL DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size )
36 if (address->seg) /* segmented addr */
37 /* Note: we use IsBadReadPtr here because we are */
38 /* always allowed to write to read-only segments */
39 return IsBadReadPtr( (SEGPTR)MAKELONG( (WORD)address->off,
40 (WORD)address->seg ), size );
41 /* FIXME: should check if resulting linear addr is writable */
42 else /* linear address */
43 return FALSE; /* FIXME: should do some checks here */
47 /***********************************************************************
48 * DEBUG_ReadMemory
50 * Read a memory value.
52 int DEBUG_ReadMemory( const DBG_ADDR *address )
54 DBG_ADDR addr = *address;
56 DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
57 if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return 0;
58 return *(int *)DBG_ADDR_TO_LIN( &addr );
62 /***********************************************************************
63 * DEBUG_WriteMemory
65 * Store a value in memory.
67 void DEBUG_WriteMemory( const DBG_ADDR *address, int value )
69 DBG_ADDR addr = *address;
71 DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
72 if (!DBG_CHECK_WRITE_PTR( &addr, sizeof(int) )) return;
73 *(int *)DBG_ADDR_TO_LIN( &addr ) = value;
77 /***********************************************************************
78 * DEBUG_ExamineMemory
80 * Implementation of the 'x' command.
82 void DEBUG_ExamineMemory( const DBG_ADDR *address, int count, char format )
84 DBG_ADDR addr = *address;
85 unsigned char * pnt;
86 unsigned int * dump;
87 unsigned short int * wdump;
88 int i;
90 DBG_FIX_ADDR_SEG( &addr, (format == 'i') ?
91 CS_reg(DEBUG_context) : DS_reg(DEBUG_context) );
93 if (format != 'i' && count > 1)
95 DEBUG_PrintAddress( &addr, dbg_mode );
96 fprintf(stderr,": ");
99 pnt = DBG_ADDR_TO_LIN( &addr );
101 switch(format)
103 case 's':
104 if (count == 1) count = 256;
105 while (count--)
107 if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
108 if (!*pnt) break;
109 addr.off++;
110 fputc( *pnt++, stderr );
112 fprintf(stderr,"\n");
113 return;
115 case 'i':
116 while (count--)
118 DEBUG_PrintAddress( &addr, dbg_mode );
119 fprintf(stderr,": ");
120 if (!DBG_CHECK_READ_PTR( &addr, 1 )) return;
121 DEBUG_Disasm( &addr );
122 fprintf(stderr,"\n");
124 return;
125 case 'x':
126 dump = (unsigned int *)pnt;
127 for(i=0; i<count; i++)
129 if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return;
130 fprintf(stderr," %8.8x", *dump++);
131 addr.off += sizeof(int);
132 if ((i % 8) == 7)
134 fprintf(stderr,"\n");
135 DEBUG_PrintAddress( &addr, dbg_mode );
136 fprintf(stderr,": ");
139 fprintf(stderr,"\n");
140 return;
142 case 'd':
143 dump = (unsigned int *)pnt;
144 for(i=0; i<count; i++)
146 if (!DBG_CHECK_READ_PTR( &addr, sizeof(int) )) return;
147 fprintf(stderr," %d", *dump++);
148 addr.off += sizeof(int);
149 if ((i % 8) == 7)
151 fprintf(stderr,"\n");
152 DEBUG_PrintAddress( &addr, dbg_mode );
153 fprintf(stderr,": ");
156 fprintf(stderr,"\n");
157 return;
159 case 'w':
160 wdump = (unsigned short *)pnt;
161 for(i=0; i<count; i++)
163 if (!DBG_CHECK_READ_PTR( &addr, sizeof(short) )) return;
164 fprintf(stderr," %04x", *wdump++);
165 addr.off += sizeof(short);
166 if ((i % 8) == 7)
168 fprintf(stderr,"\n");
169 DEBUG_PrintAddress( &addr, dbg_mode );
170 fprintf(stderr,": ");
173 fprintf(stderr,"\n");
174 return;
176 case 'c':
177 for(i=0; i<count; i++)
179 if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
180 if(*pnt < 0x20)
182 fprintf(stderr," ");
183 pnt++;
185 else fprintf(stderr," %c", *pnt++);
186 addr.off++;
187 if ((i % 32) == 31)
189 fprintf(stderr,"\n");
190 DEBUG_PrintAddress( &addr, dbg_mode );
191 fprintf(stderr,": ");
194 fprintf(stderr,"\n");
195 return;
197 case 'b':
198 for(i=0; i<count; i++)
200 if (!DBG_CHECK_READ_PTR( &addr, sizeof(char) )) return;
201 fprintf(stderr," %02x", (*pnt++) & 0xff);
202 addr.off++;
203 if ((i % 16) == 15)
205 fprintf(stderr,"\n");
206 DEBUG_PrintAddress( &addr, dbg_mode );
207 fprintf(stderr,": ");
210 fprintf(stderr,"\n");
211 return;