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