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
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 #define OFFSET_OF(_f,_s) ((unsigned)(&(((_s*)NULL)->_f)))
48 static inline BOOL
cmp_symbol(const SYMBOL_INFO
* si1
, const SYMBOL_INFO
* si2
)
50 /* FIXME: !memcmp(si1, si2, sizeof(SYMBOL_INFO) + si1->NameLen)
51 * is wrong because sizeof(SYMBOL_INFO) can be aligned on 4-byte boundary
52 * Note: we also need to zero out the structures before calling
53 * stack_get_frame, so that un-touched fields by stack_get_frame
54 * get the same value!!
56 return !memcmp(si1
, si2
, OFFSET_OF(Name
, SYMBOL_INFO
)) &&
57 !memcmp(si1
->Name
, si2
->Name
, si1
->NameLen
);
60 int display_add(struct expr
*exp
, int count
, char format
)
63 BOOL local_binding
= FALSE
;
65 for (i
= 0; i
< ndisplays
; i
++)
66 if (displaypoints
[i
].exp
== NULL
)
71 /* no space left - expand */
72 maxdisplays
+= DISPTAB_DELTA
;
73 displaypoints
= dbg_heap_realloc(displaypoints
,
74 maxdisplays
* sizeof(*displaypoints
));
77 if (i
== ndisplays
) ndisplays
++;
79 displaypoints
[i
].exp
= expr_clone(exp
, &local_binding
);
80 displaypoints
[i
].count
= count
;
81 displaypoints
[i
].format
= format
;
82 displaypoints
[i
].enabled
= TRUE
;
85 displaypoints
[i
].func
= (SYMBOL_INFO
*)displaypoints
[i
].func_buffer
;
86 memset(displaypoints
[i
].func
, 0, sizeof(SYMBOL_INFO
));
87 displaypoints
[i
].func
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
88 displaypoints
[i
].func
->MaxNameLen
= sizeof(displaypoints
[i
].func_buffer
) -
89 sizeof(*displaypoints
[i
].func
);
90 if (!stack_get_current_symbol(displaypoints
[i
].func
))
92 expr_free(displaypoints
[i
].exp
);
93 displaypoints
[i
].exp
= NULL
;
97 else displaypoints
[i
].func
= NULL
;
102 int display_info(void)
105 char buffer
[sizeof(SYMBOL_INFO
) + 256];
109 func
= (SYMBOL_INFO
*)buffer
;
110 memset(func
, 0, sizeof(SYMBOL_INFO
));
111 func
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
112 func
->MaxNameLen
= sizeof(buffer
) - sizeof(*func
);
113 if (!stack_get_current_symbol(func
)) return FALSE
;
115 for (i
= 0; i
< ndisplays
; i
++)
117 if (displaypoints
[i
].exp
== NULL
) continue;
119 dbg_printf("%d: ", i
+ 1);
120 expr_print(displaypoints
[i
].exp
);
122 if (displaypoints
[i
].enabled
)
124 if (displaypoints
[i
].func
&& !cmp_symbol(displaypoints
[i
].func
, func
))
125 info
= " (out of scope)";
130 info
= " (disabled)";
131 if (displaypoints
[i
].func
)
132 dbg_printf(" in %s", displaypoints
[i
].func
->Name
);
133 dbg_printf("%s\n", info
);
138 static void print_one_display(int i
)
140 struct dbg_lvalue lvalue
;
142 if (displaypoints
[i
].enabled
)
144 lvalue
= expr_eval(displaypoints
[i
].exp
);
145 if (lvalue
.type
.id
== dbg_itype_none
)
147 dbg_printf("Unable to evaluate expression ");
148 expr_print(displaypoints
[i
].exp
);
149 dbg_printf("\nDisabling display %d ...\n", i
+ 1);
150 displaypoints
[i
].enabled
= FALSE
;
155 dbg_printf("%d: ", i
+ 1);
156 expr_print(displaypoints
[i
].exp
);
158 if (!displaypoints
[i
].enabled
)
159 dbg_printf("(disabled)\n");
161 if (displaypoints
[i
].format
== 'i')
162 memory_examine(&lvalue
, displaypoints
[i
].count
, displaypoints
[i
].format
);
164 print_value(&lvalue
, displaypoints
[i
].format
, 0);
167 int display_print(void)
170 char buffer
[sizeof(SYMBOL_INFO
) + 256];
173 func
= (SYMBOL_INFO
*)buffer
;
174 memset(func
, 0, sizeof(SYMBOL_INFO
));
175 func
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
176 func
->MaxNameLen
= sizeof(buffer
) - sizeof(*func
);
177 if (!stack_get_current_symbol(func
)) return FALSE
;
179 for (i
= 0; i
< ndisplays
; i
++)
181 if (displaypoints
[i
].exp
== NULL
|| !displaypoints
[i
].enabled
)
183 if (displaypoints
[i
].func
&& !cmp_symbol(displaypoints
[i
].func
, func
))
185 print_one_display(i
);
191 int display_delete(int displaynum
)
195 if (displaynum
> ndisplays
|| displaynum
== 0 || displaynum
< -1 ||
196 displaypoints
[displaynum
- 1].exp
== NULL
)
198 dbg_printf("Invalid display number\n");
202 if (displaynum
== -1)
204 for (i
= 0; i
< ndisplays
; i
++)
206 if (displaypoints
[i
].exp
!= NULL
)
208 expr_free(displaypoints
[i
].exp
);
209 displaypoints
[i
].exp
= NULL
;
212 maxdisplays
= DISPTAB_DELTA
;
213 displaypoints
= dbg_heap_realloc(displaypoints
,
214 (maxdisplays
= DISPTAB_DELTA
) * sizeof(*displaypoints
));
217 else if (displaypoints
[--displaynum
].exp
!= NULL
)
219 expr_free(displaypoints
[displaynum
].exp
);
220 displaypoints
[displaynum
].exp
= NULL
;
221 while (displaynum
== ndisplays
- 1 && displaypoints
[displaynum
].exp
== NULL
)
226 if (maxdisplays
- ndisplays
>= 2 * DISPTAB_DELTA
)
229 maxdisplays
= (ndisplays
+ DISPTAB_DELTA
- 1) & ~(DISPTAB_DELTA
- 1);
230 displaypoints
= dbg_heap_realloc(displaypoints
,
231 maxdisplays
* sizeof(*displaypoints
));
237 int display_enable(int displaynum
, int enable
)
239 char buffer
[sizeof(SYMBOL_INFO
) + 256];
242 func
= (SYMBOL_INFO
*)buffer
;
243 memset(func
, 0, sizeof(SYMBOL_INFO
));
244 func
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
245 func
->MaxNameLen
= sizeof(buffer
) - sizeof(*func
);
246 if (!stack_get_current_symbol(func
)) return FALSE
;
249 if (displaynum
>= ndisplays
|| displaynum
< 0 ||
250 displaypoints
[displaynum
].exp
== NULL
)
252 dbg_printf("Invalid display number\n");
256 displaypoints
[displaynum
].enabled
= enable
;
257 if (!displaypoints
[displaynum
].func
||
258 cmp_symbol(displaypoints
[displaynum
].func
, func
))
260 print_one_display(displaynum
);