Moved a number of 16-bit functions to file16.c.
[wine.git] / programs / winedbg / display.c
blob279032cf665bc971da8758525fe63973bf733f53
1 /*
2 * File display.c - display handling for Wine internal debugger.
4 * Copyright (C) 1997, Eric Youngdale.
5 * Copyright (C) 2003, Michal Miroslaw
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdlib.h>
23 #include <string.h>
24 #include <limits.h>
25 #include <sys/types.h>
27 #include "debugger.h"
29 #include <stdarg.h>
31 #define DISPTAB_DELTA 8 /* needs to be power of 2, search for MARK to see why :) */
33 struct display {
34 struct expr *exp;
35 int count;
36 char format;
37 char enabled;
38 struct name_hash *function_name;
41 static struct display *displaypoints = NULL;
42 static unsigned int maxdisplays = 0, ndisplays = 0;
44 static struct name_hash *DEBUG_GetCurrentFrameFunctionName(void)
46 struct name_hash *name;
47 unsigned int eip, ebp;
49 if (DEBUG_GetCurrentFrame(&name, &eip, &ebp))
50 return name;
51 return NULL;
54 int DEBUG_AddDisplay(struct expr *exp, int count, char format, int in_frame)
56 int i;
58 for (i = 0; i < ndisplays; i++)
59 if (displaypoints[i].exp == NULL)
60 break;
62 if (i == maxdisplays) /* no space left - expand */
63 displaypoints = DBG_realloc(displaypoints,
64 (maxdisplays += DISPTAB_DELTA) * sizeof(*displaypoints));
66 if (i == ndisplays)
67 ++ndisplays;
69 displaypoints[i].exp = DEBUG_CloneExpr(exp);
70 displaypoints[i].count = count;
71 displaypoints[i].format = format;
72 displaypoints[i].enabled = TRUE;
73 displaypoints[i].function_name =
74 (in_frame ? DEBUG_GetCurrentFrameFunctionName() : NULL);
76 return TRUE;
79 int DEBUG_InfoDisplay(void)
81 int i;
83 for (i = 0; i < ndisplays; i++) {
84 if (displaypoints[i].exp == NULL)
85 continue;
87 if (displaypoints[i].function_name)
88 DEBUG_Printf("%d in %s%s : ", i + 1,
89 DEBUG_GetSymbolName(displaypoints[i].function_name),
90 (displaypoints[i].enabled ?
91 (displaypoints[i].function_name != DEBUG_GetCurrentFrameFunctionName() ?
92 " (out of scope)" : "")
93 : " (disabled)")
95 else
96 DEBUG_Printf("%d%s : ", i + 1,
97 (displaypoints[i].enabled ? "" : " (disabled)"));
98 DEBUG_DisplayExpr(displaypoints[i].exp);
99 DEBUG_Printf("\n");
102 return TRUE;
105 void DEBUG_PrintOneDisplay(int i)
107 DBG_VALUE value;
109 if (displaypoints[i].enabled) {
110 value = DEBUG_EvalExpr(displaypoints[i].exp);
111 if (value.type == NULL) {
112 DEBUG_Printf("Unable to evaluate expression ");
113 DEBUG_DisplayExpr(displaypoints[i].exp);
114 DEBUG_Printf("\nDisabling display %d ...\n", i + 1);
115 displaypoints[i].enabled = FALSE;
116 return;
120 DEBUG_Printf("%d : ", i + 1);
121 DEBUG_DisplayExpr(displaypoints[i].exp);
122 DEBUG_Printf(" = ");
123 if (!displaypoints[i].enabled)
124 DEBUG_Printf("(disabled)\n");
125 else
126 if (displaypoints[i].format == 'i')
127 DEBUG_ExamineMemory(&value, displaypoints[i].count, displaypoints[i].format);
128 else
129 DEBUG_Print(&value, displaypoints[i].count, displaypoints[i].format, 0);
132 int DEBUG_DoDisplay(void)
134 int i;
135 struct name_hash *cur_function_name = DEBUG_GetCurrentFrameFunctionName();
137 for (i = 0; i < ndisplays; i++) {
138 if (displaypoints[i].exp == NULL || !displaypoints[i].enabled)
139 continue;
140 if (displaypoints[i].function_name
141 && displaypoints[i].function_name != cur_function_name)
142 continue;
143 DEBUG_PrintOneDisplay(i);
146 return TRUE;
149 int DEBUG_DelDisplay(int displaynum)
151 int i;
153 if (displaynum > ndisplays || displaynum == 0 || displaynum < -1
154 || displaypoints[displaynum - 1].exp == NULL) {
155 DEBUG_Printf("Invalid display number\n");
156 return TRUE;
159 if (displaynum == -1) {
160 for (i = 0; i < ndisplays; i++) {
161 if (displaypoints[i].exp != NULL) {
162 DEBUG_FreeExpr(displaypoints[i].exp);
163 displaypoints[i].exp = NULL;
166 displaypoints = DBG_realloc(displaypoints,
167 (maxdisplays = DISPTAB_DELTA) * sizeof(*displaypoints));
168 ndisplays = 0;
169 } else if (displaypoints[--displaynum].exp != NULL) {
170 DEBUG_FreeExpr(displaypoints[displaynum].exp);
171 displaypoints[displaynum].exp = NULL;
172 while (displaynum == ndisplays - 1
173 && displaypoints[displaynum].exp == NULL)
174 --ndisplays, --displaynum;
175 if (maxdisplays - ndisplays >= 2 * DISPTAB_DELTA) {
176 maxdisplays = (ndisplays + DISPTAB_DELTA - 1) & ~(DISPTAB_DELTA - 1); /* MARK */
177 displaypoints = DBG_realloc(displaypoints,
178 maxdisplays * sizeof(*displaypoints));
181 return TRUE;
184 int DEBUG_EnableDisplay(int displaynum, int enable)
186 --displaynum;
187 if (displaynum >= ndisplays || displaynum < 0 || displaypoints[displaynum].exp == NULL) {
188 DEBUG_Printf("Invalid display number\n");
189 return TRUE;
192 displaypoints[displaynum].enabled = enable;
193 if (!displaypoints[displaynum].function_name
194 || displaypoints[displaynum].function_name == DEBUG_GetCurrentFrameFunctionName())
195 DEBUG_PrintOneDisplay(displaynum);
197 return TRUE;