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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 /* needs to be power of 2, search for MARK to see why :) */
28 #define DISPTAB_DELTA 8
36 char func_buffer[sizeof(SYMBOL_INFO) + 256];
40 static struct display *displaypoints = NULL;
41 static unsigned int maxdisplays = 0, ndisplays = 0;
43 static inline BOOL cmp_symbol(const SYMBOL_INFO* si1, const SYMBOL_INFO* si2)
45 /* FIXME: !memcmp(si1, si2, sizeof(SYMBOL_INFO) + si1->NameLen)
46 * is wrong because sizeof(SYMBOL_INFO) can be aligned on 4-byte boundary
47 * Note: we also need to zero out the structures before calling
48 * stack_get_frame, so that un-touched fields by stack_get_frame
49 * get the same value!!
51 return !memcmp(si1, si2, FIELD_OFFSET(SYMBOL_INFO, Name)) &&
52 !memcmp(si1->Name, si2->Name, si1->NameLen);
55 int display_add(struct expr *exp, int count, char format)
58 BOOL local_binding = FALSE;
60 for (i = 0; i < ndisplays; i++)
61 if (displaypoints[i].exp == NULL)
66 /* no space left - expand */
67 maxdisplays += DISPTAB_DELTA;
68 displaypoints = dbg_heap_realloc(displaypoints,
69 maxdisplays * sizeof(*displaypoints));
72 if (i == ndisplays) ndisplays++;
74 displaypoints[i].exp = expr_clone(exp, &local_binding);
75 displaypoints[i].count = count;
76 displaypoints[i].format = format;
77 displaypoints[i].enabled = TRUE;
80 displaypoints[i].func = (SYMBOL_INFO*)displaypoints[i].func_buffer;
81 memset(displaypoints[i].func, 0, sizeof(SYMBOL_INFO));
82 displaypoints[i].func->SizeOfStruct = sizeof(SYMBOL_INFO);
83 displaypoints[i].func->MaxNameLen = sizeof(displaypoints[i].func_buffer) -
84 sizeof(*displaypoints[i].func);
85 if (!stack_get_current_symbol(displaypoints[i].func))
87 expr_free(displaypoints[i].exp);
88 displaypoints[i].exp = NULL;
92 else displaypoints[i].func = NULL;
97 int display_info(void)
100 char buffer[sizeof(SYMBOL_INFO) + 256];
104 func = (SYMBOL_INFO*)buffer;
105 memset(func, 0, sizeof(SYMBOL_INFO));
106 func->SizeOfStruct = sizeof(SYMBOL_INFO);
107 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
108 if (!stack_get_current_symbol(func)) return FALSE;
110 for (i = 0; i < ndisplays; i++)
112 if (displaypoints[i].exp == NULL) continue;
114 dbg_printf("%d: ", i + 1);
115 expr_print(displaypoints[i].exp);
117 if (displaypoints[i].enabled)
119 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
120 info = " (out of scope)";
125 info = " (disabled)";
126 if (displaypoints[i].func)
127 dbg_printf(" in %s", displaypoints[i].func->Name);
128 dbg_printf("%s\n", info);
133 static void print_one_display(int i)
135 struct dbg_lvalue lvalue;
137 if (displaypoints[i].enabled)
139 lvalue = expr_eval(displaypoints[i].exp);
140 if (lvalue.type.id == dbg_itype_none)
142 dbg_printf("Unable to evaluate expression ");
143 expr_print(displaypoints[i].exp);
144 dbg_printf("\nDisabling display %d ...\n", i + 1);
145 displaypoints[i].enabled = FALSE;
150 dbg_printf("%d: ", i + 1);
151 expr_print(displaypoints[i].exp);
153 if (!displaypoints[i].enabled)
154 dbg_printf("(disabled)\n");
156 if (displaypoints[i].format == 'i')
157 memory_examine(&lvalue, displaypoints[i].count, displaypoints[i].format);
159 print_value(&lvalue, displaypoints[i].format, 0);
162 int display_print(void)
165 char buffer[sizeof(SYMBOL_INFO) + 256];
168 func = (SYMBOL_INFO*)buffer;
169 memset(func, 0, sizeof(SYMBOL_INFO));
170 func->SizeOfStruct = sizeof(SYMBOL_INFO);
171 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
172 if (!stack_get_current_symbol(func)) return FALSE;
174 for (i = 0; i < ndisplays; i++)
176 if (displaypoints[i].exp == NULL || !displaypoints[i].enabled)
178 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
180 print_one_display(i);
186 int display_delete(int displaynum)
188 if (displaynum > ndisplays || displaynum == 0 || displaynum < -1 ||
189 displaypoints[displaynum - 1].exp == NULL)
191 dbg_printf("Invalid display number\n");
195 if (displaynum == -1)
199 for (i = 0; i < ndisplays; i++)
201 if (displaypoints[i].exp != NULL)
203 expr_free(displaypoints[i].exp);
204 displaypoints[i].exp = NULL;
207 maxdisplays = DISPTAB_DELTA;
208 displaypoints = dbg_heap_realloc(displaypoints,
209 (maxdisplays = DISPTAB_DELTA) * sizeof(*displaypoints));
212 else if (displaypoints[--displaynum].exp != NULL)
214 expr_free(displaypoints[displaynum].exp);
215 displaypoints[displaynum].exp = NULL;
216 while (displaynum == ndisplays - 1 && displaypoints[displaynum].exp == NULL)
221 if (maxdisplays - ndisplays >= 2 * DISPTAB_DELTA)
224 maxdisplays = (ndisplays + DISPTAB_DELTA - 1) & ~(DISPTAB_DELTA - 1);
225 displaypoints = dbg_heap_realloc(displaypoints,
226 maxdisplays * sizeof(*displaypoints));
232 int display_enable(int displaynum, int enable)
234 char buffer[sizeof(SYMBOL_INFO) + 256];
237 func = (SYMBOL_INFO*)buffer;
238 memset(func, 0, sizeof(SYMBOL_INFO));
239 func->SizeOfStruct = sizeof(SYMBOL_INFO);
240 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
241 if (!stack_get_current_symbol(func)) return FALSE;
244 if (displaynum >= ndisplays || displaynum < 0 ||
245 displaypoints[displaynum].exp == NULL)
247 dbg_printf("Invalid display number\n");
251 displaypoints[displaynum].enabled = enable;
252 if (!displaypoints[displaynum].func ||
253 cmp_symbol(displaypoints[displaynum].func, func))
255 print_one_display(displaynum);