Commit | Line | Data |
---|---|---|
f377b406 SC |
1 | /* TUI display registers in window. |
2 | Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc. | |
3 | Contributed by Hewlett-Packard Company. | |
c906108c | 4 | |
f377b406 | 5 | This file is part of GDB. |
c906108c | 6 | |
f377b406 SC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program 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 | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "tui.h" | |
24 | #include "tuiData.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "gdbcmd.h" | |
28 | #include "frame.h" | |
29 | #include "inferior.h" | |
30 | #include "target.h" | |
31 | #include "tuiLayout.h" | |
32 | #include "tuiWin.h" | |
e8b915dc SC |
33 | #include "tuiDataWin.h" |
34 | #include "tuiGeneralWin.h" | |
c46cc7df | 35 | #include "tui-file.h" |
c906108c SS |
36 | |
37 | /***************************************** | |
38 | ** LOCAL DEFINITIONS ** | |
39 | ******************************************/ | |
40 | #define DOUBLE_FLOAT_LABEL_WIDTH 6 | |
41 | #define DOUBLE_FLOAT_LABEL_FMT "%6.6s: " | |
42 | #define DOUBLE_FLOAT_VALUE_WIDTH 30 /*min of 16 but may be in sci notation */ | |
43 | ||
44 | #define SINGLE_FLOAT_LABEL_WIDTH 6 | |
45 | #define SINGLE_FLOAT_LABEL_FMT "%6.6s: " | |
46 | #define SINGLE_FLOAT_VALUE_WIDTH 25 /* min of 8 but may be in sci notation */ | |
47 | ||
c46cc7df | 48 | #define SINGLE_LABEL_WIDTH 16 |
c906108c | 49 | #define SINGLE_LABEL_FMT "%10.10s: " |
c46cc7df | 50 | #define SINGLE_VALUE_WIDTH 20 /* minimum of 8 but may be in sci notation */ |
c906108c SS |
51 | |
52 | /* In the code HP gave Cygnus, this was actually a function call to a | |
53 | PA-specific function, which was supposed to determine whether the | |
54 | target was a 64-bit or 32-bit processor. However, the 64-bit | |
55 | support wasn't complete, so we didn't merge that in, so we leave | |
56 | this here as a stub. */ | |
57 | #define IS_64BIT 0 | |
58 | ||
59 | /***************************************** | |
60 | ** STATIC DATA ** | |
61 | ******************************************/ | |
62 | ||
63 | ||
64 | /***************************************** | |
65 | ** STATIC LOCAL FUNCTIONS FORWARD DECLS ** | |
66 | ******************************************/ | |
67 | static TuiStatus _tuiSetRegsContent | |
a14ed312 KB |
68 | (int, int, struct frame_info *, TuiRegisterDisplayType, int); |
69 | static char *_tuiRegisterName (int); | |
70 | static TuiStatus _tuiGetRegisterRawValue (int, char *, struct frame_info *); | |
c906108c | 71 | static void _tuiSetRegisterElement |
a14ed312 KB |
72 | (int, struct frame_info *, TuiDataElementPtr, int); |
73 | static void _tuiDisplayRegister (int, TuiGenWinInfoPtr, enum precision_type); | |
c906108c | 74 | static void _tuiRegisterFormat |
a14ed312 KB |
75 | (char *, int, int, TuiDataElementPtr, enum precision_type); |
76 | static TuiStatus _tuiSetGeneralRegsContent (int); | |
77 | static TuiStatus _tuiSetSpecialRegsContent (int); | |
78 | static TuiStatus _tuiSetGeneralAndSpecialRegsContent (int); | |
79 | static TuiStatus _tuiSetFloatRegsContent (TuiRegisterDisplayType, int); | |
c906108c | 80 | static int _tuiRegValueHasChanged |
a14ed312 KB |
81 | (TuiDataElementPtr, struct frame_info *, char *); |
82 | static void _tuiShowFloat_command (char *, int); | |
83 | static void _tuiShowGeneral_command (char *, int); | |
84 | static void _tuiShowSpecial_command (char *, int); | |
e8b915dc | 85 | static void _tui_vShowRegisters_commandSupport (TuiRegisterDisplayType); |
a14ed312 KB |
86 | static void _tuiToggleFloatRegs_command (char *, int); |
87 | static void _tuiScrollRegsForward_command (char *, int); | |
88 | static void _tuiScrollRegsBackward_command (char *, int); | |
c906108c SS |
89 | |
90 | ||
91 | ||
92 | /***************************************** | |
93 | ** PUBLIC FUNCTIONS ** | |
94 | ******************************************/ | |
95 | ||
96 | /* | |
c5aa993b JM |
97 | ** tuiLastRegsLineNo() |
98 | ** Answer the number of the last line in the regs display. | |
99 | ** If there are no registers (-1) is returned. | |
100 | */ | |
c906108c | 101 | int |
c906108c | 102 | tuiLastRegsLineNo (void) |
c906108c SS |
103 | { |
104 | register int numLines = (-1); | |
105 | ||
106 | if (dataWin->detail.dataDisplayInfo.regsContentCount > 0) | |
107 | { | |
108 | numLines = (dataWin->detail.dataDisplayInfo.regsContentCount / | |
109 | dataWin->detail.dataDisplayInfo.regsColumnCount); | |
110 | if (dataWin->detail.dataDisplayInfo.regsContentCount % | |
111 | dataWin->detail.dataDisplayInfo.regsColumnCount) | |
112 | numLines++; | |
113 | } | |
114 | return numLines; | |
115 | } /* tuiLastRegsLineNo */ | |
116 | ||
117 | ||
118 | /* | |
c5aa993b JM |
119 | ** tuiLineFromRegElementNo() |
120 | ** Answer the line number that the register element at elementNo is | |
121 | ** on. If elementNo is greater than the number of register elements | |
122 | ** there are, -1 is returned. | |
123 | */ | |
c906108c | 124 | int |
eca6576c | 125 | tuiLineFromRegElementNo (int elementNo) |
c906108c SS |
126 | { |
127 | if (elementNo < dataWin->detail.dataDisplayInfo.regsContentCount) | |
128 | { | |
129 | int i, line = (-1); | |
130 | ||
131 | i = 1; | |
132 | while (line == (-1)) | |
133 | { | |
134 | if (elementNo < | |
135 | (dataWin->detail.dataDisplayInfo.regsColumnCount * i)) | |
136 | line = i - 1; | |
137 | else | |
138 | i++; | |
139 | } | |
140 | ||
141 | return line; | |
142 | } | |
143 | else | |
144 | return (-1); | |
145 | } /* tuiLineFromRegElementNo */ | |
146 | ||
147 | ||
148 | /* | |
c5aa993b JM |
149 | ** tuiFirstRegElementNoInLine() |
150 | ** Answer the index of the first element in lineNo. If lineNo is | |
151 | ** past the register area (-1) is returned. | |
152 | */ | |
c906108c | 153 | int |
eca6576c | 154 | tuiFirstRegElementNoInLine (int lineNo) |
c906108c SS |
155 | { |
156 | if ((lineNo * dataWin->detail.dataDisplayInfo.regsColumnCount) | |
157 | <= dataWin->detail.dataDisplayInfo.regsContentCount) | |
158 | return ((lineNo + 1) * | |
159 | dataWin->detail.dataDisplayInfo.regsColumnCount) - | |
160 | dataWin->detail.dataDisplayInfo.regsColumnCount; | |
161 | else | |
162 | return (-1); | |
163 | } /* tuiFirstRegElementNoInLine */ | |
164 | ||
165 | ||
166 | /* | |
c5aa993b JM |
167 | ** tuiLastRegElementNoInLine() |
168 | ** Answer the index of the last element in lineNo. If lineNo is past | |
169 | ** the register area (-1) is returned. | |
170 | */ | |
c906108c | 171 | int |
eca6576c | 172 | tuiLastRegElementNoInLine (int lineNo) |
c906108c SS |
173 | { |
174 | if ((lineNo * dataWin->detail.dataDisplayInfo.regsColumnCount) <= | |
175 | dataWin->detail.dataDisplayInfo.regsContentCount) | |
176 | return ((lineNo + 1) * | |
177 | dataWin->detail.dataDisplayInfo.regsColumnCount) - 1; | |
178 | else | |
179 | return (-1); | |
180 | } /* tuiLastRegElementNoInLine */ | |
181 | ||
182 | ||
183 | /* | |
c5aa993b JM |
184 | ** tuiCalculateRegsColumnCount |
185 | ** Calculate the number of columns that should be used to display | |
186 | ** the registers. | |
187 | */ | |
c906108c | 188 | int |
eca6576c | 189 | tuiCalculateRegsColumnCount (TuiRegisterDisplayType dpyType) |
c906108c SS |
190 | { |
191 | int colCount, colWidth; | |
192 | ||
193 | if (IS_64BIT || dpyType == TUI_DFLOAT_REGS) | |
194 | colWidth = DOUBLE_FLOAT_VALUE_WIDTH + DOUBLE_FLOAT_LABEL_WIDTH; | |
195 | else | |
196 | { | |
197 | if (dpyType == TUI_SFLOAT_REGS) | |
198 | colWidth = SINGLE_FLOAT_VALUE_WIDTH + SINGLE_FLOAT_LABEL_WIDTH; | |
199 | else | |
200 | colWidth = SINGLE_VALUE_WIDTH + SINGLE_LABEL_WIDTH; | |
201 | } | |
202 | colCount = (dataWin->generic.width - 2) / colWidth; | |
203 | ||
204 | return colCount; | |
205 | } /* tuiCalulateRegsColumnCount */ | |
206 | ||
207 | ||
208 | /* | |
c5aa993b JM |
209 | ** tuiShowRegisters(). |
210 | ** Show the registers int the data window as indicated by dpyType. | |
211 | ** If there is any other registers being displayed, then they are | |
212 | ** cleared. What registers are displayed is dependent upon dpyType. | |
213 | */ | |
c906108c | 214 | void |
eca6576c | 215 | tuiShowRegisters (TuiRegisterDisplayType dpyType) |
c906108c SS |
216 | { |
217 | TuiStatus ret = TUI_FAILURE; | |
218 | int refreshValuesOnly = FALSE; | |
219 | ||
220 | /* Say that registers should be displayed, even if there is a problem */ | |
221 | dataWin->detail.dataDisplayInfo.displayRegs = TRUE; | |
222 | ||
223 | if (target_has_registers) | |
224 | { | |
225 | refreshValuesOnly = | |
226 | (dpyType == dataWin->detail.dataDisplayInfo.regsDisplayType); | |
227 | switch (dpyType) | |
228 | { | |
229 | case TUI_GENERAL_REGS: | |
230 | ret = _tuiSetGeneralRegsContent (refreshValuesOnly); | |
231 | break; | |
232 | case TUI_SFLOAT_REGS: | |
233 | case TUI_DFLOAT_REGS: | |
234 | ret = _tuiSetFloatRegsContent (dpyType, refreshValuesOnly); | |
235 | break; | |
236 | ||
237 | /* could ifdef out */ | |
238 | ||
239 | case TUI_SPECIAL_REGS: | |
240 | ret = _tuiSetSpecialRegsContent (refreshValuesOnly); | |
241 | break; | |
242 | case TUI_GENERAL_AND_SPECIAL_REGS: | |
243 | ret = _tuiSetGeneralAndSpecialRegsContent (refreshValuesOnly); | |
244 | break; | |
245 | ||
246 | /* end of potential if def */ | |
247 | ||
248 | default: | |
249 | break; | |
250 | } | |
251 | } | |
252 | if (ret == TUI_FAILURE) | |
253 | { | |
254 | dataWin->detail.dataDisplayInfo.regsDisplayType = TUI_UNDEFINED_REGS; | |
255 | tuiEraseDataContent (NO_REGS_STRING); | |
256 | } | |
257 | else | |
258 | { | |
259 | int i; | |
260 | ||
261 | /* Clear all notation of changed values */ | |
262 | for (i = 0; (i < dataWin->detail.dataDisplayInfo.regsContentCount); i++) | |
263 | { | |
264 | TuiGenWinInfoPtr dataItemWin; | |
265 | ||
266 | dataItemWin = &dataWin->detail.dataDisplayInfo. | |
267 | regsContent[i]->whichElement.dataWindow; | |
268 | (&((TuiWinElementPtr) | |
269 | dataItemWin->content[0])->whichElement.data)->highlight = FALSE; | |
270 | } | |
271 | dataWin->detail.dataDisplayInfo.regsDisplayType = dpyType; | |
272 | tuiDisplayAllData (); | |
273 | } | |
274 | (tuiLayoutDef ())->regsDisplayType = dpyType; | |
275 | ||
276 | return; | |
277 | } /* tuiShowRegisters */ | |
278 | ||
279 | ||
280 | /* | |
c5aa993b JM |
281 | ** tuiDisplayRegistersFrom(). |
282 | ** Function to display the registers in the content from | |
283 | ** 'startElementNo' until the end of the register content or the | |
284 | ** end of the display height. No checking for displaying past | |
285 | ** the end of the registers is done here. | |
286 | */ | |
c906108c | 287 | void |
eca6576c | 288 | tuiDisplayRegistersFrom (int startElementNo) |
c906108c SS |
289 | { |
290 | if (dataWin->detail.dataDisplayInfo.regsContent != (TuiWinContent) NULL && | |
291 | dataWin->detail.dataDisplayInfo.regsContentCount > 0) | |
292 | { | |
293 | register int i = startElementNo; | |
294 | int j, valueCharsWide, charsWide, itemWinWidth, curY, labelWidth; | |
295 | enum precision_type precision; | |
296 | ||
297 | precision = (dataWin->detail.dataDisplayInfo.regsDisplayType | |
298 | == TUI_DFLOAT_REGS) ? | |
299 | double_precision : unspecified_precision; | |
300 | if (IS_64BIT || | |
301 | dataWin->detail.dataDisplayInfo.regsDisplayType == TUI_DFLOAT_REGS) | |
302 | { | |
303 | valueCharsWide = DOUBLE_FLOAT_VALUE_WIDTH; | |
304 | labelWidth = DOUBLE_FLOAT_LABEL_WIDTH; | |
305 | } | |
306 | else | |
307 | { | |
308 | if (dataWin->detail.dataDisplayInfo.regsDisplayType == | |
309 | TUI_SFLOAT_REGS) | |
310 | { | |
311 | valueCharsWide = SINGLE_FLOAT_VALUE_WIDTH; | |
312 | labelWidth = SINGLE_FLOAT_LABEL_WIDTH; | |
313 | } | |
314 | else | |
315 | { | |
316 | valueCharsWide = SINGLE_VALUE_WIDTH; | |
317 | labelWidth = SINGLE_LABEL_WIDTH; | |
318 | } | |
319 | } | |
320 | itemWinWidth = valueCharsWide + labelWidth; | |
321 | /* | |
c5aa993b JM |
322 | ** Now create each data "sub" window, and write the display into it. |
323 | */ | |
c906108c SS |
324 | curY = 1; |
325 | while (i < dataWin->detail.dataDisplayInfo.regsContentCount && | |
326 | curY <= dataWin->generic.viewportHeight) | |
327 | { | |
328 | for (j = 0; | |
329 | (j < dataWin->detail.dataDisplayInfo.regsColumnCount && | |
330 | i < dataWin->detail.dataDisplayInfo.regsContentCount); j++) | |
331 | { | |
332 | TuiGenWinInfoPtr dataItemWin; | |
333 | TuiDataElementPtr dataElementPtr; | |
334 | ||
c5aa993b | 335 | /* create the window if necessary */ |
c906108c SS |
336 | dataItemWin = &dataWin->detail.dataDisplayInfo. |
337 | regsContent[i]->whichElement.dataWindow; | |
338 | dataElementPtr = &((TuiWinElementPtr) | |
339 | dataItemWin->content[0])->whichElement.data; | |
340 | if (dataItemWin->handle == (WINDOW *) NULL) | |
341 | { | |
342 | dataItemWin->height = 1; | |
343 | dataItemWin->width = (precision == double_precision) ? | |
344 | itemWinWidth + 2 : itemWinWidth + 1; | |
345 | dataItemWin->origin.x = (itemWinWidth * j) + 1; | |
346 | dataItemWin->origin.y = curY; | |
347 | makeWindow (dataItemWin, DONT_BOX_WINDOW); | |
c46cc7df | 348 | scrollok (dataItemWin->handle, FALSE); |
c906108c SS |
349 | } |
350 | /* | |
c5aa993b JM |
351 | ** Get the printable representation of the register |
352 | ** and display it | |
353 | */ | |
c906108c SS |
354 | _tuiDisplayRegister ( |
355 | dataElementPtr->itemNo, dataItemWin, precision); | |
356 | i++; /* next register */ | |
357 | } | |
358 | curY++; /* next row; */ | |
359 | } | |
360 | } | |
361 | ||
362 | return; | |
363 | } /* tuiDisplayRegistersFrom */ | |
364 | ||
365 | ||
366 | /* | |
c5aa993b JM |
367 | ** tuiDisplayRegElementAtLine(). |
368 | ** Function to display the registers in the content from | |
369 | ** 'startElementNo' on 'startLineNo' until the end of the | |
370 | ** register content or the end of the display height. | |
371 | ** This function checks that we won't display off the end | |
372 | ** of the register display. | |
373 | */ | |
c906108c | 374 | void |
eca6576c | 375 | tuiDisplayRegElementAtLine (int startElementNo, int startLineNo) |
c906108c SS |
376 | { |
377 | if (dataWin->detail.dataDisplayInfo.regsContent != (TuiWinContent) NULL && | |
378 | dataWin->detail.dataDisplayInfo.regsContentCount > 0) | |
379 | { | |
380 | register int elementNo = startElementNo; | |
381 | ||
382 | if (startElementNo != 0 && startLineNo != 0) | |
383 | { | |
384 | register int lastLineNo, firstLineOnLastPage; | |
385 | ||
386 | lastLineNo = tuiLastRegsLineNo (); | |
387 | firstLineOnLastPage = lastLineNo - (dataWin->generic.height - 2); | |
388 | if (firstLineOnLastPage < 0) | |
389 | firstLineOnLastPage = 0; | |
390 | /* | |
c5aa993b JM |
391 | ** If there is no other data displayed except registers, |
392 | ** and the elementNo causes us to scroll past the end of the | |
393 | ** registers, adjust what element to really start the display at. | |
394 | */ | |
c906108c SS |
395 | if (dataWin->detail.dataDisplayInfo.dataContentCount <= 0 && |
396 | startLineNo > firstLineOnLastPage) | |
397 | elementNo = tuiFirstRegElementNoInLine (firstLineOnLastPage); | |
398 | } | |
399 | tuiDisplayRegistersFrom (elementNo); | |
400 | } | |
401 | ||
402 | return; | |
403 | } /* tuiDisplayRegElementAtLine */ | |
404 | ||
405 | ||
406 | ||
407 | /* | |
c5aa993b JM |
408 | ** tuiDisplayRegistersFromLine(). |
409 | ** Function to display the registers starting at line lineNo in | |
410 | ** the data window. Answers the line number that the display | |
411 | ** actually started from. If nothing is displayed (-1) is returned. | |
412 | */ | |
c906108c | 413 | int |
eca6576c | 414 | tuiDisplayRegistersFromLine (int lineNo, int forceDisplay) |
c906108c SS |
415 | { |
416 | int elementNo; | |
417 | ||
418 | if (dataWin->detail.dataDisplayInfo.regsContentCount > 0) | |
419 | { | |
420 | int line, elementNo; | |
421 | ||
422 | if (lineNo < 0) | |
423 | line = 0; | |
424 | else if (forceDisplay) | |
425 | { /* | |
c5aa993b JM |
426 | ** If we must display regs (forceDisplay is true), then make |
427 | ** sure that we don't display off the end of the registers. | |
428 | */ | |
c906108c SS |
429 | if (lineNo >= tuiLastRegsLineNo ()) |
430 | { | |
431 | if ((line = tuiLineFromRegElementNo ( | |
432 | dataWin->detail.dataDisplayInfo.regsContentCount - 1)) < 0) | |
433 | line = 0; | |
434 | } | |
435 | else | |
436 | line = lineNo; | |
437 | } | |
438 | else | |
439 | line = lineNo; | |
440 | ||
441 | elementNo = tuiFirstRegElementNoInLine (line); | |
442 | if (elementNo < dataWin->detail.dataDisplayInfo.regsContentCount) | |
443 | tuiDisplayRegElementAtLine (elementNo, line); | |
444 | else | |
445 | line = (-1); | |
446 | ||
447 | return line; | |
448 | } | |
449 | ||
450 | return (-1); /* nothing was displayed */ | |
451 | } /* tuiDisplayRegistersFromLine */ | |
452 | ||
453 | ||
454 | /* | |
c5aa993b JM |
455 | ** tuiCheckRegisterValues() |
456 | ** This function check all displayed registers for changes in | |
457 | ** values, given a particular frame. If the values have changed, | |
458 | ** they are updated with the new value and highlighted. | |
459 | */ | |
c906108c | 460 | void |
eca6576c | 461 | tuiCheckRegisterValues (struct frame_info *frame) |
c906108c SS |
462 | { |
463 | if (m_winPtrNotNull (dataWin) && dataWin->generic.isVisible) | |
464 | { | |
465 | if (dataWin->detail.dataDisplayInfo.regsContentCount <= 0 && | |
466 | dataWin->detail.dataDisplayInfo.displayRegs) | |
467 | tuiShowRegisters ((tuiLayoutDef ())->regsDisplayType); | |
468 | else | |
469 | { | |
470 | int i, j; | |
471 | char rawBuf[MAX_REGISTER_RAW_SIZE]; | |
472 | ||
473 | for (i = 0; | |
474 | (i < dataWin->detail.dataDisplayInfo.regsContentCount); i++) | |
475 | { | |
476 | TuiDataElementPtr dataElementPtr; | |
477 | TuiGenWinInfoPtr dataItemWinPtr; | |
478 | int wasHilighted; | |
479 | ||
480 | dataItemWinPtr = &dataWin->detail.dataDisplayInfo. | |
481 | regsContent[i]->whichElement.dataWindow; | |
482 | dataElementPtr = &((TuiWinElementPtr) | |
483 | dataItemWinPtr->content[0])->whichElement.data; | |
484 | wasHilighted = dataElementPtr->highlight; | |
485 | dataElementPtr->highlight = | |
486 | _tuiRegValueHasChanged (dataElementPtr, frame, &rawBuf[0]); | |
487 | if (dataElementPtr->highlight) | |
488 | { | |
c46cc7df SC |
489 | int size; |
490 | ||
491 | size = REGISTER_RAW_SIZE (dataElementPtr->itemNo); | |
492 | for (j = 0; j < size; j++) | |
c906108c SS |
493 | ((char *) dataElementPtr->value)[j] = rawBuf[j]; |
494 | _tuiDisplayRegister ( | |
495 | dataElementPtr->itemNo, | |
496 | dataItemWinPtr, | |
497 | ((dataWin->detail.dataDisplayInfo.regsDisplayType == | |
498 | TUI_DFLOAT_REGS) ? | |
499 | double_precision : unspecified_precision)); | |
500 | } | |
501 | else if (wasHilighted) | |
502 | { | |
503 | dataElementPtr->highlight = FALSE; | |
504 | _tuiDisplayRegister ( | |
505 | dataElementPtr->itemNo, | |
506 | dataItemWinPtr, | |
507 | ((dataWin->detail.dataDisplayInfo.regsDisplayType == | |
508 | TUI_DFLOAT_REGS) ? | |
509 | double_precision : unspecified_precision)); | |
510 | } | |
511 | } | |
512 | } | |
513 | } | |
514 | return; | |
515 | } /* tuiCheckRegisterValues */ | |
516 | ||
517 | ||
518 | /* | |
c5aa993b JM |
519 | ** tuiToggleFloatRegs(). |
520 | */ | |
c906108c | 521 | void |
c906108c | 522 | tuiToggleFloatRegs (void) |
c906108c SS |
523 | { |
524 | TuiLayoutDefPtr layoutDef = tuiLayoutDef (); | |
525 | ||
526 | if (layoutDef->floatRegsDisplayType == TUI_SFLOAT_REGS) | |
527 | layoutDef->floatRegsDisplayType = TUI_DFLOAT_REGS; | |
528 | else | |
529 | layoutDef->floatRegsDisplayType = TUI_SFLOAT_REGS; | |
530 | ||
531 | if (m_winPtrNotNull (dataWin) && dataWin->generic.isVisible && | |
532 | (dataWin->detail.dataDisplayInfo.regsDisplayType == TUI_SFLOAT_REGS || | |
533 | dataWin->detail.dataDisplayInfo.regsDisplayType == TUI_DFLOAT_REGS)) | |
534 | tuiShowRegisters (layoutDef->floatRegsDisplayType); | |
535 | ||
536 | return; | |
537 | } /* tuiToggleFloatRegs */ | |
538 | ||
539 | ||
540 | void | |
fba45db2 | 541 | _initialize_tuiRegs (void) |
c906108c | 542 | { |
41783295 | 543 | if (xdb_commands) |
c906108c SS |
544 | { |
545 | add_com ("fr", class_tui, _tuiShowFloat_command, | |
546 | "Display only floating point registers\n"); | |
547 | add_com ("gr", class_tui, _tuiShowGeneral_command, | |
548 | "Display only general registers\n"); | |
549 | add_com ("sr", class_tui, _tuiShowSpecial_command, | |
550 | "Display only special registers\n"); | |
551 | add_com ("+r", class_tui, _tuiScrollRegsForward_command, | |
552 | "Scroll the registers window forward\n"); | |
553 | add_com ("-r", class_tui, _tuiScrollRegsBackward_command, | |
554 | "Scroll the register window backward\n"); | |
555 | add_com ("tf", class_tui, _tuiToggleFloatRegs_command, | |
556 | "Toggle between single and double precision floating point registers.\n"); | |
557 | add_cmd (TUI_FLOAT_REGS_NAME_LOWER, | |
558 | class_tui, | |
559 | _tuiToggleFloatRegs_command, | |
560 | "Toggle between single and double precision floating point \ | |
561 | registers.\n", | |
562 | &togglelist); | |
563 | } | |
41783295 | 564 | } |
c906108c SS |
565 | |
566 | ||
567 | /***************************************** | |
568 | ** STATIC LOCAL FUNCTIONS ** | |
569 | ******************************************/ | |
570 | ||
571 | ||
572 | /* | |
c5aa993b JM |
573 | ** _tuiRegisterName(). |
574 | ** Return the register name. | |
575 | */ | |
c906108c | 576 | static char * |
eca6576c | 577 | _tuiRegisterName (int regNum) |
c906108c | 578 | { |
c46cc7df SC |
579 | return REGISTER_NAME (regNum); |
580 | } | |
581 | extern int pagination_enabled; | |
c906108c | 582 | |
c46cc7df SC |
583 | static void |
584 | tui_restore_gdbout (void *ui) | |
585 | { | |
586 | ui_file_delete (gdb_stdout); | |
587 | gdb_stdout = (struct ui_file*) ui; | |
588 | pagination_enabled = 1; | |
589 | } | |
c906108c SS |
590 | |
591 | /* | |
c5aa993b JM |
592 | ** _tuiRegisterFormat |
593 | ** Function to format the register name and value into a buffer, | |
594 | ** suitable for printing or display | |
595 | */ | |
c906108c | 596 | static void |
eca6576c SC |
597 | _tuiRegisterFormat (char *buf, int bufLen, int regNum, |
598 | TuiDataElementPtr dataElement, | |
599 | enum precision_type precision) | |
c906108c | 600 | { |
d9fcf2fb | 601 | struct ui_file *stream; |
c46cc7df SC |
602 | struct ui_file *old_stdout; |
603 | char *name; | |
604 | struct cleanup *cleanups; | |
605 | char *p; | |
c906108c | 606 | |
c46cc7df SC |
607 | name = REGISTER_NAME (regNum); |
608 | if (name == 0) | |
609 | { | |
610 | strcpy (buf, ""); | |
611 | return; | |
612 | } | |
613 | ||
614 | pagination_enabled = 0; | |
615 | old_stdout = gdb_stdout; | |
11cf8741 | 616 | stream = tui_sfileopen (bufLen); |
c46cc7df SC |
617 | gdb_stdout = stream; |
618 | cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout); | |
619 | do_registers_info (regNum, 0); | |
c906108c | 620 | |
c46cc7df SC |
621 | /* Save formatted output in the buffer. */ |
622 | strncpy (buf, tui_file_get_strbuf (stream), bufLen); | |
623 | ||
624 | /* Remove the possible \n. */ | |
625 | p = strchr (buf, '\n'); | |
626 | if (p) | |
627 | *p = 0; | |
628 | ||
629 | do_cleanups (cleanups); | |
630 | } | |
c906108c SS |
631 | |
632 | ||
633 | #define NUM_GENERAL_REGS 32 | |
634 | /* | |
c5aa993b JM |
635 | ** _tuiSetGeneralRegsContent(). |
636 | ** Set the content of the data window to consist of the general registers. | |
637 | */ | |
c906108c | 638 | static TuiStatus |
eca6576c | 639 | _tuiSetGeneralRegsContent (int refreshValuesOnly) |
c906108c SS |
640 | { |
641 | return (_tuiSetRegsContent (0, | |
642 | NUM_GENERAL_REGS - 1, | |
643 | selected_frame, | |
644 | TUI_GENERAL_REGS, | |
645 | refreshValuesOnly)); | |
646 | ||
647 | } /* _tuiSetGeneralRegsContent */ | |
648 | ||
649 | ||
c46cc7df SC |
650 | #ifndef PCOQ_HEAD_REGNUM |
651 | #define START_SPECIAL_REGS 0 | |
652 | #else | |
c906108c | 653 | #define START_SPECIAL_REGS PCOQ_HEAD_REGNUM |
c46cc7df SC |
654 | #endif |
655 | ||
c906108c | 656 | /* |
c5aa993b JM |
657 | ** _tuiSetSpecialRegsContent(). |
658 | ** Set the content of the data window to consist of the special registers. | |
659 | */ | |
c906108c | 660 | static TuiStatus |
eca6576c | 661 | _tuiSetSpecialRegsContent (int refreshValuesOnly) |
c906108c SS |
662 | { |
663 | TuiStatus ret = TUI_FAILURE; | |
664 | int i, endRegNum; | |
665 | ||
666 | endRegNum = FP0_REGNUM - 1; | |
667 | #if 0 | |
668 | endRegNum = (-1); | |
a728f042 | 669 | for (i = START_SPECIAL_REGS; (i < NUM_REGS && endRegNum < 0); i++) |
c906108c SS |
670 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT) |
671 | endRegNum = i - 1; | |
672 | #endif | |
673 | ret = _tuiSetRegsContent (START_SPECIAL_REGS, | |
674 | endRegNum, | |
675 | selected_frame, | |
676 | TUI_SPECIAL_REGS, | |
677 | refreshValuesOnly); | |
678 | ||
679 | return ret; | |
680 | } /* _tuiSetSpecialRegsContent */ | |
681 | ||
682 | ||
683 | /* | |
c5aa993b JM |
684 | ** _tuiSetGeneralAndSpecialRegsContent(). |
685 | ** Set the content of the data window to consist of the special registers. | |
686 | */ | |
c906108c | 687 | static TuiStatus |
eca6576c | 688 | _tuiSetGeneralAndSpecialRegsContent (int refreshValuesOnly) |
c906108c SS |
689 | { |
690 | TuiStatus ret = TUI_FAILURE; | |
691 | int i, endRegNum = (-1); | |
692 | ||
693 | endRegNum = FP0_REGNUM - 1; | |
694 | #if 0 | |
695 | endRegNum = (-1); | |
a728f042 | 696 | for (i = 0; (i < NUM_REGS && endRegNum < 0); i++) |
c906108c SS |
697 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT) |
698 | endRegNum = i - 1; | |
699 | #endif | |
700 | ret = _tuiSetRegsContent ( | |
701 | 0, endRegNum, selected_frame, TUI_SPECIAL_REGS, refreshValuesOnly); | |
702 | ||
703 | return ret; | |
704 | } /* _tuiSetGeneralAndSpecialRegsContent */ | |
705 | ||
706 | /* | |
c5aa993b JM |
707 | ** _tuiSetFloatRegsContent(). |
708 | ** Set the content of the data window to consist of the float registers. | |
709 | */ | |
c906108c | 710 | static TuiStatus |
c46cc7df | 711 | _tuiSetFloatRegsContent (TuiRegisterDisplayType dpyType, int refreshValuesOnly) |
c906108c SS |
712 | { |
713 | TuiStatus ret = TUI_FAILURE; | |
714 | int i, startRegNum; | |
715 | ||
716 | startRegNum = FP0_REGNUM; | |
717 | #if 0 | |
718 | startRegNum = (-1); | |
a728f042 | 719 | for (i = NUM_REGS - 1; (i >= 0 && startRegNum < 0); i--) |
c906108c SS |
720 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) != TYPE_CODE_FLT) |
721 | startRegNum = i + 1; | |
722 | #endif | |
723 | ret = _tuiSetRegsContent (startRegNum, | |
a728f042 | 724 | NUM_REGS - 1, |
c906108c SS |
725 | selected_frame, |
726 | dpyType, | |
727 | refreshValuesOnly); | |
728 | ||
729 | return ret; | |
730 | } /* _tuiSetFloatRegsContent */ | |
731 | ||
732 | ||
733 | /* | |
c5aa993b JM |
734 | ** _tuiRegValueHasChanged(). |
735 | ** Answer TRUE if the register's value has changed, FALSE otherwise. | |
736 | ** If TRUE, newValue is filled in with the new value. | |
737 | */ | |
c906108c | 738 | static int |
eca6576c SC |
739 | _tuiRegValueHasChanged (TuiDataElementPtr dataElement, |
740 | struct frame_info *frame, | |
741 | char *newValue) | |
c906108c SS |
742 | { |
743 | int hasChanged = FALSE; | |
744 | ||
745 | if (dataElement->itemNo != UNDEFINED_ITEM && | |
746 | _tuiRegisterName (dataElement->itemNo) != (char *) NULL) | |
747 | { | |
748 | char rawBuf[MAX_REGISTER_RAW_SIZE]; | |
749 | int i; | |
750 | ||
751 | if (_tuiGetRegisterRawValue ( | |
752 | dataElement->itemNo, rawBuf, frame) == TUI_SUCCESS) | |
753 | { | |
c46cc7df SC |
754 | int size = REGISTER_RAW_SIZE (dataElement->itemNo); |
755 | ||
756 | for (i = 0; (i < size && !hasChanged); i++) | |
c906108c SS |
757 | hasChanged = (((char *) dataElement->value)[i] != rawBuf[i]); |
758 | if (hasChanged && newValue != (char *) NULL) | |
759 | { | |
c46cc7df | 760 | for (i = 0; i < size; i++) |
c906108c SS |
761 | newValue[i] = rawBuf[i]; |
762 | } | |
763 | } | |
764 | } | |
765 | return hasChanged; | |
766 | } /* _tuiRegValueHasChanged */ | |
767 | ||
768 | ||
769 | ||
770 | /* | |
c5aa993b JM |
771 | ** _tuiGetRegisterRawValue(). |
772 | ** Get the register raw value. The raw value is returned in regValue. | |
773 | */ | |
c906108c | 774 | static TuiStatus |
c46cc7df | 775 | _tuiGetRegisterRawValue (int regNum, char *regValue, struct frame_info *frame) |
c906108c SS |
776 | { |
777 | TuiStatus ret = TUI_FAILURE; | |
778 | ||
779 | if (target_has_registers) | |
780 | { | |
c46cc7df SC |
781 | int opt; |
782 | ||
783 | get_saved_register (regValue, &opt, (CORE_ADDR*) NULL, frame, | |
784 | regNum, (enum lval_type*) NULL); | |
785 | if (register_cached (regNum) >= 0) | |
786 | ret = TUI_SUCCESS; | |
c906108c | 787 | } |
c906108c SS |
788 | return ret; |
789 | } /* _tuiGetRegisterRawValue */ | |
790 | ||
791 | ||
792 | ||
793 | /* | |
c5aa993b JM |
794 | ** _tuiSetRegisterElement(). |
795 | ** Function to initialize a data element with the input and | |
796 | ** the register value. | |
797 | */ | |
c906108c | 798 | static void |
eca6576c SC |
799 | _tuiSetRegisterElement (int regNum, struct frame_info *frame, |
800 | TuiDataElementPtr dataElement, | |
801 | int refreshValueOnly) | |
c906108c SS |
802 | { |
803 | if (dataElement != (TuiDataElementPtr) NULL) | |
804 | { | |
805 | if (!refreshValueOnly) | |
806 | { | |
807 | dataElement->itemNo = regNum; | |
808 | dataElement->name = _tuiRegisterName (regNum); | |
809 | dataElement->highlight = FALSE; | |
810 | } | |
811 | if (dataElement->value == (Opaque) NULL) | |
812 | dataElement->value = (Opaque) xmalloc (MAX_REGISTER_RAW_SIZE); | |
813 | if (dataElement->value != (Opaque) NULL) | |
814 | _tuiGetRegisterRawValue (regNum, dataElement->value, frame); | |
815 | } | |
816 | ||
817 | return; | |
818 | } /* _tuiSetRegisterElement */ | |
819 | ||
820 | ||
821 | /* | |
c5aa993b JM |
822 | ** _tuiSetRegsContent(). |
823 | ** Set the content of the data window to consist of the registers | |
824 | ** numbered from startRegNum to endRegNum. Note that if | |
825 | ** refreshValuesOnly is TRUE, startRegNum and endRegNum are ignored. | |
826 | */ | |
c906108c | 827 | static TuiStatus |
eca6576c SC |
828 | _tuiSetRegsContent (int startRegNum, int endRegNum, |
829 | struct frame_info *frame, | |
830 | TuiRegisterDisplayType dpyType, | |
831 | int refreshValuesOnly) | |
c906108c SS |
832 | { |
833 | TuiStatus ret = TUI_FAILURE; | |
834 | int numRegs = endRegNum - startRegNum + 1; | |
835 | int allocatedHere = FALSE; | |
836 | ||
837 | if (dataWin->detail.dataDisplayInfo.regsContentCount > 0 && | |
838 | !refreshValuesOnly) | |
839 | { | |
840 | freeDataContent (dataWin->detail.dataDisplayInfo.regsContent, | |
841 | dataWin->detail.dataDisplayInfo.regsContentCount); | |
842 | dataWin->detail.dataDisplayInfo.regsContentCount = 0; | |
843 | } | |
844 | if (dataWin->detail.dataDisplayInfo.regsContentCount <= 0) | |
845 | { | |
846 | dataWin->detail.dataDisplayInfo.regsContent = | |
847 | allocContent (numRegs, DATA_WIN); | |
848 | allocatedHere = TRUE; | |
849 | } | |
850 | ||
851 | if (dataWin->detail.dataDisplayInfo.regsContent != (TuiWinContent) NULL) | |
852 | { | |
853 | int i; | |
854 | ||
855 | if (!refreshValuesOnly || allocatedHere) | |
856 | { | |
857 | dataWin->generic.content = (OpaquePtr) NULL; | |
858 | dataWin->generic.contentSize = 0; | |
859 | addContentElements (&dataWin->generic, numRegs); | |
860 | dataWin->detail.dataDisplayInfo.regsContent = | |
861 | (TuiWinContent) dataWin->generic.content; | |
862 | dataWin->detail.dataDisplayInfo.regsContentCount = numRegs; | |
863 | } | |
864 | /* | |
c5aa993b JM |
865 | ** Now set the register names and values |
866 | */ | |
c906108c SS |
867 | for (i = startRegNum; (i <= endRegNum); i++) |
868 | { | |
869 | TuiGenWinInfoPtr dataItemWin; | |
870 | ||
871 | dataItemWin = &dataWin->detail.dataDisplayInfo. | |
872 | regsContent[i - startRegNum]->whichElement.dataWindow; | |
873 | _tuiSetRegisterElement ( | |
874 | i, | |
875 | frame, | |
876 | &((TuiWinElementPtr) dataItemWin->content[0])->whichElement.data, | |
877 | !allocatedHere && refreshValuesOnly); | |
878 | } | |
879 | dataWin->detail.dataDisplayInfo.regsColumnCount = | |
880 | tuiCalculateRegsColumnCount (dpyType); | |
881 | #ifdef LATER | |
882 | if (dataWin->detail.dataDisplayInfo.dataContentCount > 0) | |
883 | { | |
884 | /* delete all the windows? */ | |
885 | /* realloc content equal to dataContentCount + regsContentCount */ | |
886 | /* append dataWin->detail.dataDisplayInfo.dataContent to content */ | |
887 | } | |
888 | #endif | |
889 | dataWin->generic.contentSize = | |
890 | dataWin->detail.dataDisplayInfo.regsContentCount + | |
891 | dataWin->detail.dataDisplayInfo.dataContentCount; | |
892 | ret = TUI_SUCCESS; | |
893 | } | |
894 | ||
895 | return ret; | |
896 | } /* _tuiSetRegsContent */ | |
897 | ||
898 | ||
899 | /* | |
c5aa993b JM |
900 | ** _tuiDisplayRegister(). |
901 | ** Function to display a register in a window. If hilite is TRUE, | |
902 | ** than the value will be displayed in reverse video | |
903 | */ | |
c906108c | 904 | static void |
eca6576c SC |
905 | _tuiDisplayRegister (int regNum, |
906 | TuiGenWinInfoPtr winInfo, /* the data item window */ | |
907 | enum precision_type precision) | |
c906108c SS |
908 | { |
909 | if (winInfo->handle != (WINDOW *) NULL) | |
910 | { | |
c46cc7df SC |
911 | int i; |
912 | char buf[40]; | |
c906108c SS |
913 | int valueCharsWide, labelWidth; |
914 | TuiDataElementPtr dataElementPtr = &((TuiWinContent) | |
915 | winInfo->content)[0]->whichElement.data; | |
916 | ||
917 | if (IS_64BIT || | |
918 | dataWin->detail.dataDisplayInfo.regsDisplayType == TUI_DFLOAT_REGS) | |
919 | { | |
920 | valueCharsWide = DOUBLE_FLOAT_VALUE_WIDTH; | |
921 | labelWidth = DOUBLE_FLOAT_LABEL_WIDTH; | |
922 | } | |
923 | else | |
924 | { | |
925 | if (dataWin->detail.dataDisplayInfo.regsDisplayType == | |
926 | TUI_SFLOAT_REGS) | |
927 | { | |
928 | valueCharsWide = SINGLE_FLOAT_VALUE_WIDTH; | |
929 | labelWidth = SINGLE_FLOAT_LABEL_WIDTH; | |
930 | } | |
931 | else | |
932 | { | |
933 | valueCharsWide = SINGLE_VALUE_WIDTH; | |
934 | labelWidth = SINGLE_LABEL_WIDTH; | |
935 | } | |
936 | } | |
937 | ||
938 | buf[0] = (char) 0; | |
939 | _tuiRegisterFormat (buf, | |
940 | valueCharsWide + labelWidth, | |
941 | regNum, | |
942 | dataElementPtr, | |
943 | precision); | |
c46cc7df | 944 | |
c906108c SS |
945 | if (dataElementPtr->highlight) |
946 | wstandout (winInfo->handle); | |
947 | ||
c46cc7df SC |
948 | wmove (winInfo->handle, 0, 0); |
949 | for (i = 1; i < winInfo->width; i++) | |
950 | waddch (winInfo->handle, ' '); | |
c906108c SS |
951 | wmove (winInfo->handle, 0, 0); |
952 | waddstr (winInfo->handle, buf); | |
953 | ||
954 | if (dataElementPtr->highlight) | |
955 | wstandend (winInfo->handle); | |
956 | tuiRefreshWin (winInfo); | |
957 | } | |
958 | return; | |
959 | } /* _tuiDisplayRegister */ | |
960 | ||
961 | ||
962 | static void | |
e8b915dc | 963 | _tui_vShowRegisters_commandSupport (TuiRegisterDisplayType dpyType) |
c906108c | 964 | { |
c906108c SS |
965 | |
966 | if (m_winPtrNotNull (dataWin) && dataWin->generic.isVisible) | |
967 | { /* Data window already displayed, show the registers */ | |
968 | if (dataWin->detail.dataDisplayInfo.regsDisplayType != dpyType) | |
969 | tuiShowRegisters (dpyType); | |
970 | } | |
971 | else | |
972 | (tuiLayoutDef ())->regsDisplayType = dpyType; | |
973 | ||
974 | return; | |
975 | } /* _tui_vShowRegisters_commandSupport */ | |
976 | ||
977 | ||
978 | static void | |
eca6576c | 979 | _tuiShowFloat_command (char *arg, int fromTTY) |
c906108c SS |
980 | { |
981 | if (m_winPtrIsNull (dataWin) || !dataWin->generic.isVisible || | |
982 | (dataWin->detail.dataDisplayInfo.regsDisplayType != TUI_SFLOAT_REGS && | |
983 | dataWin->detail.dataDisplayInfo.regsDisplayType != TUI_DFLOAT_REGS)) | |
e8b915dc | 984 | _tui_vShowRegisters_commandSupport ((tuiLayoutDef ())->floatRegsDisplayType); |
c906108c SS |
985 | |
986 | return; | |
987 | } /* _tuiShowFloat_command */ | |
988 | ||
989 | ||
990 | static void | |
eca6576c | 991 | _tuiShowGeneral_command (char *arg, int fromTTY) |
c906108c | 992 | { |
e8b915dc SC |
993 | _tui_vShowRegisters_commandSupport (TUI_GENERAL_REGS); |
994 | } | |
c906108c SS |
995 | |
996 | ||
997 | static void | |
eca6576c | 998 | _tuiShowSpecial_command (char *arg, int fromTTY) |
c906108c | 999 | { |
e8b915dc SC |
1000 | _tui_vShowRegisters_commandSupport (TUI_SPECIAL_REGS); |
1001 | } | |
c906108c SS |
1002 | |
1003 | ||
1004 | static void | |
eca6576c | 1005 | _tuiToggleFloatRegs_command (char *arg, int fromTTY) |
c906108c SS |
1006 | { |
1007 | if (m_winPtrNotNull (dataWin) && dataWin->generic.isVisible) | |
e8b915dc | 1008 | tuiToggleFloatRegs (); |
c906108c SS |
1009 | else |
1010 | { | |
1011 | TuiLayoutDefPtr layoutDef = tuiLayoutDef (); | |
1012 | ||
1013 | if (layoutDef->floatRegsDisplayType == TUI_SFLOAT_REGS) | |
1014 | layoutDef->floatRegsDisplayType = TUI_DFLOAT_REGS; | |
1015 | else | |
1016 | layoutDef->floatRegsDisplayType = TUI_SFLOAT_REGS; | |
1017 | } | |
1018 | ||
1019 | ||
1020 | return; | |
1021 | } /* _tuiToggleFloatRegs_command */ | |
1022 | ||
1023 | ||
1024 | static void | |
eca6576c | 1025 | _tuiScrollRegsForward_command (char *arg, int fromTTY) |
c906108c | 1026 | { |
e8b915dc SC |
1027 | tui_scroll (FORWARD_SCROLL, dataWin, 1); |
1028 | } | |
c906108c SS |
1029 | |
1030 | ||
1031 | static void | |
eca6576c | 1032 | _tuiScrollRegsBackward_command (char *arg, int fromTTY) |
c906108c | 1033 | { |
e8b915dc SC |
1034 | tui_scroll (BACKWARD_SCROLL, dataWin, 1); |
1035 | } |