ntdll: Implement RtlIsEcCode().
[wine.git] / programs / winedbg / display.c
blob370aa9f6bd7dce22672d53ef88370886740b187d
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdlib.h>
23 #include <string.h>
25 #include "debugger.h"
27 /* needs to be power of 2, search for MARK to see why :) */
28 #define DISPTAB_DELTA 8
30 struct display
32 struct expr* exp;
33 int count;
34 char format;
35 char enabled;
36 char func_buffer[sizeof(SYMBOL_INFO) + 256];
37 SYMBOL_INFO* func;
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 BOOL display_add(struct expr *exp, int count, char format)
57 unsigned i;
58 BOOL local_binding = FALSE;
60 for (i = 0; i < ndisplays; i++)
61 if (displaypoints[i].exp == NULL)
62 break;
64 if (i == maxdisplays)
66 struct display *new;
67 /* no space left - expand */
68 new = realloc(displaypoints,
69 (maxdisplays + DISPTAB_DELTA) * sizeof(*displaypoints));
70 if (!new) return FALSE;
71 displaypoints = new;
72 maxdisplays += DISPTAB_DELTA;
75 if (i == ndisplays) ndisplays++;
77 displaypoints[i].exp = expr_clone(exp, &local_binding);
78 displaypoints[i].count = count;
79 displaypoints[i].format = format;
80 displaypoints[i].enabled = TRUE;
81 if (local_binding)
83 displaypoints[i].func = (SYMBOL_INFO*)displaypoints[i].func_buffer;
84 memset(displaypoints[i].func, 0, sizeof(SYMBOL_INFO));
85 displaypoints[i].func->SizeOfStruct = sizeof(SYMBOL_INFO);
86 displaypoints[i].func->MaxNameLen = sizeof(displaypoints[i].func_buffer) -
87 sizeof(*displaypoints[i].func);
88 if (!stack_get_current_symbol(displaypoints[i].func))
90 expr_free(displaypoints[i].exp);
91 displaypoints[i].exp = NULL;
92 return FALSE;
95 else displaypoints[i].func = NULL;
97 return TRUE;
100 BOOL display_info(void)
102 unsigned i;
103 char buffer[sizeof(SYMBOL_INFO) + 256];
104 SYMBOL_INFO* func;
105 const char* info;
107 func = (SYMBOL_INFO*)buffer;
108 memset(func, 0, sizeof(SYMBOL_INFO));
109 func->SizeOfStruct = sizeof(SYMBOL_INFO);
110 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
111 if (!stack_get_current_symbol(func)) return FALSE;
113 for (i = 0; i < ndisplays; i++)
115 if (displaypoints[i].exp == NULL) continue;
117 dbg_printf("%d: ", i + 1);
118 expr_print(displaypoints[i].exp);
120 if (displaypoints[i].enabled)
122 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
123 info = " (out of scope)";
124 else
125 info = "";
127 else
128 info = " (disabled)";
129 if (displaypoints[i].func)
130 dbg_printf(" in %s", displaypoints[i].func->Name);
131 dbg_printf("%s\n", info);
133 return TRUE;
136 static void print_one_display(int i)
138 struct dbg_lvalue lvalue;
140 if (displaypoints[i].enabled)
142 lvalue = expr_eval(displaypoints[i].exp);
143 if (lvalue.type.id == dbg_itype_none)
145 dbg_printf("Unable to evaluate expression ");
146 expr_print(displaypoints[i].exp);
147 dbg_printf("\nDisabling display %d ...\n", i + 1);
148 displaypoints[i].enabled = FALSE;
149 return;
153 dbg_printf("%d: ", i + 1);
154 expr_print(displaypoints[i].exp);
155 dbg_printf(" = ");
156 if (!displaypoints[i].enabled)
157 dbg_printf("(disabled)\n");
158 else
159 if (displaypoints[i].format == 'i')
160 memory_examine(&lvalue, displaypoints[i].count, displaypoints[i].format);
161 else
162 print_value(&lvalue, displaypoints[i].format, 0);
165 BOOL display_print(void)
167 unsigned i;
168 char buffer[sizeof(SYMBOL_INFO) + 256];
169 SYMBOL_INFO* func;
171 func = (SYMBOL_INFO*)buffer;
172 memset(func, 0, sizeof(SYMBOL_INFO));
173 func->SizeOfStruct = sizeof(SYMBOL_INFO);
174 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
175 if (!stack_get_current_symbol(func)) return FALSE;
177 for (i = 0; i < ndisplays; i++)
179 if (displaypoints[i].exp == NULL || !displaypoints[i].enabled)
180 continue;
181 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
182 continue;
183 print_one_display(i);
186 return TRUE;
189 BOOL display_delete(int displaynum)
191 if (displaynum > ndisplays || displaynum == 0 || displaynum < -1 ||
192 displaypoints[displaynum - 1].exp == NULL)
194 dbg_printf("Invalid display number\n");
195 return TRUE;
198 if (displaynum == -1)
200 unsigned i;
202 for (i = 0; i < ndisplays; i++)
204 if (displaypoints[i].exp != NULL)
206 expr_free(displaypoints[i].exp);
207 displaypoints[i].exp = NULL;
210 maxdisplays = DISPTAB_DELTA;
211 displaypoints = realloc(displaypoints,
212 (maxdisplays = DISPTAB_DELTA) * sizeof(*displaypoints));
213 ndisplays = 0;
215 else if (displaypoints[--displaynum].exp != NULL)
217 expr_free(displaypoints[displaynum].exp);
218 displaypoints[displaynum].exp = NULL;
219 while (displaynum == ndisplays - 1 && displaypoints[displaynum].exp == NULL)
221 --ndisplays;
222 --displaynum;
224 if (maxdisplays - ndisplays >= 2 * DISPTAB_DELTA)
226 /* MARK */
227 maxdisplays = (ndisplays + DISPTAB_DELTA - 1) & ~(DISPTAB_DELTA - 1);
228 displaypoints = realloc(displaypoints,
229 maxdisplays * sizeof(*displaypoints));
232 return TRUE;
235 BOOL display_enable(int displaynum, int enable)
237 char buffer[sizeof(SYMBOL_INFO) + 256];
238 SYMBOL_INFO* func;
240 func = (SYMBOL_INFO*)buffer;
241 memset(func, 0, sizeof(SYMBOL_INFO));
242 func->SizeOfStruct = sizeof(SYMBOL_INFO);
243 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
244 if (!stack_get_current_symbol(func)) return FALSE;
246 --displaynum;
247 if (displaynum >= ndisplays || displaynum < 0 ||
248 displaypoints[displaynum].exp == NULL)
250 dbg_printf("Invalid display number\n");
251 return TRUE;
254 displaypoints[displaynum].enabled = enable;
255 if (!displaypoints[displaynum].func ||
256 cmp_symbol(displaypoints[displaynum].func, func))
258 print_one_display(displaynum);
261 return TRUE;