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 BOOL
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
)
67 /* no space left - expand */
68 new = realloc(displaypoints
,
69 (maxdisplays
+ DISPTAB_DELTA
) * sizeof(*displaypoints
));
70 if (!new) return FALSE
;
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
;
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
;
95 else displaypoints
[i
].func
= NULL
;
100 BOOL
display_info(void)
103 char buffer
[sizeof(SYMBOL_INFO
) + 256];
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)";
128 info
= " (disabled)";
129 if (displaypoints
[i
].func
)
130 dbg_printf(" in %s", displaypoints
[i
].func
->Name
);
131 dbg_printf("%s\n", info
);
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
;
153 dbg_printf("%d: ", i
+ 1);
154 expr_print(displaypoints
[i
].exp
);
156 if (!displaypoints
[i
].enabled
)
157 dbg_printf("(disabled)\n");
159 if (displaypoints
[i
].format
== 'i')
160 memory_examine(&lvalue
, displaypoints
[i
].count
, displaypoints
[i
].format
);
162 print_value(&lvalue
, displaypoints
[i
].format
, 0);
165 BOOL
display_print(void)
168 char buffer
[sizeof(SYMBOL_INFO
) + 256];
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
)
181 if (displaypoints
[i
].func
&& !cmp_symbol(displaypoints
[i
].func
, func
))
183 print_one_display(i
);
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");
198 if (displaynum
== -1)
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
));
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
)
224 if (maxdisplays
- ndisplays
>= 2 * DISPTAB_DELTA
)
227 maxdisplays
= (ndisplays
+ DISPTAB_DELTA
- 1) & ~(DISPTAB_DELTA
- 1);
228 displaypoints
= realloc(displaypoints
,
229 maxdisplays
* sizeof(*displaypoints
));
235 BOOL
display_enable(int displaynum
, int enable
)
237 char buffer
[sizeof(SYMBOL_INFO
) + 256];
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
;
247 if (displaynum
>= ndisplays
|| displaynum
< 0 ||
248 displaypoints
[displaynum
].exp
== NULL
)
250 dbg_printf("Invalid display number\n");
254 displaypoints
[displaynum
].enabled
= enable
;
255 if (!displaypoints
[displaynum
].func
||
256 cmp_symbol(displaypoints
[displaynum
].func
, func
))
258 print_one_display(displaynum
);