2 * Debugger memory handling
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
13 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
80 * Implementation of the 'x' command.
82 void DEBUG_ExamineMemory( const DBG_ADDR
*address
, int count
, char format
)
84 DBG_ADDR addr
= *address
;
87 unsigned short int * wdump
;
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
);
99 pnt
= DBG_ADDR_TO_LIN( &addr
);
104 if (count
== 1) count
= 256;
107 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(char) )) return;
110 fputc( *pnt
++, stderr
);
112 fprintf(stderr
,"\n");
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");
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);
134 fprintf(stderr
,"\n");
135 DEBUG_PrintAddress( &addr
, dbg_mode
);
136 fprintf(stderr
,": ");
139 fprintf(stderr
,"\n");
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);
151 fprintf(stderr
,"\n");
152 DEBUG_PrintAddress( &addr
, dbg_mode
);
153 fprintf(stderr
,": ");
156 fprintf(stderr
,"\n");
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);
168 fprintf(stderr
,"\n");
169 DEBUG_PrintAddress( &addr
, dbg_mode
);
170 fprintf(stderr
,": ");
173 fprintf(stderr
,"\n");
177 for(i
=0; i
<count
; i
++)
179 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(char) )) return;
185 else fprintf(stderr
," %c", *pnt
++);
189 fprintf(stderr
,"\n");
190 DEBUG_PrintAddress( &addr
, dbg_mode
);
191 fprintf(stderr
,": ");
194 fprintf(stderr
,"\n");
198 for(i
=0; i
<count
; i
++)
200 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(char) )) return;
201 fprintf(stderr
," %02x", (*pnt
++) & 0xff);
205 fprintf(stderr
,"\n");
206 DEBUG_PrintAddress( &addr
, dbg_mode
);
207 fprintf(stderr
,": ");
210 fprintf(stderr
,"\n");