Release 950901
[wine] / debugger / memory.c
1 /*
2  * Debugger memory handling
3  *
4  * Copyright 1993 Eric Youngdale
5  * Copyright 1995 Alexandre Julliard
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "debugger.h"
11
12
13 /***********************************************************************
14  *           DEBUG_ReadMemory
15  *
16  * Read a memory value.
17  */
18 int DEBUG_ReadMemory( const DBG_ADDR *address )
19 {
20     DBG_ADDR addr = *address;
21
22     DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
23     return *(int *)DBG_ADDR_TO_LIN( &addr );
24 }
25
26
27 /***********************************************************************
28  *           DEBUG_WriteMemory
29  *
30  * Store a value in memory.
31  */
32 void DEBUG_WriteMemory( const DBG_ADDR *address, int value )
33 {
34     DBG_ADDR addr = *address;
35
36     DBG_FIX_ADDR_SEG( &addr, DS_reg(DEBUG_context) );
37     *(int *)DBG_ADDR_TO_LIN( &addr ) = value;
38 }
39
40
41 /***********************************************************************
42  *           DEBUG_ExamineMemory
43  *
44  * Implementation of the 'x' command.
45  */
46 void DEBUG_ExamineMemory( const DBG_ADDR *address, int count, char format )
47 {
48     DBG_ADDR addr = *address;
49     unsigned char * pnt;
50     unsigned int * dump;
51     unsigned short int * wdump;
52     int i;
53
54     DBG_FIX_ADDR_SEG( &addr, (format == 'i') ?
55                              CS_reg(DEBUG_context) : DS_reg(DEBUG_context) );
56
57     if (format != 'i' && count > 1)
58     {
59         DEBUG_PrintAddress( &addr, dbg_mode );
60         fprintf(stderr,":  ");
61     }
62
63     pnt = DBG_ADDR_TO_LIN( &addr );
64
65     switch(format)
66     {
67         case 's':
68                 if (count == 1) count = 256;
69                 while(*pnt && count--) fputc( *pnt++, stderr );
70                 fprintf(stderr,"\n");
71                 return;
72
73         case 'i':
74                 while (count--)
75                 {
76                     DEBUG_PrintAddress( &addr, dbg_mode );
77                     fprintf(stderr,":  ");
78                     DEBUG_Disasm( &addr );
79                     fprintf(stderr,"\n");
80                 }
81                 return;
82         case 'x':
83                 dump = (unsigned int *)pnt;
84                 for(i=0; i<count; i++) 
85                 {
86                         fprintf(stderr," %8.8x", *dump++);
87                         addr.off += 4;
88                         if ((i % 8) == 7) {
89                                 fprintf(stderr,"\n");
90                                 DEBUG_PrintAddress( &addr, dbg_mode );
91                                 fprintf(stderr,":  ");
92                         };
93                 }
94                 fprintf(stderr,"\n");
95                 return;
96         
97         case 'd':
98                 dump = (unsigned int *)pnt;
99                 for(i=0; i<count; i++) 
100                 {
101                         fprintf(stderr," %d", *dump++);
102                         addr.off += 4;
103                         if ((i % 8) == 7) {
104                                 fprintf(stderr,"\n");
105                                 DEBUG_PrintAddress( &addr, dbg_mode );
106                                 fprintf(stderr,":  ");
107                         };
108                 }
109                 fprintf(stderr,"\n");
110                 return;
111         
112         case 'w':
113                 wdump = (unsigned short *)pnt;
114                 for(i=0; i<count; i++) 
115                 {
116                         fprintf(stderr," %04x", *wdump++);
117                         addr.off += 2;
118                         if ((i % 8) == 7) {
119                                 fprintf(stderr,"\n");
120                                 DEBUG_PrintAddress( &addr, dbg_mode );
121                                 fprintf(stderr,":  ");
122                         };
123                 }
124                 fprintf(stderr,"\n");
125                 return;
126         
127         case 'c':
128                 for(i=0; i<count; i++) 
129                 {
130                         if(*pnt < 0x20) {
131                                 fprintf(stderr,"  ");
132                                 pnt++;
133                         } else
134                                 fprintf(stderr," %c", *pnt++);
135                         addr.off++;
136                         if ((i % 32) == 31) {
137                                 fprintf(stderr,"\n");
138                                 DEBUG_PrintAddress( &addr, dbg_mode );
139                                 fprintf(stderr,":  ");
140                         };
141                 }
142                 fprintf(stderr,"\n");
143                 return;
144         
145         case 'b':
146                 for(i=0; i<count; i++) 
147                 {
148                         fprintf(stderr," %02x", (*pnt++) & 0xff);
149                         addr.off++;
150                         if ((i % 16) == 15) {
151                                 fprintf(stderr,"\n");
152                                 DEBUG_PrintAddress( &addr, dbg_mode );
153                                 fprintf(stderr,":  ");
154                         };
155                 }
156                 fprintf(stderr,"\n");
157                 return;
158         }
159 }