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