shell32/tests: Add tests for CommandLineToArgvW.
[wine/hacks.git] / programs / winedbg / display.c
blob090196110ee637f7541483d2b3ab9dbd0fb6f8b2
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 #define OFFSET_OF(_f,_s) ((unsigned)(&(((_s*)NULL)->_f)))
45 static inline BOOL cmp_symbol(const SYMBOL_INFO* si1, const SYMBOL_INFO* si2)
47 /* FIXME: !memcmp(si1, si2, sizeof(SYMBOL_INFO) + si1->NameLen)
48 * is wrong because sizeof(SYMBOL_INFO) can be aligned on 4-byte boundary
49 * Note: we also need to zero out the structures before calling
50 * stack_get_frame, so that un-touched fields by stack_get_frame
51 * get the same value!!
53 return !memcmp(si1, si2, OFFSET_OF(Name, SYMBOL_INFO)) &&
54 !memcmp(si1->Name, si2->Name, si1->NameLen);
57 int display_add(struct expr *exp, int count, char format)
59 unsigned i;
60 BOOL local_binding = FALSE;
62 for (i = 0; i < ndisplays; i++)
63 if (displaypoints[i].exp == NULL)
64 break;
66 if (i == maxdisplays)
68 /* no space left - expand */
69 maxdisplays += DISPTAB_DELTA;
70 displaypoints = dbg_heap_realloc(displaypoints,
71 maxdisplays * sizeof(*displaypoints));
74 if (i == ndisplays) ndisplays++;
76 displaypoints[i].exp = expr_clone(exp, &local_binding);
77 displaypoints[i].count = count;
78 displaypoints[i].format = format;
79 displaypoints[i].enabled = TRUE;
80 if (local_binding)
82 displaypoints[i].func = (SYMBOL_INFO*)displaypoints[i].func_buffer;
83 memset(displaypoints[i].func, 0, sizeof(SYMBOL_INFO));
84 displaypoints[i].func->SizeOfStruct = sizeof(SYMBOL_INFO);
85 displaypoints[i].func->MaxNameLen = sizeof(displaypoints[i].func_buffer) -
86 sizeof(*displaypoints[i].func);
87 if (!stack_get_current_symbol(displaypoints[i].func))
89 expr_free(displaypoints[i].exp);
90 displaypoints[i].exp = NULL;
91 return FALSE;
94 else displaypoints[i].func = NULL;
96 return TRUE;
99 int display_info(void)
101 unsigned i;
102 char buffer[sizeof(SYMBOL_INFO) + 256];
103 SYMBOL_INFO* func;
104 const char* info;
106 func = (SYMBOL_INFO*)buffer;
107 memset(func, 0, sizeof(SYMBOL_INFO));
108 func->SizeOfStruct = sizeof(SYMBOL_INFO);
109 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
110 if (!stack_get_current_symbol(func)) return FALSE;
112 for (i = 0; i < ndisplays; i++)
114 if (displaypoints[i].exp == NULL) continue;
116 dbg_printf("%d: ", i + 1);
117 expr_print(displaypoints[i].exp);
119 if (displaypoints[i].enabled)
121 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
122 info = " (out of scope)";
123 else
124 info = "";
126 else
127 info = " (disabled)";
128 if (displaypoints[i].func)
129 dbg_printf(" in %s", displaypoints[i].func->Name);
130 dbg_printf("%s\n", info);
132 return TRUE;
135 static void print_one_display(int i)
137 struct dbg_lvalue lvalue;
139 if (displaypoints[i].enabled)
141 lvalue = expr_eval(displaypoints[i].exp);
142 if (lvalue.type.id == dbg_itype_none)
144 dbg_printf("Unable to evaluate expression ");
145 expr_print(displaypoints[i].exp);
146 dbg_printf("\nDisabling display %d ...\n", i + 1);
147 displaypoints[i].enabled = FALSE;
148 return;
152 dbg_printf("%d: ", i + 1);
153 expr_print(displaypoints[i].exp);
154 dbg_printf(" = ");
155 if (!displaypoints[i].enabled)
156 dbg_printf("(disabled)\n");
157 else
158 if (displaypoints[i].format == 'i')
159 memory_examine(&lvalue, displaypoints[i].count, displaypoints[i].format);
160 else
161 print_value(&lvalue, displaypoints[i].format, 0);
164 int display_print(void)
166 unsigned i;
167 char buffer[sizeof(SYMBOL_INFO) + 256];
168 SYMBOL_INFO* func;
170 func = (SYMBOL_INFO*)buffer;
171 memset(func, 0, sizeof(SYMBOL_INFO));
172 func->SizeOfStruct = sizeof(SYMBOL_INFO);
173 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
174 if (!stack_get_current_symbol(func)) return FALSE;
176 for (i = 0; i < ndisplays; i++)
178 if (displaypoints[i].exp == NULL || !displaypoints[i].enabled)
179 continue;
180 if (displaypoints[i].func && !cmp_symbol(displaypoints[i].func, func))
181 continue;
182 print_one_display(i);
185 return TRUE;
188 int display_delete(int displaynum)
190 if (displaynum > ndisplays || displaynum == 0 || displaynum < -1 ||
191 displaypoints[displaynum - 1].exp == NULL)
193 dbg_printf("Invalid display number\n");
194 return TRUE;
197 if (displaynum == -1)
199 unsigned i;
201 for (i = 0; i < ndisplays; i++)
203 if (displaypoints[i].exp != NULL)
205 expr_free(displaypoints[i].exp);
206 displaypoints[i].exp = NULL;
209 maxdisplays = DISPTAB_DELTA;
210 displaypoints = dbg_heap_realloc(displaypoints,
211 (maxdisplays = DISPTAB_DELTA) * sizeof(*displaypoints));
212 ndisplays = 0;
214 else if (displaypoints[--displaynum].exp != NULL)
216 expr_free(displaypoints[displaynum].exp);
217 displaypoints[displaynum].exp = NULL;
218 while (displaynum == ndisplays - 1 && displaypoints[displaynum].exp == NULL)
220 --ndisplays;
221 --displaynum;
223 if (maxdisplays - ndisplays >= 2 * DISPTAB_DELTA)
225 /* MARK */
226 maxdisplays = (ndisplays + DISPTAB_DELTA - 1) & ~(DISPTAB_DELTA - 1);
227 displaypoints = dbg_heap_realloc(displaypoints,
228 maxdisplays * sizeof(*displaypoints));
231 return TRUE;
234 int display_enable(int displaynum, int enable)
236 char buffer[sizeof(SYMBOL_INFO) + 256];
237 SYMBOL_INFO* func;
239 func = (SYMBOL_INFO*)buffer;
240 memset(func, 0, sizeof(SYMBOL_INFO));
241 func->SizeOfStruct = sizeof(SYMBOL_INFO);
242 func->MaxNameLen = sizeof(buffer) - sizeof(*func);
243 if (!stack_get_current_symbol(func)) return FALSE;
245 --displaynum;
246 if (displaynum >= ndisplays || displaynum < 0 ||
247 displaypoints[displaynum].exp == NULL)
249 dbg_printf("Invalid display number\n");
250 return TRUE;
253 displaypoints[displaynum].enabled = enable;
254 if (!displaypoints[displaynum].func ||
255 cmp_symbol(displaypoints[displaynum].func, func))
257 print_one_display(displaynum);
260 return TRUE;