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