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