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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
, int in_frame
)
64 for (i
= 0; i
< ndisplays
; i
++)
65 if (displaypoints
[i
].exp
== NULL
)
70 /* no space left - expand */
71 maxdisplays
+= DISPTAB_DELTA
;
72 displaypoints
= dbg_heap_realloc(displaypoints
,
73 maxdisplays
* sizeof(*displaypoints
));
76 if (i
== ndisplays
) ndisplays
++;
78 displaypoints
[i
].exp
= expr_clone(exp
);
79 displaypoints
[i
].count
= count
;
80 displaypoints
[i
].format
= format
;
81 displaypoints
[i
].enabled
= TRUE
;
84 displaypoints
[i
].func
= (SYMBOL_INFO
*)displaypoints
[i
].func_buffer
;
85 memset(displaypoints
[i
].func
, 0, sizeof(SYMBOL_INFO
));
86 displaypoints
[i
].func
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
87 displaypoints
[i
].func
->MaxNameLen
= sizeof(displaypoints
[i
].func_buffer
) -
88 sizeof(*displaypoints
[i
].func
);
89 if (!stack_get_frame(displaypoints
[i
].func
, NULL
))
91 expr_free(displaypoints
[i
].exp
);
92 displaypoints
[i
].exp
= NULL
;
96 else displaypoints
[i
].func
= NULL
;
101 int display_info(void)
104 char buffer
[sizeof(SYMBOL_INFO
) + 256];
108 func
= (SYMBOL_INFO
*)buffer
;
109 memset(func
, 0, sizeof(SYMBOL_INFO
));
110 func
->SizeOfStruct
= sizeof(SYMBOL_INFO
);
111 func
->MaxNameLen
= sizeof(buffer
) - sizeof(*func
);
112 if (!stack_get_frame(func
, NULL
)) return FALSE
;
114 for (i
= 0; i
< ndisplays
; i
++)
116 if (displaypoints
[i
].exp
== NULL
) continue;
118 dbg_printf("%d: ", i
+ 1);
119 expr_print(displaypoints
[i
].exp
);
121 if (displaypoints
[i
].enabled
)
123 if (displaypoints
[i
].func
&& !cmp_symbol(displaypoints
[i
].func
, func
))
124 info
= " (out of scope)";
129 info
= " (disabled)";
130 if (displaypoints
[i
].func
)
131 dbg_printf(" in %s", displaypoints
[i
].func
->Name
);
132 dbg_printf("%s\n", info
);
137 static void print_one_display(int i
)
139 struct dbg_lvalue lvalue
;
141 if (displaypoints
[i
].enabled
)
143 lvalue
= expr_eval(displaypoints
[i
].exp
);
144 if (lvalue
.type
.id
== dbg_itype_none
)
146 dbg_printf("Unable to evaluate expression ");
147 expr_print(displaypoints
[i
].exp
);
148 dbg_printf("\nDisabling display %d ...\n", i
+ 1);
149 displaypoints
[i
].enabled
= FALSE
;
154 dbg_printf("%d: ", i
+ 1);
155 expr_print(displaypoints
[i
].exp
);
157 if (!displaypoints
[i
].enabled
)
158 dbg_printf("(disabled)\n");
160 if (displaypoints
[i
].format
== 'i')
161 memory_examine((void*)types_extract_as_integer(&lvalue
),
162 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_frame(func
, NULL
)) 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_frame(func
, NULL
)) 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
);