No longer directly accessing debuggee memory.
[wine] / debugger / display.c
1 /*
2  * File display.c - display handling for Wine internal debugger.
3  *
4  * Copyright (C) 1997, Eric Youngdale.
5  *
6  */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <limits.h>
12 #include <sys/types.h>
13
14 #include "debugger.h"
15
16 #include <stdarg.h>
17
18 #define MAX_DISPLAY 25
19
20 struct display
21 {
22   struct expr * exp;
23   int           count;
24   char          format;
25 };
26
27 static struct display displaypoints[MAX_DISPLAY];
28
29 int
30 DEBUG_AddDisplay(struct expr * exp, int count, char format)
31 {
32   int i;
33
34   /*
35    * First find a slot where we can store this display.
36    */
37   for(i=0; i < MAX_DISPLAY; i++ )
38     {
39       if( displaypoints[i].exp == NULL )
40         {
41           displaypoints[i].exp = DEBUG_CloneExpr(exp);
42           displaypoints[i].count  = count;
43           displaypoints[i].format = format;
44           break;
45         }
46     }
47
48   return TRUE;
49 }
50
51 int
52 DEBUG_InfoDisplay()
53 {
54   int i;
55
56   /*
57    * First find a slot where we can store this display.
58    */
59   for(i=0; i < MAX_DISPLAY; i++ )
60     {
61       if( displaypoints[i].exp != NULL )
62         {
63           fprintf(stderr, "%d : ", i+1);
64           DEBUG_DisplayExpr(displaypoints[i].exp);
65           fprintf(stderr, "\n");
66         }
67     }
68
69   return TRUE;
70 }
71
72 int
73 DEBUG_DoDisplay()
74 {
75   DBG_ADDR      addr;
76   int i;
77
78   /*
79    * First find a slot where we can store this display.
80    */
81   for(i=0; i < MAX_DISPLAY; i++ )
82     {
83       if( displaypoints[i].exp != NULL )
84         {
85           addr = DEBUG_EvalExpr(displaypoints[i].exp);
86           if( addr.type == NULL )
87             {
88               fprintf(stderr, "Unable to evaluate expression ");
89               DEBUG_DisplayExpr(displaypoints[i].exp);
90               fprintf(stderr, "\nDisabling...\n");
91               DEBUG_DelDisplay(i);
92             }
93           else
94             {
95               fprintf(stderr, "%d  : ", i + 1);
96               DEBUG_DisplayExpr(displaypoints[i].exp);
97               fprintf(stderr, " = ");
98               if( displaypoints[i].format == 'i' )
99                 {
100                   DEBUG_ExamineMemory( &addr, 
101                                displaypoints[i].count, 
102                                displaypoints[i].format);
103                 }
104               else
105                 {
106                   DEBUG_Print( &addr, 
107                                displaypoints[i].count, 
108                                displaypoints[i].format, 0);
109                 }
110             }
111         }
112     }
113
114   return TRUE;
115 }
116
117 int
118 DEBUG_DelDisplay(int displaynum)
119 {
120   int i;
121   
122   if( displaynum >= MAX_DISPLAY || displaynum == 0 || displaynum < -1 )
123     {
124       fprintf(stderr, "Invalid display number\n");
125       return TRUE;
126     }
127   if( displaynum == -1 )
128     {
129       for(i=0; i < MAX_DISPLAY; i++ )
130         {
131           if( displaypoints[i].exp != NULL )
132             {
133               DEBUG_FreeExpr(displaypoints[i].exp);
134               displaypoints[i].exp = NULL;
135             }
136         }
137     }
138   else if( displaypoints[displaynum - 1].exp != NULL )
139     {
140       DEBUG_FreeExpr(displaypoints[displaynum - 1].exp);
141       displaypoints[displaynum - 1].exp = NULL;
142     }
143   return TRUE;
144 }