2 * Debugger memory handling
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
14 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
81 * Implementation of the 'x' command.
83 void DEBUG_ExamineMemory( const DBG_ADDR
*address
, int count
, char format
)
85 DBG_ADDR addr
= *address
;
88 unsigned short int * wdump
;
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
);
100 pnt
= DBG_ADDR_TO_LIN( &addr
);
105 if (count
== 1) count
= 256;
108 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(char) )) return;
111 fputc( *pnt
++, stderr
);
113 fprintf(stderr
,"\n");
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");
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);
135 fprintf(stderr
,"\n");
136 DEBUG_PrintAddress( &addr
, dbg_mode
);
137 fprintf(stderr
,": ");
140 fprintf(stderr
,"\n");
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);
152 fprintf(stderr
,"\n");
153 DEBUG_PrintAddress( &addr
, dbg_mode
);
154 fprintf(stderr
,": ");
157 fprintf(stderr
,"\n");
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);
169 fprintf(stderr
,"\n");
170 DEBUG_PrintAddress( &addr
, dbg_mode
);
171 fprintf(stderr
,": ");
174 fprintf(stderr
,"\n");
178 for(i
=0; i
<count
; i
++)
180 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(char) )) return;
186 else fprintf(stderr
," %c", *pnt
++);
190 fprintf(stderr
,"\n");
191 DEBUG_PrintAddress( &addr
, dbg_mode
);
192 fprintf(stderr
,": ");
195 fprintf(stderr
,"\n");
199 for(i
=0; i
<count
; i
++)
201 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(char) )) return;
202 fprintf(stderr
," %02x", (*pnt
++) & 0xff);
206 fprintf(stderr
,"\n");
207 DEBUG_PrintAddress( &addr
, dbg_mode
);
208 fprintf(stderr
,": ");
211 fprintf(stderr
,"\n");