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
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
30 /* needs to be power of 2, search for MARK to see why :) */
31 #define DISPTAB_DELTA 8
39 char func_buffer[sizeof(SYMBOL_INFO) + 256];
43 static struct display *displaypoints = NULL;
44 static unsigned int maxdisplays = 0, ndisplays = 0;
46 static inline BOOL cmp_symbol(const SYMBOL_INFO* si1, const SYMBOL_INFO* si2)
48 if (si1->NameLen != si2->NameLen) return FALSE;
49 return !memcmp(si1, si2, sizeof(SYMBOL_INFO) + si1->NameLen);
52 int display_add(struct expr *exp, int count, char format, int in_frame)
56 for (i = 0; i < ndisplays; i++)
57 if (displaypoints[i].exp == NULL)
62 /* no space left - expand */
63 maxdisplays += DISPTAB_DELTA;
64 displaypoints = dbg_heap_realloc(displaypoints,
65 maxdisplays * sizeof(*displaypoints));
68 if (i == ndisplays) ndisplays++;
70 displaypoints[i].exp = expr_clone(exp);
71 displaypoints[i].count = count;
72 displaypoints[i].format = format;
73 displaypoints[i].enabled = TRUE;
76 displaypoints[i].func = (SYMBOL_INFO*)displaypoints[i].func_buffer;
77 displaypoints[i].func->SizeOfStruct = sizeof(SYMBOL_INFO);
78 displaypoints[i].func->MaxNameLen = sizeof(displaypoints[i].func_buffer) -
79 sizeof(*displaypoints[i].func);
80 if (!stack_get_frame(displaypoints[i].func, NULL))
82 expr_free(displaypoints[i].exp);
83 displaypoints[i].exp = NULL;
87 else displaypoints[i].func = NULL;
92 int display_info(void)
95 char buffer[sizeof(SYMBOL_INFO) + 256];
99 func = (SYMBOL_INFO*)buffer;
100 func->SizeOfStruct = sizeof(SYMBOL_INFO);
101 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
102 if (!stack_get_frame(func, NULL)) return FALSE;
104 for (i = 0; i < ndisplays; i++)
106 if (displaypoints[i].exp == NULL) continue;
108 if (displaypoints[i].enabled)
110 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
111 info = " (out of scope)";
116 info = " (disabled)";
117 dbg_printf("%d in %s%s: ",
118 i + 1, func ? displaypoints[i].func->Name : "", info);
119 expr_print(displaypoints[i].exp);
125 static void print_one_display(int i)
127 struct dbg_lvalue lvalue;
129 if (displaypoints[i].enabled)
131 lvalue = expr_eval(displaypoints[i].exp);
132 if (lvalue.typeid == dbg_itype_none)
134 dbg_printf("Unable to evaluate expression ");
135 expr_print(displaypoints[i].exp);
136 dbg_printf("\nDisabling display %d ...\n", i + 1);
137 displaypoints[i].enabled = FALSE;
142 dbg_printf("%d: ", i + 1);
143 expr_print(displaypoints[i].exp);
145 if (!displaypoints[i].enabled)
146 dbg_printf("(disabled)\n");
148 if (displaypoints[i].format == 'i')
149 memory_examine(&lvalue, displaypoints[i].count, displaypoints[i].format);
151 print_value(&lvalue, displaypoints[i].format, 0);
154 int display_print(void)
157 char buffer[sizeof(SYMBOL_INFO) + 256];
160 func = (SYMBOL_INFO*)buffer;
161 func->SizeOfStruct = sizeof(SYMBOL_INFO);
162 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
163 if (!stack_get_frame(func, NULL)) return FALSE;
165 for (i = 0; i < ndisplays; i++)
167 if (displaypoints[i].exp == NULL || !displaypoints[i].enabled)
169 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
171 print_one_display(i);
177 int display_delete(int displaynum)
181 if (displaynum > ndisplays || displaynum == 0 || displaynum < -1 ||
182 displaypoints[displaynum - 1].exp == NULL)
184 dbg_printf("Invalid display number\n");
188 if (displaynum == -1)
190 for (i = 0; i < ndisplays; i++)
192 if (displaypoints[i].exp != NULL)
194 expr_free(displaypoints[i].exp);
195 displaypoints[i].exp = NULL;
198 maxdisplays = DISPTAB_DELTA;
199 displaypoints = dbg_heap_realloc(displaypoints,
200 (maxdisplays = DISPTAB_DELTA) * sizeof(*displaypoints));
203 else if (displaypoints[--displaynum].exp != NULL)
205 expr_free(displaypoints[displaynum].exp);
206 displaypoints[displaynum].exp = NULL;
207 while (displaynum == ndisplays - 1 && displaypoints[displaynum].exp == NULL)
212 if (maxdisplays - ndisplays >= 2 * DISPTAB_DELTA)
215 maxdisplays = (ndisplays + DISPTAB_DELTA - 1) & ~(DISPTAB_DELTA - 1);
216 displaypoints = dbg_heap_realloc(displaypoints,
217 maxdisplays * sizeof(*displaypoints));
223 int display_enable(int displaynum, int enable)
225 char buffer[sizeof(SYMBOL_INFO) + 256];
228 func = (SYMBOL_INFO*)buffer;
229 func->SizeOfStruct = sizeof(SYMBOL_INFO);
230 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
231 if (!stack_get_frame(func, NULL)) return FALSE;
234 if (displaynum >= ndisplays || displaynum < 0 ||
235 displaypoints[displaynum].exp == NULL)
237 dbg_printf("Invalid display number\n");
241 displaypoints[displaynum].enabled = enable;
242 if (!displaypoints[displaynum].func ||
243 cmp_symbol(displaypoints[displaynum].func, func))
245 print_one_display(displaynum);