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
25 #include <sys/types.h>
31 #define DISPTAB_DELTA 8 /* needs to be power of 2, search for MARK to see why :) */
38 struct name_hash
*function_name
;
41 static struct display
*displaypoints
= NULL
;
42 static unsigned int maxdisplays
= 0, ndisplays
= 0;
44 static struct name_hash
*DEBUG_GetCurrentFrameFunctionName(void)
46 struct name_hash
*name
;
47 unsigned int eip
, ebp
;
49 if (DEBUG_GetCurrentFrame(&name
, &eip
, &ebp
))
54 int DEBUG_AddDisplay(struct expr
*exp
, int count
, char format
, int in_frame
)
58 for (i
= 0; i
< ndisplays
; i
++)
59 if (displaypoints
[i
].exp
== NULL
)
62 if (i
== maxdisplays
) /* no space left - expand */
63 displaypoints
= DBG_realloc(displaypoints
,
64 (maxdisplays
+= DISPTAB_DELTA
) * sizeof(*displaypoints
));
69 displaypoints
[i
].exp
= DEBUG_CloneExpr(exp
);
70 displaypoints
[i
].count
= count
;
71 displaypoints
[i
].format
= format
;
72 displaypoints
[i
].enabled
= TRUE
;
73 displaypoints
[i
].function_name
=
74 (in_frame
? DEBUG_GetCurrentFrameFunctionName() : NULL
);
79 int DEBUG_InfoDisplay(void)
83 for (i
= 0; i
< ndisplays
; i
++) {
84 if (displaypoints
[i
].exp
== NULL
)
87 if (displaypoints
[i
].function_name
)
88 DEBUG_Printf("%d in %s%s : ", i
+ 1,
89 DEBUG_GetSymbolName(displaypoints
[i
].function_name
),
90 (displaypoints
[i
].enabled
?
91 (displaypoints
[i
].function_name
!= DEBUG_GetCurrentFrameFunctionName() ?
92 " (out of scope)" : "")
96 DEBUG_Printf("%d%s : ", i
+ 1,
97 (displaypoints
[i
].enabled
? "" : " (disabled)"));
98 DEBUG_DisplayExpr(displaypoints
[i
].exp
);
105 void DEBUG_PrintOneDisplay(int i
)
109 if (displaypoints
[i
].enabled
) {
110 value
= DEBUG_EvalExpr(displaypoints
[i
].exp
);
111 if (value
.type
== NULL
) {
112 DEBUG_Printf("Unable to evaluate expression ");
113 DEBUG_DisplayExpr(displaypoints
[i
].exp
);
114 DEBUG_Printf("\nDisabling display %d ...\n", i
+ 1);
115 displaypoints
[i
].enabled
= FALSE
;
120 DEBUG_Printf("%d : ", i
+ 1);
121 DEBUG_DisplayExpr(displaypoints
[i
].exp
);
123 if (!displaypoints
[i
].enabled
)
124 DEBUG_Printf("(disabled)\n");
126 if (displaypoints
[i
].format
== 'i')
127 DEBUG_ExamineMemory(&value
, displaypoints
[i
].count
, displaypoints
[i
].format
);
129 DEBUG_Print(&value
, displaypoints
[i
].count
, displaypoints
[i
].format
, 0);
132 int DEBUG_DoDisplay(void)
135 struct name_hash
*cur_function_name
= DEBUG_GetCurrentFrameFunctionName();
137 for (i
= 0; i
< ndisplays
; i
++) {
138 if (displaypoints
[i
].exp
== NULL
|| !displaypoints
[i
].enabled
)
140 if (displaypoints
[i
].function_name
141 && displaypoints
[i
].function_name
!= cur_function_name
)
143 DEBUG_PrintOneDisplay(i
);
149 int DEBUG_DelDisplay(int displaynum
)
153 if (displaynum
> ndisplays
|| displaynum
== 0 || displaynum
< -1
154 || displaypoints
[displaynum
- 1].exp
== NULL
) {
155 DEBUG_Printf("Invalid display number\n");
159 if (displaynum
== -1) {
160 for (i
= 0; i
< ndisplays
; i
++) {
161 if (displaypoints
[i
].exp
!= NULL
) {
162 DEBUG_FreeExpr(displaypoints
[i
].exp
);
163 displaypoints
[i
].exp
= NULL
;
166 displaypoints
= DBG_realloc(displaypoints
,
167 (maxdisplays
= DISPTAB_DELTA
) * sizeof(*displaypoints
));
169 } else if (displaypoints
[--displaynum
].exp
!= NULL
) {
170 DEBUG_FreeExpr(displaypoints
[displaynum
].exp
);
171 displaypoints
[displaynum
].exp
= NULL
;
172 while (displaynum
== ndisplays
- 1
173 && displaypoints
[displaynum
].exp
== NULL
)
174 --ndisplays
, --displaynum
;
175 if (maxdisplays
- ndisplays
>= 2 * DISPTAB_DELTA
) {
176 maxdisplays
= (ndisplays
+ DISPTAB_DELTA
- 1) & ~(DISPTAB_DELTA
- 1); /* MARK */
177 displaypoints
= DBG_realloc(displaypoints
,
178 maxdisplays
* sizeof(*displaypoints
));
184 int DEBUG_EnableDisplay(int displaynum
, int enable
)
187 if (displaynum
>= ndisplays
|| displaynum
< 0 || displaypoints
[displaynum
].exp
== NULL
) {
188 DEBUG_Printf("Invalid display number\n");
192 displaypoints
[displaynum
].enabled
= enable
;
193 if (!displaypoints
[displaynum
].function_name
194 || displaypoints
[displaynum
].function_name
== DEBUG_GetCurrentFrameFunctionName())
195 DEBUG_PrintOneDisplay(displaynum
);