1 /* General utility routines for GDB, the GNU debugger.
2 Copyright 1986, 89, 90, 91, 92, 95, 96, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
24 #include "event-loop.h"
33 /* SunOS's curses.h has a '#define reg register' in it. Thank you Sun. */
44 #include "expression.h"
48 #include <readline/readline.h>
50 /* readline defines this. */
53 void (*error_begin_hook) PARAMS ((void));
55 /* Prototypes for local functions */
57 static void vfprintf_maybe_filtered PARAMS ((GDB_FILE *, const char *,
60 static void fputs_maybe_filtered PARAMS ((const char *, GDB_FILE *, int));
62 #if defined (USE_MMALLOC) && !defined (NO_MMCHECK)
63 static void malloc_botch PARAMS ((void));
67 prompt_for_continue PARAMS ((void));
70 set_width_command PARAMS ((char *, int, struct cmd_list_element *));
73 set_width PARAMS ((void));
75 #ifndef GDB_FILE_ISATTY
76 #define GDB_FILE_ISATTY(GDB_FILE_PTR) (gdb_file_isatty(GDB_FILE_PTR))
79 /* Chain of cleanup actions established with make_cleanup,
80 to be executed if an error happens. */
82 static struct cleanup *cleanup_chain; /* cleaned up after a failed command */
83 static struct cleanup *final_cleanup_chain; /* cleaned up when gdb exits */
84 static struct cleanup *run_cleanup_chain; /* cleaned up on each 'run' */
85 static struct cleanup *exec_cleanup_chain; /* cleaned up on each execution command */
87 /* Pointer to what is left to do for an execution command after the
88 target stops. Used only in asynchronous mode, by targets that
89 support async execution. The finish and until commands use it. So
90 does the target extended-remote command. */
91 struct continuation *cmd_continuation;
93 /* Nonzero if we have job control. */
97 /* Nonzero means a quit has been requested. */
101 /* Nonzero means quit immediately if Control-C is typed now, rather
102 than waiting until QUIT is executed. Be careful in setting this;
103 code which executes with immediate_quit set has to be very careful
104 about being able to deal with being interrupted at any time. It is
105 almost always better to use QUIT; the only exception I can think of
106 is being able to quit out of a system call (using EINTR loses if
107 the SIGINT happens between the previous QUIT and the system call).
108 To immediately quit in the case in which a SIGINT happens between
109 the previous QUIT and setting immediate_quit (desirable anytime we
110 expect to block), call QUIT after setting immediate_quit. */
114 /* Nonzero means that encoded C++ names should be printed out in their
115 C++ form rather than raw. */
119 /* Nonzero means that encoded C++ names should be printed out in their
120 C++ form even in assembler language displays. If this is set, but
121 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
123 int asm_demangle = 0;
125 /* Nonzero means that strings with character values >0x7F should be printed
126 as octal escapes. Zero means just print the value (e.g. it's an
127 international character, and the terminal or window can cope.) */
129 int sevenbit_strings = 0;
131 /* String to be printed before error messages, if any. */
133 char *error_pre_print;
135 /* String to be printed before quit messages, if any. */
137 char *quit_pre_print;
139 /* String to be printed before warning messages, if any. */
141 char *warning_pre_print = "\nwarning: ";
143 int pagination_enabled = 1;
146 /* Add a new cleanup to the cleanup_chain,
147 and return the previous chain pointer
148 to be passed later to do_cleanups or discard_cleanups.
149 Args are FUNCTION to clean up with, and ARG to pass to it. */
152 make_cleanup (function, arg)
153 void (*function) PARAMS ((PTR));
156 return make_my_cleanup (&cleanup_chain, function, arg);
160 make_final_cleanup (function, arg)
161 void (*function) PARAMS ((PTR));
164 return make_my_cleanup (&final_cleanup_chain, function, arg);
168 make_run_cleanup (function, arg)
169 void (*function) PARAMS ((PTR));
172 return make_my_cleanup (&run_cleanup_chain, function, arg);
176 make_exec_cleanup (function, arg)
177 void (*function) PARAMS ((PTR));
180 return make_my_cleanup (&exec_cleanup_chain, function, arg);
187 freeargv ((char **) arg);
191 make_cleanup_freeargv (arg)
194 return make_my_cleanup (&cleanup_chain, do_freeargv, arg);
198 make_my_cleanup (pmy_chain, function, arg)
199 struct cleanup **pmy_chain;
200 void (*function) PARAMS ((PTR));
203 register struct cleanup *new
204 = (struct cleanup *) xmalloc (sizeof (struct cleanup));
205 register struct cleanup *old_chain = *pmy_chain;
207 new->next = *pmy_chain;
208 new->function = function;
215 /* Discard cleanups and do the actions they describe
216 until we get back to the point OLD_CHAIN in the cleanup_chain. */
219 do_cleanups (old_chain)
220 register struct cleanup *old_chain;
222 do_my_cleanups (&cleanup_chain, old_chain);
226 do_final_cleanups (old_chain)
227 register struct cleanup *old_chain;
229 do_my_cleanups (&final_cleanup_chain, old_chain);
233 do_run_cleanups (old_chain)
234 register struct cleanup *old_chain;
236 do_my_cleanups (&run_cleanup_chain, old_chain);
240 do_exec_cleanups (old_chain)
241 register struct cleanup *old_chain;
243 do_my_cleanups (&exec_cleanup_chain, old_chain);
247 do_my_cleanups (pmy_chain, old_chain)
248 register struct cleanup **pmy_chain;
249 register struct cleanup *old_chain;
251 register struct cleanup *ptr;
252 while ((ptr = *pmy_chain) != old_chain)
254 *pmy_chain = ptr->next; /* Do this first incase recursion */
255 (*ptr->function) (ptr->arg);
260 /* Discard cleanups, not doing the actions they describe,
261 until we get back to the point OLD_CHAIN in the cleanup_chain. */
264 discard_cleanups (old_chain)
265 register struct cleanup *old_chain;
267 discard_my_cleanups (&cleanup_chain, old_chain);
271 discard_final_cleanups (old_chain)
272 register struct cleanup *old_chain;
274 discard_my_cleanups (&final_cleanup_chain, old_chain);
278 discard_my_cleanups (pmy_chain, old_chain)
279 register struct cleanup **pmy_chain;
280 register struct cleanup *old_chain;
282 register struct cleanup *ptr;
283 while ((ptr = *pmy_chain) != old_chain)
285 *pmy_chain = ptr->next;
290 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
294 return save_my_cleanups (&cleanup_chain);
298 save_final_cleanups ()
300 return save_my_cleanups (&final_cleanup_chain);
304 save_my_cleanups (pmy_chain)
305 struct cleanup **pmy_chain;
307 struct cleanup *old_chain = *pmy_chain;
313 /* Restore the cleanup chain from a previously saved chain. */
315 restore_cleanups (chain)
316 struct cleanup *chain;
318 restore_my_cleanups (&cleanup_chain, chain);
322 restore_final_cleanups (chain)
323 struct cleanup *chain;
325 restore_my_cleanups (&final_cleanup_chain, chain);
329 restore_my_cleanups (pmy_chain, chain)
330 struct cleanup **pmy_chain;
331 struct cleanup *chain;
336 /* This function is useful for cleanups.
340 old_chain = make_cleanup (free_current_contents, &foo);
342 to arrange to free the object thus allocated. */
345 free_current_contents (location)
351 /* Provide a known function that does nothing, to use as a base for
352 for a possibly long chain of cleanups. This is useful where we
353 use the cleanup chain for handling normal cleanups as well as dealing
354 with cleanups that need to be done as a result of a call to error().
355 In such cases, we may not be certain where the first cleanup is, unless
356 we have a do-nothing one to always use as the base. */
365 /* Add a continuation to the continuation list, the gloabl list
368 add_continuation (continuation_hook, arg_list)
369 void (*continuation_hook) PARAMS ((struct continuation_arg *));
370 struct continuation_arg *arg_list;
372 struct continuation *continuation_ptr;
374 continuation_ptr = (struct continuation *) xmalloc (sizeof (struct continuation));
375 continuation_ptr->continuation_hook = continuation_hook;
376 continuation_ptr->arg_list = arg_list;
377 continuation_ptr->next = cmd_continuation;
378 cmd_continuation = continuation_ptr;
381 /* Walk down the cmd_continuation list, and execute all the
384 do_all_continuations ()
386 struct continuation *continuation_ptr;
388 while (cmd_continuation)
390 (cmd_continuation->continuation_hook) (cmd_continuation->arg_list);
391 continuation_ptr = cmd_continuation;
392 cmd_continuation = continuation_ptr->next;
393 free (continuation_ptr);
398 /* Print a warning message. Way to use this is to call warning_begin,
399 output the warning message (use unfiltered output to gdb_stderr),
400 ending in a newline. There is not currently a warning_end that you
401 call afterwards, but such a thing might be added if it is useful
402 for a GUI to separate warning messages from other output.
404 FIXME: Why do warnings use unfiltered output and errors filtered?
405 Is this anything other than a historical accident? */
410 target_terminal_ours ();
411 wrap_here (""); /* Force out any buffered output */
412 gdb_flush (gdb_stdout);
413 if (warning_pre_print)
414 fprintf_unfiltered (gdb_stderr, warning_pre_print);
417 /* Print a warning message.
418 The first argument STRING is the warning message, used as a fprintf string,
419 and the remaining args are passed as arguments to it.
420 The primary difference between warnings and errors is that a warning
421 does not force the return to command level. */
424 warning (const char *string,...)
427 va_start (args, string);
429 (*warning_hook) (string, args);
433 vfprintf_unfiltered (gdb_stderr, string, args);
434 fprintf_unfiltered (gdb_stderr, "\n");
439 /* Start the printing of an error message. Way to use this is to call
440 this, output the error message (use filtered output to gdb_stderr
441 (FIXME: Some callers, like memory_error, use gdb_stdout)), ending
442 in a newline, and then call return_to_top_level (RETURN_ERROR).
443 error() provides a convenient way to do this for the special case
444 that the error message can be formatted with a single printf call,
445 but this is more general. */
449 if (error_begin_hook)
452 target_terminal_ours ();
453 wrap_here (""); /* Force out any buffered output */
454 gdb_flush (gdb_stdout);
456 annotate_error_begin ();
459 fprintf_filtered (gdb_stderr, error_pre_print);
462 /* Print an error message and return to command level.
463 The first argument STRING is the error message, used as a fprintf string,
464 and the remaining args are passed as arguments to it. */
467 error (const char *string,...)
470 va_start (args, string);
476 vfprintf_filtered (gdb_stderr, string, args);
477 fprintf_filtered (gdb_stderr, "\n");
479 return_to_top_level (RETURN_ERROR);
484 /* Print a message reporting an internal error. Ask the user if they
485 want to continue, dump core, or just exit. */
488 internal_error (char *string, ...)
490 static char msg[] = "Internal GDB error: recursive internal error.\n";
491 static int dejavu = 0;
496 /* don't allow infinite error recursion. */
504 fputs_unfiltered (msg, gdb_stderr);
508 write (STDERR_FILENO, msg, sizeof (msg));
512 /* Try to get the message out */
513 fputs_unfiltered ("gdb-internal-error: ", gdb_stderr);
514 va_start (args, string);
515 vfprintf_unfiltered (gdb_stderr, string, args);
517 fputs_unfiltered ("\n", gdb_stderr);
519 /* Default (no case) is to quit GDB. When in batch mode this
520 lessens the likelhood of GDB going into an infinate loop. */
521 continue_p = query ("\
522 An internal GDB error was detected. This may make make further\n\
523 debugging unreliable. Continue this debugging session? ");
525 /* Default (no case) is to not dump core. Lessen the chance of GDB
526 leaving random core files around. */
527 dump_core_p = query ("\
528 Create a core file containing the current state of GDB? ");
547 return_to_top_level (RETURN_ERROR);
550 /* The strerror() function can return NULL for errno values that are
551 out of range. Provide a "safe" version that always returns a
555 safe_strerror (errnum)
561 if ((msg = strerror (errnum)) == NULL)
563 sprintf (buf, "(undocumented errno %d)", errnum);
569 /* The strsignal() function can return NULL for signal values that are
570 out of range. Provide a "safe" version that always returns a
574 safe_strsignal (signo)
580 if ((msg = strsignal (signo)) == NULL)
582 sprintf (buf, "(undocumented signal %d)", signo);
589 /* Print the system error message for errno, and also mention STRING
590 as the file name for which the error was encountered.
591 Then return to command level. */
594 perror_with_name (string)
600 err = safe_strerror (errno);
601 combined = (char *) alloca (strlen (err) + strlen (string) + 3);
602 strcpy (combined, string);
603 strcat (combined, ": ");
604 strcat (combined, err);
606 /* I understand setting these is a matter of taste. Still, some people
607 may clear errno but not know about bfd_error. Doing this here is not
609 bfd_set_error (bfd_error_no_error);
612 error ("%s.", combined);
615 /* Print the system error message for ERRCODE, and also mention STRING
616 as the file name for which the error was encountered. */
619 print_sys_errmsg (string, errcode)
626 err = safe_strerror (errcode);
627 combined = (char *) alloca (strlen (err) + strlen (string) + 3);
628 strcpy (combined, string);
629 strcat (combined, ": ");
630 strcat (combined, err);
632 /* We want anything which was printed on stdout to come out first, before
634 gdb_flush (gdb_stdout);
635 fprintf_unfiltered (gdb_stderr, "%s.\n", combined);
638 /* Control C eventually causes this to be called, at a convenient time. */
643 serial_t gdb_stdout_serial = serial_fdopen (1);
645 target_terminal_ours ();
647 /* We want all output to appear now, before we print "Quit". We
648 have 3 levels of buffering we have to flush (it's possible that
649 some of these should be changed to flush the lower-level ones
652 /* 1. The _filtered buffer. */
653 wrap_here ((char *) 0);
655 /* 2. The stdio buffer. */
656 gdb_flush (gdb_stdout);
657 gdb_flush (gdb_stderr);
659 /* 3. The system-level buffer. */
660 SERIAL_DRAIN_OUTPUT (gdb_stdout_serial);
661 SERIAL_UN_FDOPEN (gdb_stdout_serial);
663 annotate_error_begin ();
665 /* Don't use *_filtered; we don't want to prompt the user to continue. */
667 fprintf_unfiltered (gdb_stderr, quit_pre_print);
670 /* No steenking SIGINT will ever be coming our way when the
671 program is resumed. Don't lie. */
672 fprintf_unfiltered (gdb_stderr, "Quit\n");
675 /* If there is no terminal switching for this target, then we can't
676 possibly get screwed by the lack of job control. */
677 || current_target.to_terminal_ours == NULL)
678 fprintf_unfiltered (gdb_stderr, "Quit\n");
680 fprintf_unfiltered (gdb_stderr,
681 "Quit (expect signal SIGINT when the program is resumed)\n");
683 return_to_top_level (RETURN_QUIT);
687 #if defined(_MSC_VER) /* should test for wingdb instead? */
690 * Windows translates all keyboard and mouse events
691 * into a message which is appended to the message
692 * queue for the process.
698 int k = win32pollquit ();
705 #else /* !defined(__GO32__) && !defined(_MSC_VER) */
710 /* Done by signals */
713 #endif /* !defined(__GO32__) && !defined(_MSC_VER) */
715 /* Control C comes here */
721 /* Restore the signal handler. Harmless with BSD-style signals, needed
722 for System V-style signals. So just always do it, rather than worrying
723 about USG defines and stuff like that. */
724 signal (signo, request_quit);
734 /* Memory management stuff (malloc friends). */
736 /* Make a substitute size_t for non-ANSI compilers. */
738 #ifndef HAVE_STDDEF_H
740 #define size_t unsigned int
744 #if !defined (USE_MMALLOC)
751 return malloc (size);
755 mrealloc (md, ptr, size)
760 if (ptr == 0) /* Guard against old realloc's */
761 return malloc (size);
763 return realloc (ptr, size);
774 #endif /* USE_MMALLOC */
776 #if !defined (USE_MMALLOC) || defined (NO_MMCHECK)
784 #else /* Have mmalloc and want corruption checking */
789 fprintf_unfiltered (gdb_stderr, "Memory corruption\n");
793 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
794 by MD, to detect memory corruption. Note that MD may be NULL to specify
795 the default heap that grows via sbrk.
797 Note that for freshly created regions, we must call mmcheckf prior to any
798 mallocs in the region. Otherwise, any region which was allocated prior to
799 installing the checking hooks, which is later reallocated or freed, will
800 fail the checks! The mmcheck function only allows initial hooks to be
801 installed before the first mmalloc. However, anytime after we have called
802 mmcheck the first time to install the checking hooks, we can call it again
803 to update the function pointer to the memory corruption handler.
805 Returns zero on failure, non-zero on success. */
807 #ifndef MMCHECK_FORCE
808 #define MMCHECK_FORCE 0
815 if (!mmcheckf (md, malloc_botch, MMCHECK_FORCE))
817 /* Don't use warning(), which relies on current_target being set
818 to something other than dummy_target, until after
819 initialize_all_files(). */
822 (gdb_stderr, "warning: failed to install memory consistency checks; ");
824 (gdb_stderr, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
830 #endif /* Have mmalloc and want corruption checking */
832 /* Called when a memory allocation fails, with the number of bytes of
833 memory requested in SIZE. */
841 internal_error ("virtual memory exhausted: can't allocate %ld bytes.", size);
845 internal_error ("virtual memory exhausted.");
849 /* Like mmalloc but get error if no storage available, and protect against
850 the caller wanting to allocate zero bytes. Whether to return NULL for
851 a zero byte request, or translate the request into a request for one
852 byte of zero'd storage, is a religious issue. */
865 else if ((val = mmalloc (md, size)) == NULL)
872 /* Like mrealloc but get error if no storage available. */
875 xmrealloc (md, ptr, size)
884 val = mrealloc (md, ptr, size);
888 val = mmalloc (md, size);
897 /* Like malloc but get error if no storage available, and protect against
898 the caller wanting to allocate zero bytes. */
904 return (xmmalloc ((PTR) NULL, size));
907 /* Like mrealloc but get error if no storage available. */
914 return (xmrealloc ((PTR) NULL, ptr, size));
918 /* My replacement for the read system call.
919 Used like `read' but keeps going if `read' returns too soon. */
922 myread (desc, addr, len)
932 val = read (desc, addr, len);
943 /* Make a copy of the string at PTR with SIZE characters
944 (and add a null character at the end in the copy).
945 Uses malloc to get the space. Returns the address of the copy. */
948 savestring (ptr, size)
952 register char *p = (char *) xmalloc (size + 1);
953 memcpy (p, ptr, size);
959 msavestring (md, ptr, size)
964 register char *p = (char *) xmmalloc (md, size + 1);
965 memcpy (p, ptr, size);
970 /* The "const" is so it compiles under DGUX (which prototypes strsave
971 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
972 Doesn't real strsave return NULL if out of memory? */
977 return savestring (ptr, strlen (ptr));
985 return (msavestring (md, ptr, strlen (ptr)));
989 print_spaces (n, file)
991 register GDB_FILE *file;
993 fputs_unfiltered (n_spaces (n), file);
996 /* Print a host address. */
999 gdb_print_address (addr, stream)
1004 /* We could use the %p conversion specifier to fprintf if we had any
1005 way of knowing whether this host supports it. But the following
1006 should work on the Alpha and on 32 bit machines. */
1008 fprintf_filtered (stream, "0x%lx", (unsigned long) addr);
1011 /* Ask user a y-or-n question and return 1 iff answer is yes.
1012 Takes three args which are given to printf to print the question.
1013 The first, a control string, should end in "? ".
1014 It should not say how to answer, because we do that. */
1018 query (char *ctlstr,...)
1021 register int answer;
1025 va_start (args, ctlstr);
1029 return query_hook (ctlstr, args);
1032 /* Automatically answer "yes" if input is not from a terminal. */
1033 if (!input_from_terminal_p ())
1036 /* FIXME Automatically answer "yes" if called from MacGDB. */
1043 wrap_here (""); /* Flush any buffered output */
1044 gdb_flush (gdb_stdout);
1046 if (annotation_level > 1)
1047 printf_filtered ("\n\032\032pre-query\n");
1049 vfprintf_filtered (gdb_stdout, ctlstr, args);
1050 printf_filtered ("(y or n) ");
1052 if (annotation_level > 1)
1053 printf_filtered ("\n\032\032query\n");
1056 /* If not in MacGDB, move to a new line so the entered line doesn't
1057 have a prompt on the front of it. */
1059 fputs_unfiltered ("\n", gdb_stdout);
1063 gdb_flush (gdb_stdout);
1066 if (!tui_version || cmdWin == tuiWinWithFocus ())
1068 answer = fgetc (stdin);
1071 answer = (unsigned char) tuiBufferGetc ();
1074 clearerr (stdin); /* in case of C-d */
1075 if (answer == EOF) /* C-d */
1080 /* Eat rest of input line, to EOF or newline */
1081 if ((answer != '\n') || (tui_version && answer != '\r'))
1085 if (!tui_version || cmdWin == tuiWinWithFocus ())
1087 ans2 = fgetc (stdin);
1090 ans2 = (unsigned char) tuiBufferGetc ();
1094 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
1095 TUIDO (((TuiOpaqueFuncPtr) tui_vStartNewLines, 1));
1109 printf_filtered ("Please answer y or n.\n");
1112 if (annotation_level > 1)
1113 printf_filtered ("\n\032\032post-query\n");
1118 /* Parse a C escape sequence. STRING_PTR points to a variable
1119 containing a pointer to the string to parse. That pointer
1120 should point to the character after the \. That pointer
1121 is updated past the characters we use. The value of the
1122 escape sequence is returned.
1124 A negative value means the sequence \ newline was seen,
1125 which is supposed to be equivalent to nothing at all.
1127 If \ is followed by a null character, we return a negative
1128 value and leave the string pointer pointing at the null character.
1130 If \ is followed by 000, we return 0 and leave the string pointer
1131 after the zeros. A value of 0 does not mean end of string. */
1134 parse_escape (string_ptr)
1137 register int c = *(*string_ptr)++;
1141 return 007; /* Bell (alert) char */
1144 case 'e': /* Escape character */
1162 c = *(*string_ptr)++;
1164 c = parse_escape (string_ptr);
1167 return (c & 0200) | (c & 037);
1178 register int i = c - '0';
1179 register int count = 0;
1182 if ((c = *(*string_ptr)++) >= '0' && c <= '7')
1200 /* Print the character C on STREAM as part of the contents of a literal
1201 string whose delimiter is QUOTER. Note that this routine should only
1202 be call for printing things which are independent of the language
1203 of the program being debugged. */
1205 static void printchar PARAMS ((int c, void (*do_fputs) (const char *, GDB_FILE*), void (*do_fprintf) (GDB_FILE*, const char *, ...), GDB_FILE *stream, int quoter));
1208 printchar (c, do_fputs, do_fprintf, stream, quoter)
1210 void (*do_fputs) PARAMS ((const char *, GDB_FILE*));
1211 void (*do_fprintf) PARAMS ((GDB_FILE*, const char *, ...));
1216 c &= 0xFF; /* Avoid sign bit follies */
1218 if (c < 0x20 || /* Low control chars */
1219 (c >= 0x7F && c < 0xA0) || /* DEL, High controls */
1220 (sevenbit_strings && c >= 0x80))
1221 { /* high order bit set */
1225 do_fputs ("\\n", stream);
1228 do_fputs ("\\b", stream);
1231 do_fputs ("\\t", stream);
1234 do_fputs ("\\f", stream);
1237 do_fputs ("\\r", stream);
1240 do_fputs ("\\e", stream);
1243 do_fputs ("\\a", stream);
1246 do_fprintf (stream, "\\%.3o", (unsigned int) c);
1252 if (c == '\\' || c == quoter)
1253 do_fputs ("\\", stream);
1254 do_fprintf (stream, "%c", c);
1258 /* Print the character C on STREAM as part of the contents of a
1259 literal string whose delimiter is QUOTER. Note that these routines
1260 should only be call for printing things which are independent of
1261 the language of the program being debugged. */
1264 fputstr_filtered (str, quoter, stream)
1270 printchar (*str++, fputs_filtered, fprintf_filtered, stream, quoter);
1274 fputstr_unfiltered (str, quoter, stream)
1280 printchar (*str++, fputs_unfiltered, fprintf_unfiltered, stream, quoter);
1284 fputstrn_unfiltered (str, n, quoter, stream)
1291 for (i = 0; i < n; i++)
1292 printchar (str[i], fputs_unfiltered, fprintf_unfiltered, stream, quoter);
1297 /* Number of lines per page or UINT_MAX if paging is disabled. */
1298 static unsigned int lines_per_page;
1299 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
1300 static unsigned int chars_per_line;
1301 /* Current count of lines printed on this page, chars on this line. */
1302 static unsigned int lines_printed, chars_printed;
1304 /* Buffer and start column of buffered text, for doing smarter word-
1305 wrapping. When someone calls wrap_here(), we start buffering output
1306 that comes through fputs_filtered(). If we see a newline, we just
1307 spit it out and forget about the wrap_here(). If we see another
1308 wrap_here(), we spit it out and remember the newer one. If we see
1309 the end of the line, we spit out a newline, the indent, and then
1310 the buffered output. */
1312 /* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
1313 are waiting to be output (they have already been counted in chars_printed).
1314 When wrap_buffer[0] is null, the buffer is empty. */
1315 static char *wrap_buffer;
1317 /* Pointer in wrap_buffer to the next character to fill. */
1318 static char *wrap_pointer;
1320 /* String to indent by if the wrap occurs. Must not be NULL if wrap_column
1322 static char *wrap_indent;
1324 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
1325 is not in effect. */
1326 static int wrap_column;
1329 /* Inialize the lines and chars per page */
1334 if (tui_version && m_winPtrNotNull (cmdWin))
1336 lines_per_page = cmdWin->generic.height;
1337 chars_per_line = cmdWin->generic.width;
1342 /* These defaults will be used if we are unable to get the correct
1343 values from termcap. */
1344 #if defined(__GO32__)
1345 lines_per_page = ScreenRows ();
1346 chars_per_line = ScreenCols ();
1348 lines_per_page = 24;
1349 chars_per_line = 80;
1351 #if !defined (MPW) && !defined (_WIN32)
1352 /* No termcap under MPW, although might be cool to do something
1353 by looking at worksheet or console window sizes. */
1354 /* Initialize the screen height and width from termcap. */
1356 char *termtype = getenv ("TERM");
1358 /* Positive means success, nonpositive means failure. */
1361 /* 2048 is large enough for all known terminals, according to the
1362 GNU termcap manual. */
1363 char term_buffer[2048];
1367 status = tgetent (term_buffer, termtype);
1371 int running_in_emacs = getenv ("EMACS") != NULL;
1373 val = tgetnum ("li");
1374 if (val >= 0 && !running_in_emacs)
1375 lines_per_page = val;
1377 /* The number of lines per page is not mentioned
1378 in the terminal description. This probably means
1379 that paging is not useful (e.g. emacs shell window),
1380 so disable paging. */
1381 lines_per_page = UINT_MAX;
1383 val = tgetnum ("co");
1385 chars_per_line = val;
1391 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1393 /* If there is a better way to determine the window size, use it. */
1394 SIGWINCH_HANDLER (SIGWINCH);
1397 /* If the output is not a terminal, don't paginate it. */
1398 if (!GDB_FILE_ISATTY (gdb_stdout))
1399 lines_per_page = UINT_MAX;
1400 } /* the command_line_version */
1407 if (chars_per_line == 0)
1412 wrap_buffer = (char *) xmalloc (chars_per_line + 2);
1413 wrap_buffer[0] = '\0';
1416 wrap_buffer = (char *) xrealloc (wrap_buffer, chars_per_line + 2);
1417 wrap_pointer = wrap_buffer; /* Start it at the beginning */
1422 set_width_command (args, from_tty, c)
1425 struct cmd_list_element *c;
1430 /* Wait, so the user can read what's on the screen. Prompt the user
1431 to continue by pressing RETURN. */
1434 prompt_for_continue ()
1437 char cont_prompt[120];
1439 if (annotation_level > 1)
1440 printf_unfiltered ("\n\032\032pre-prompt-for-continue\n");
1442 strcpy (cont_prompt,
1443 "---Type <return> to continue, or q <return> to quit---");
1444 if (annotation_level > 1)
1445 strcat (cont_prompt, "\n\032\032prompt-for-continue\n");
1447 /* We must do this *before* we call gdb_readline, else it will eventually
1448 call us -- thinking that we're trying to print beyond the end of the
1450 reinitialize_more_filter ();
1453 /* On a real operating system, the user can quit with SIGINT.
1456 'q' is provided on all systems so users don't have to change habits
1457 from system to system, and because telling them what to do in
1458 the prompt is more user-friendly than expecting them to think of
1460 /* Call readline, not gdb_readline, because GO32 readline handles control-C
1461 whereas control-C to gdb_readline will cause the user to get dumped
1463 ignore = readline (cont_prompt);
1465 if (annotation_level > 1)
1466 printf_unfiltered ("\n\032\032post-prompt-for-continue\n");
1471 while (*p == ' ' || *p == '\t')
1476 request_quit (SIGINT);
1478 async_request_quit (0);
1484 /* Now we have to do this again, so that GDB will know that it doesn't
1485 need to save the ---Type <return>--- line at the top of the screen. */
1486 reinitialize_more_filter ();
1488 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
1491 /* Reinitialize filter; ie. tell it to reset to original values. */
1494 reinitialize_more_filter ()
1500 /* Indicate that if the next sequence of characters overflows the line,
1501 a newline should be inserted here rather than when it hits the end.
1502 If INDENT is non-null, it is a string to be printed to indent the
1503 wrapped part on the next line. INDENT must remain accessible until
1504 the next call to wrap_here() or until a newline is printed through
1507 If the line is already overfull, we immediately print a newline and
1508 the indentation, and disable further wrapping.
1510 If we don't know the width of lines, but we know the page height,
1511 we must not wrap words, but should still keep track of newlines
1512 that were explicitly printed.
1514 INDENT should not contain tabs, as that will mess up the char count
1515 on the next line. FIXME.
1517 This routine is guaranteed to force out any output which has been
1518 squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
1519 used to force out output from the wrap_buffer. */
1525 /* This should have been allocated, but be paranoid anyway. */
1531 *wrap_pointer = '\0';
1532 fputs_unfiltered (wrap_buffer, gdb_stdout);
1534 wrap_pointer = wrap_buffer;
1535 wrap_buffer[0] = '\0';
1536 if (chars_per_line == UINT_MAX) /* No line overflow checking */
1540 else if (chars_printed >= chars_per_line)
1542 puts_filtered ("\n");
1544 puts_filtered (indent);
1549 wrap_column = chars_printed;
1553 wrap_indent = indent;
1557 /* Ensure that whatever gets printed next, using the filtered output
1558 commands, starts at the beginning of the line. I.E. if there is
1559 any pending output for the current line, flush it and start a new
1560 line. Otherwise do nothing. */
1565 if (chars_printed > 0)
1567 puts_filtered ("\n");
1572 /* ``struct gdb_file'' implementation that maps directly onto
1573 <stdio.h>'s FILE. */
1575 static gdb_file_fputs_ftype stdio_file_fputs;
1576 static gdb_file_isatty_ftype stdio_file_isatty;
1577 static gdb_file_delete_ftype stdio_file_delete;
1578 static struct gdb_file *stdio_file_new PARAMS ((FILE * file, int close_p));
1579 static gdb_file_flush_ftype stdio_file_flush;
1581 static int stdio_file_magic;
1590 static struct gdb_file *
1591 stdio_file_new (file, close_p)
1595 struct gdb_file *gdb_file = gdb_file_new ();
1596 struct stdio_file *stdio = xmalloc (sizeof (struct stdio_file));
1597 stdio->magic = &stdio_file_magic;
1599 stdio->close_p = close_p;
1600 set_gdb_file_data (gdb_file, stdio, stdio_file_delete);
1601 set_gdb_file_flush (gdb_file, stdio_file_flush);
1602 set_gdb_file_fputs (gdb_file, stdio_file_fputs);
1603 set_gdb_file_isatty (gdb_file, stdio_file_isatty);
1608 stdio_file_delete (file)
1609 struct gdb_file *file;
1611 struct stdio_file *stdio = gdb_file_data (file);
1612 if (stdio->magic != &stdio_file_magic)
1613 error ("Internal error: bad magic number");
1616 fclose (stdio->file);
1622 stdio_file_flush (file)
1623 struct gdb_file *file;
1625 struct stdio_file *stdio = gdb_file_data (file);
1626 if (stdio->magic != &stdio_file_magic)
1627 error ("Internal error: bad magic number");
1628 fflush (stdio->file);
1632 stdio_file_fputs (linebuffer, file)
1633 const char *linebuffer;
1634 struct gdb_file *file;
1636 struct stdio_file *stdio = gdb_file_data (file);
1637 if (stdio->magic != &stdio_file_magic)
1638 error ("Internal error: bad magic number");
1639 fputs (linebuffer, stdio->file);
1643 stdio_file_isatty (file)
1644 struct gdb_file *file;
1646 struct stdio_file *stdio = gdb_file_data (file);
1647 if (stdio->magic != &stdio_file_magic)
1648 error ("Internal error: bad magic number");
1649 return (isatty (fileno (stdio->file)));
1652 /* Like fdopen(). Create a gdb_file from a previously opened FILE. */
1655 stdio_fileopen (file)
1658 return stdio_file_new (file, 0);
1662 /* A ``struct gdb_file'' that is compatible with all the legacy
1676 enum streamtype ts_streamtype;
1677 FILE *ts_filestream;
1682 static gdb_file_flush_ftype tui_file_flush;
1683 extern gdb_file_fputs_ftype tui_file_fputs;
1684 static gdb_file_isatty_ftype tui_file_isatty;
1685 static gdb_file_rewind_ftype tui_file_rewind;
1686 static gdb_file_put_ftype tui_file_put;
1687 static gdb_file_delete_ftype tui_file_delete;
1688 static struct gdb_file *tui_file_new PARAMS ((void));
1689 static int tui_file_magic;
1691 static struct gdb_file *
1694 struct tui_stream *tui = xmalloc (sizeof (struct tui_stream));
1695 struct gdb_file *file = gdb_file_new ();
1696 set_gdb_file_data (file, tui, tui_file_delete);
1697 set_gdb_file_flush (file, tui_file_flush);
1698 set_gdb_file_fputs (file, tui_file_fputs);
1699 set_gdb_file_isatty (file, tui_file_isatty);
1700 set_gdb_file_rewind (file, tui_file_rewind);
1701 set_gdb_file_put (file, tui_file_put);
1702 tui->ts_magic = &tui_file_magic;
1707 tui_file_delete (file)
1708 struct gdb_file *file;
1710 struct tui_stream *tmpstream = gdb_file_data (file);
1711 if (tmpstream->ts_magic != &tui_file_magic)
1712 error ("Internal error: bad magic number");
1713 if ((tmpstream->ts_streamtype == astring) &&
1714 (tmpstream->ts_strbuf != NULL))
1716 free (tmpstream->ts_strbuf);
1722 tui_fileopen (stream)
1725 struct gdb_file *file = tui_file_new ();
1726 struct tui_stream *tmpstream = gdb_file_data (file);
1727 tmpstream->ts_streamtype = afile;
1728 tmpstream->ts_filestream = stream;
1729 tmpstream->ts_strbuf = NULL;
1730 tmpstream->ts_buflen = 0;
1735 tui_file_isatty (file)
1736 struct gdb_file *file;
1738 struct tui_stream *stream = gdb_file_data (file);
1739 if (stream->ts_magic != &tui_file_magic)
1740 error ("Internal error: bad magic number");
1741 if (stream->ts_streamtype == afile)
1742 return (isatty (fileno (stream->ts_filestream)));
1748 tui_file_rewind (file)
1749 struct gdb_file *file;
1751 struct tui_stream *stream = gdb_file_data (file);
1752 if (stream->ts_magic != &tui_file_magic)
1753 error ("Internal error: bad magic number");
1754 stream->ts_strbuf[0] = '\0';
1758 tui_file_put (file, dest)
1759 struct gdb_file *file;
1760 struct gdb_file *dest;
1762 struct tui_stream *stream = gdb_file_data (file);
1763 if (stream->ts_magic != &tui_file_magic)
1764 error ("Internal error: bad magic number");
1765 if (stream->ts_streamtype == astring)
1767 fputs_unfiltered (stream->ts_strbuf, dest);
1771 /* All TUI I/O sent to the *_filtered and *_unfiltered functions
1772 eventually ends up here. The fputs_unfiltered_hook is primarily
1773 used by GUIs to collect all output and send it to the GUI, instead
1774 of the controlling terminal. Only output to gdb_stdout and
1775 gdb_stderr are sent to the hook. Everything else is sent on to
1776 fputs to allow file I/O to be handled appropriately. */
1778 /* FIXME: Should be broken up and moved to a TUI specific file. */
1781 tui_file_fputs (linebuffer, file)
1782 const char *linebuffer;
1785 struct tui_stream *stream = gdb_file_data (file);
1787 extern int tui_owns_terminal;
1789 /* If anything (GUI, TUI) wants to capture GDB output, this is
1790 * the place... the way to do it is to set up
1791 * fputs_unfiltered_hook.
1792 * Our TUI ("gdb -tui") used to hook output, but in the
1793 * new (XDB style) scheme, we do not do that anymore... - RT
1795 if (fputs_unfiltered_hook
1796 && (file == gdb_stdout
1797 || file == gdb_stderr))
1798 fputs_unfiltered_hook (linebuffer, file);
1802 if (tui_version && tui_owns_terminal)
1804 /* If we get here somehow while updating the TUI (from
1805 * within a tuiDo(), then we need to temporarily
1806 * set up the terminal for GDB output. This probably just
1807 * happens on error output.
1810 if (stream->ts_streamtype == astring)
1812 gdb_file_adjust_strbuf (strlen (linebuffer), stream);
1813 strcat (stream->ts_strbuf, linebuffer);
1817 tuiTermUnsetup (0, (tui_version) ? cmdWin->detail.commandInfo.curch : 0);
1818 fputs (linebuffer, stream->ts_filestream);
1820 if (linebuffer[strlen (linebuffer) - 1] == '\n')
1821 tuiClearCommandCharCount ();
1823 tuiIncrCommandCharCountBy (strlen (linebuffer));
1828 /* The normal case - just do a fputs() */
1829 if (stream->ts_streamtype == astring)
1831 gdb_file_adjust_strbuf (strlen (linebuffer), stream);
1832 strcat (stream->ts_strbuf, linebuffer);
1835 fputs (linebuffer, stream->ts_filestream);
1840 if (stream->ts_streamtype == astring)
1842 gdb_file_adjust_strbuf (strlen (linebuffer), file);
1843 strcat (stream->ts_strbuf, linebuffer);
1846 fputs (linebuffer, stream->ts_filestream);
1852 gdb_file_init_astring (n)
1855 struct gdb_file *file = tui_file_new ();
1856 struct tui_stream *tmpstream = gdb_file_data (file);
1857 if (tmpstream->ts_magic != &tui_file_magic)
1858 error ("Internal error: bad magic number");
1860 tmpstream->ts_streamtype = astring;
1861 tmpstream->ts_filestream = NULL;
1864 tmpstream->ts_strbuf = xmalloc ((n + 1) * sizeof (char));
1865 tmpstream->ts_strbuf[0] = '\0';
1868 tmpstream->ts_strbuf = NULL;
1869 tmpstream->ts_buflen = n;
1875 gdb_file_deallocate (streamptr)
1876 GDB_FILE **streamptr;
1878 gdb_file_delete (*streamptr);
1883 gdb_file_get_strbuf (file)
1886 struct tui_stream *stream = gdb_file_data (file);
1887 if (stream->ts_magic != &tui_file_magic)
1888 error ("Internal error: bad magic number");
1889 return (stream->ts_strbuf);
1892 /* adjust the length of the buffer by the amount necessary
1893 to accomodate appending a string of length N to the buffer contents */
1895 gdb_file_adjust_strbuf (n, file)
1899 struct tui_stream *stream = gdb_file_data (file);
1901 if (stream->ts_magic != &tui_file_magic)
1902 error ("Internal error: bad magic number");
1904 if (stream->ts_streamtype != astring)
1907 if (stream->ts_strbuf)
1909 /* There is already a buffer allocated */
1910 non_null_chars = strlen (stream->ts_strbuf);
1912 if (n > (stream->ts_buflen - non_null_chars - 1))
1914 stream->ts_buflen = n + non_null_chars + 1;
1915 stream->ts_strbuf = xrealloc (stream->ts_strbuf, stream->ts_buflen);
1919 /* No buffer yet, so allocate one of the desired size */
1920 stream->ts_strbuf = xmalloc ((n + 1) * sizeof (char));
1924 gdb_fopen (name, mode)
1928 FILE *f = fopen (name, mode);
1931 return stdio_file_new (f, 1);
1935 tui_file_flush (file)
1938 struct tui_stream *stream = gdb_file_data (file);
1939 if (stream->ts_magic != &tui_file_magic)
1940 error ("Internal error: bad magic number");
1942 && (file == gdb_stdout
1943 || file == gdb_stderr))
1949 fflush (stream->ts_filestream);
1953 gdb_fclose (streamptr)
1954 GDB_FILE **streamptr;
1956 gdb_file_delete (*streamptr);
1961 /* Implement the ``struct gdb_file'' object. */
1963 static gdb_file_isatty_ftype null_file_isatty;
1964 static gdb_file_fputs_ftype null_file_fputs;
1965 static gdb_file_flush_ftype null_file_flush;
1966 static gdb_file_delete_ftype null_file_delete;
1967 static gdb_file_rewind_ftype null_file_rewind;
1968 static gdb_file_put_ftype null_file_put;
1972 gdb_file_flush_ftype *to_flush;
1973 gdb_file_fputs_ftype *to_fputs;
1974 gdb_file_delete_ftype *to_delete;
1975 gdb_file_isatty_ftype *to_isatty;
1976 gdb_file_rewind_ftype *to_rewind;
1977 gdb_file_put_ftype *to_put;
1984 struct gdb_file *file = xmalloc (sizeof (struct gdb_file));
1985 set_gdb_file_data (file, NULL, null_file_delete);
1986 set_gdb_file_flush (file, null_file_flush);
1987 set_gdb_file_fputs (file, null_file_fputs);
1988 set_gdb_file_isatty (file, null_file_isatty);
1989 set_gdb_file_rewind (file, null_file_rewind);
1990 set_gdb_file_put (file, null_file_put);
1995 gdb_file_delete (file)
1996 struct gdb_file *file;
1998 file->to_delete (file);
2003 null_file_isatty (file)
2004 struct gdb_file *file;
2010 null_file_rewind (file)
2011 struct gdb_file *file;
2017 null_file_put (file, src)
2018 struct gdb_file *file;
2019 struct gdb_file *src;
2025 null_file_flush (file)
2026 struct gdb_file *file;
2032 null_file_fputs (buf, file)
2034 struct gdb_file *file;
2040 null_file_delete (file)
2041 struct gdb_file *file;
2047 gdb_file_data (file)
2048 struct gdb_file *file;
2050 return file->to_data;
2055 struct gdb_file *file;
2057 file->to_flush (file);
2061 gdb_file_isatty (file)
2062 struct gdb_file *file;
2064 return file->to_isatty (file);
2068 gdb_file_rewind (file)
2069 struct gdb_file *file;
2071 file->to_rewind (file);
2075 gdb_file_put (file, dest)
2076 struct gdb_file *file;
2077 struct gdb_file *dest;
2079 file->to_put (file, dest);
2083 fputs_unfiltered (buf, file)
2085 struct gdb_file *file;
2087 file->to_fputs (buf, file);
2091 set_gdb_file_flush (file, flush)
2092 struct gdb_file *file;
2093 gdb_file_flush_ftype *flush;
2095 file->to_flush = flush;
2099 set_gdb_file_isatty (file, isatty)
2100 struct gdb_file *file;
2101 gdb_file_isatty_ftype *isatty;
2103 file->to_isatty = isatty;
2107 set_gdb_file_rewind (file, rewind)
2108 struct gdb_file *file;
2109 gdb_file_rewind_ftype *rewind;
2111 file->to_rewind = rewind;
2115 set_gdb_file_put (file, put)
2116 struct gdb_file *file;
2117 gdb_file_put_ftype *put;
2123 set_gdb_file_fputs (file, fputs)
2124 struct gdb_file *file;
2125 gdb_file_fputs_ftype *fputs;
2127 file->to_fputs = fputs;
2131 set_gdb_file_data (file, data, delete)
2132 struct gdb_file *file;
2134 gdb_file_delete_ftype *delete;
2136 file->to_data = data;
2137 file->to_delete = delete;
2140 /* Like fputs but if FILTER is true, pause after every screenful.
2142 Regardless of FILTER can wrap at points other than the final
2143 character of a line.
2145 Unlike fputs, fputs_maybe_filtered does not return a value.
2146 It is OK for LINEBUFFER to be NULL, in which case just don't print
2149 Note that a longjmp to top level may occur in this routine (only if
2150 FILTER is true) (since prompt_for_continue may do so) so this
2151 routine should not be called when cleanups are not in place. */
2154 fputs_maybe_filtered (linebuffer, stream, filter)
2155 const char *linebuffer;
2159 const char *lineptr;
2161 if (linebuffer == 0)
2164 /* Don't do any filtering if it is disabled. */
2165 if ((stream != gdb_stdout) || !pagination_enabled
2166 || (lines_per_page == UINT_MAX && chars_per_line == UINT_MAX))
2168 fputs_unfiltered (linebuffer, stream);
2172 /* Go through and output each character. Show line extension
2173 when this is necessary; prompt user for new page when this is
2176 lineptr = linebuffer;
2179 /* Possible new page. */
2181 (lines_printed >= lines_per_page - 1))
2182 prompt_for_continue ();
2184 while (*lineptr && *lineptr != '\n')
2186 /* Print a single line. */
2187 if (*lineptr == '\t')
2190 *wrap_pointer++ = '\t';
2192 fputc_unfiltered ('\t', stream);
2193 /* Shifting right by 3 produces the number of tab stops
2194 we have already passed, and then adding one and
2195 shifting left 3 advances to the next tab stop. */
2196 chars_printed = ((chars_printed >> 3) + 1) << 3;
2202 *wrap_pointer++ = *lineptr;
2204 fputc_unfiltered (*lineptr, stream);
2209 if (chars_printed >= chars_per_line)
2211 unsigned int save_chars = chars_printed;
2215 /* If we aren't actually wrapping, don't output newline --
2216 if chars_per_line is right, we probably just overflowed
2217 anyway; if it's wrong, let us keep going. */
2219 fputc_unfiltered ('\n', stream);
2221 /* Possible new page. */
2222 if (lines_printed >= lines_per_page - 1)
2223 prompt_for_continue ();
2225 /* Now output indentation and wrapped string */
2228 fputs_unfiltered (wrap_indent, stream);
2229 *wrap_pointer = '\0'; /* Null-terminate saved stuff */
2230 fputs_unfiltered (wrap_buffer, stream); /* and eject it */
2231 /* FIXME, this strlen is what prevents wrap_indent from
2232 containing tabs. However, if we recurse to print it
2233 and count its chars, we risk trouble if wrap_indent is
2234 longer than (the user settable) chars_per_line.
2235 Note also that this can set chars_printed > chars_per_line
2236 if we are printing a long string. */
2237 chars_printed = strlen (wrap_indent)
2238 + (save_chars - wrap_column);
2239 wrap_pointer = wrap_buffer; /* Reset buffer */
2240 wrap_buffer[0] = '\0';
2241 wrap_column = 0; /* And disable fancy wrap */
2246 if (*lineptr == '\n')
2249 wrap_here ((char *) 0); /* Spit out chars, cancel further wraps */
2251 fputc_unfiltered ('\n', stream);
2258 fputs_filtered (linebuffer, stream)
2259 const char *linebuffer;
2262 fputs_maybe_filtered (linebuffer, stream, 1);
2266 putchar_unfiltered (c)
2273 fputs_unfiltered (buf, gdb_stdout);
2278 fputc_unfiltered (c, stream)
2286 fputs_unfiltered (buf, stream);
2291 fputc_filtered (c, stream)
2299 fputs_filtered (buf, stream);
2303 /* puts_debug is like fputs_unfiltered, except it prints special
2304 characters in printable fashion. */
2307 puts_debug (prefix, string, suffix)
2314 /* Print prefix and suffix after each line. */
2315 static int new_line = 1;
2316 static int return_p = 0;
2317 static char *prev_prefix = "";
2318 static char *prev_suffix = "";
2320 if (*string == '\n')
2323 /* If the prefix is changing, print the previous suffix, a new line,
2324 and the new prefix. */
2325 if ((return_p || (strcmp (prev_prefix, prefix) != 0)) && !new_line)
2327 fputs_unfiltered (prev_suffix, gdb_stdlog);
2328 fputs_unfiltered ("\n", gdb_stdlog);
2329 fputs_unfiltered (prefix, gdb_stdlog);
2332 /* Print prefix if we printed a newline during the previous call. */
2336 fputs_unfiltered (prefix, gdb_stdlog);
2339 prev_prefix = prefix;
2340 prev_suffix = suffix;
2342 /* Output characters in a printable format. */
2343 while ((ch = *string++) != '\0')
2349 fputc_unfiltered (ch, gdb_stdlog);
2352 fprintf_unfiltered (gdb_stdlog, "\\x%02x", ch & 0xff);
2356 fputs_unfiltered ("\\\\", gdb_stdlog);
2359 fputs_unfiltered ("\\b", gdb_stdlog);
2362 fputs_unfiltered ("\\f", gdb_stdlog);
2366 fputs_unfiltered ("\\n", gdb_stdlog);
2369 fputs_unfiltered ("\\r", gdb_stdlog);
2372 fputs_unfiltered ("\\t", gdb_stdlog);
2375 fputs_unfiltered ("\\v", gdb_stdlog);
2379 return_p = ch == '\r';
2382 /* Print suffix if we printed a newline. */
2385 fputs_unfiltered (suffix, gdb_stdlog);
2386 fputs_unfiltered ("\n", gdb_stdlog);
2391 /* Print a variable number of ARGS using format FORMAT. If this
2392 information is going to put the amount written (since the last call
2393 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
2394 call prompt_for_continue to get the users permision to continue.
2396 Unlike fprintf, this function does not return a value.
2398 We implement three variants, vfprintf (takes a vararg list and stream),
2399 fprintf (takes a stream to write on), and printf (the usual).
2401 Note also that a longjmp to top level may occur in this routine
2402 (since prompt_for_continue may do so) so this routine should not be
2403 called when cleanups are not in place. */
2406 vfprintf_maybe_filtered (stream, format, args, filter)
2413 struct cleanup *old_cleanups;
2415 vasprintf (&linebuffer, format, args);
2416 if (linebuffer == NULL)
2418 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);
2421 old_cleanups = make_cleanup (free, linebuffer);
2422 fputs_maybe_filtered (linebuffer, stream, filter);
2423 do_cleanups (old_cleanups);
2428 vfprintf_filtered (stream, format, args)
2433 vfprintf_maybe_filtered (stream, format, args, 1);
2437 vfprintf_unfiltered (stream, format, args)
2443 struct cleanup *old_cleanups;
2445 vasprintf (&linebuffer, format, args);
2446 if (linebuffer == NULL)
2448 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);
2451 old_cleanups = make_cleanup (free, linebuffer);
2452 fputs_unfiltered (linebuffer, stream);
2453 do_cleanups (old_cleanups);
2457 vprintf_filtered (format, args)
2461 vfprintf_maybe_filtered (gdb_stdout, format, args, 1);
2465 vprintf_unfiltered (format, args)
2469 vfprintf_unfiltered (gdb_stdout, format, args);
2473 fprintf_filtered (GDB_FILE * stream, const char *format,...)
2476 va_start (args, format);
2477 vfprintf_filtered (stream, format, args);
2482 fprintf_unfiltered (GDB_FILE * stream, const char *format,...)
2485 va_start (args, format);
2486 vfprintf_unfiltered (stream, format, args);
2490 /* Like fprintf_filtered, but prints its result indented.
2491 Called as fprintfi_filtered (spaces, stream, format, ...); */
2494 fprintfi_filtered (int spaces, GDB_FILE * stream, const char *format,...)
2497 va_start (args, format);
2498 print_spaces_filtered (spaces, stream);
2500 vfprintf_filtered (stream, format, args);
2506 printf_filtered (const char *format,...)
2509 va_start (args, format);
2510 vfprintf_filtered (gdb_stdout, format, args);
2516 printf_unfiltered (const char *format,...)
2519 va_start (args, format);
2520 vfprintf_unfiltered (gdb_stdout, format, args);
2524 /* Like printf_filtered, but prints it's result indented.
2525 Called as printfi_filtered (spaces, format, ...); */
2528 printfi_filtered (int spaces, const char *format,...)
2531 va_start (args, format);
2532 print_spaces_filtered (spaces, gdb_stdout);
2533 vfprintf_filtered (gdb_stdout, format, args);
2537 /* Easy -- but watch out!
2539 This routine is *not* a replacement for puts()! puts() appends a newline.
2540 This one doesn't, and had better not! */
2543 puts_filtered (string)
2546 fputs_filtered (string, gdb_stdout);
2550 puts_unfiltered (string)
2553 fputs_unfiltered (string, gdb_stdout);
2556 /* Return a pointer to N spaces and a null. The pointer is good
2557 until the next call to here. */
2563 static char *spaces = 0;
2564 static int max_spaces = -1;
2570 spaces = (char *) xmalloc (n + 1);
2571 for (t = spaces + n; t != spaces;)
2577 return spaces + max_spaces - n;
2580 /* Print N spaces. */
2582 print_spaces_filtered (n, stream)
2586 fputs_filtered (n_spaces (n), stream);
2589 /* C++ demangler stuff. */
2591 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
2592 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
2593 If the name is not mangled, or the language for the name is unknown, or
2594 demangling is off, the name is printed in its "raw" form. */
2597 fprintf_symbol_filtered (stream, name, lang, arg_mode)
2607 /* If user wants to see raw output, no problem. */
2610 fputs_filtered (name, stream);
2616 case language_cplus:
2617 demangled = cplus_demangle (name, arg_mode);
2620 demangled = cplus_demangle (name, arg_mode | DMGL_JAVA);
2622 case language_chill:
2623 demangled = chill_demangle (name);
2629 fputs_filtered (demangled ? demangled : name, stream);
2630 if (demangled != NULL)
2638 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
2639 differences in whitespace. Returns 0 if they match, non-zero if they
2640 don't (slightly different than strcmp()'s range of return values).
2642 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
2643 This "feature" is useful when searching for matching C++ function names
2644 (such as if the user types 'break FOO', where FOO is a mangled C++
2648 strcmp_iw (string1, string2)
2649 const char *string1;
2650 const char *string2;
2652 while ((*string1 != '\0') && (*string2 != '\0'))
2654 while (isspace (*string1))
2658 while (isspace (*string2))
2662 if (*string1 != *string2)
2666 if (*string1 != '\0')
2672 return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
2678 ** Answer whether string_to_compare is a full or partial match to
2679 ** template_string. The partial match must be in sequence starting
2683 subset_compare (string_to_compare, template_string)
2684 char *string_to_compare;
2685 char *template_string;
2688 if (template_string != (char *) NULL && string_to_compare != (char *) NULL &&
2689 strlen (string_to_compare) <= strlen (template_string))
2690 match = (strncmp (template_string,
2692 strlen (string_to_compare)) == 0);
2699 static void pagination_on_command PARAMS ((char *arg, int from_tty));
2701 pagination_on_command (arg, from_tty)
2705 pagination_enabled = 1;
2708 static void pagination_on_command PARAMS ((char *arg, int from_tty));
2710 pagination_off_command (arg, from_tty)
2714 pagination_enabled = 0;
2721 struct cmd_list_element *c;
2723 c = add_set_cmd ("width", class_support, var_uinteger,
2724 (char *) &chars_per_line,
2725 "Set number of characters gdb thinks are in a line.",
2727 add_show_from_set (c, &showlist);
2728 c->function.sfunc = set_width_command;
2731 (add_set_cmd ("height", class_support,
2732 var_uinteger, (char *) &lines_per_page,
2733 "Set number of lines gdb thinks are in a page.", &setlist),
2738 /* If the output is not a terminal, don't paginate it. */
2739 if (!GDB_FILE_ISATTY (gdb_stdout))
2740 lines_per_page = UINT_MAX;
2742 set_width_command ((char *) NULL, 0, c);
2745 (add_set_cmd ("demangle", class_support, var_boolean,
2747 "Set demangling of encoded C++ names when displaying symbols.",
2752 (add_set_cmd ("pagination", class_support,
2753 var_boolean, (char *) &pagination_enabled,
2754 "Set state of pagination.", &setlist),
2758 add_com ("am", class_support, pagination_on_command,
2759 "Enable pagination");
2760 add_com ("sm", class_support, pagination_off_command,
2761 "Disable pagination");
2765 (add_set_cmd ("sevenbit-strings", class_support, var_boolean,
2766 (char *) &sevenbit_strings,
2767 "Set printing of 8-bit characters in strings as \\nnn.",
2772 (add_set_cmd ("asm-demangle", class_support, var_boolean,
2773 (char *) &asm_demangle,
2774 "Set demangling of C++ names in disassembly listings.",
2779 /* Machine specific function to handle SIGWINCH signal. */
2781 #ifdef SIGWINCH_HANDLER_BODY
2782 SIGWINCH_HANDLER_BODY
2785 /* Support for converting target fp numbers into host DOUBLEST format. */
2787 /* XXX - This code should really be in libiberty/floatformat.c, however
2788 configuration issues with libiberty made this very difficult to do in the
2791 #include "floatformat.h"
2792 #include <math.h> /* ldexp */
2794 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
2795 going to bother with trying to muck around with whether it is defined in
2796 a system header, what we do if not, etc. */
2797 #define FLOATFORMAT_CHAR_BIT 8
2799 static unsigned long get_field PARAMS ((unsigned char *,
2800 enum floatformat_byteorders,
2805 /* Extract a field which starts at START and is LEN bytes long. DATA and
2806 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2807 static unsigned long
2808 get_field (data, order, total_len, start, len)
2809 unsigned char *data;
2810 enum floatformat_byteorders order;
2811 unsigned int total_len;
2815 unsigned long result;
2816 unsigned int cur_byte;
2819 /* Start at the least significant part of the field. */
2820 cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
2821 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2822 cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1;
2824 ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
2825 result = *(data + cur_byte) >> (-cur_bitshift);
2826 cur_bitshift += FLOATFORMAT_CHAR_BIT;
2827 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2832 /* Move towards the most significant part of the field. */
2833 while (cur_bitshift < len)
2835 if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
2836 /* This is the last byte; zero out the bits which are not part of
2839 (*(data + cur_byte) & ((1 << (len - cur_bitshift)) - 1))
2842 result |= *(data + cur_byte) << cur_bitshift;
2843 cur_bitshift += FLOATFORMAT_CHAR_BIT;
2844 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2852 /* Convert from FMT to a DOUBLEST.
2853 FROM is the address of the extended float.
2854 Store the DOUBLEST in *TO. */
2857 floatformat_to_doublest (fmt, from, to)
2858 const struct floatformat *fmt;
2862 unsigned char *ufrom = (unsigned char *) from;
2866 unsigned int mant_bits, mant_off;
2868 int special_exponent; /* It's a NaN, denorm or zero */
2870 /* If the mantissa bits are not contiguous from one end of the
2871 mantissa to the other, we need to make a private copy of the
2872 source bytes that is in the right order since the unpacking
2873 algorithm assumes that the bits are contiguous.
2875 Swap the bytes individually rather than accessing them through
2876 "long *" since we have no guarantee that they start on a long
2877 alignment, and also sizeof(long) for the host could be different
2878 than sizeof(long) for the target. FIXME: Assumes sizeof(long)
2879 for the target is 4. */
2881 if (fmt->byteorder == floatformat_littlebyte_bigword)
2883 static unsigned char *newfrom;
2884 unsigned char *swapin, *swapout;
2887 longswaps = fmt->totalsize / FLOATFORMAT_CHAR_BIT;
2890 if (newfrom == NULL)
2892 newfrom = (unsigned char *) xmalloc (fmt->totalsize);
2897 while (longswaps-- > 0)
2899 /* This is ugly, but efficient */
2900 *swapout++ = swapin[4];
2901 *swapout++ = swapin[5];
2902 *swapout++ = swapin[6];
2903 *swapout++ = swapin[7];
2904 *swapout++ = swapin[0];
2905 *swapout++ = swapin[1];
2906 *swapout++ = swapin[2];
2907 *swapout++ = swapin[3];
2912 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
2913 fmt->exp_start, fmt->exp_len);
2914 /* Note that if exponent indicates a NaN, we can't really do anything useful
2915 (not knowing if the host has NaN's, or how to build one). So it will
2916 end up as an infinity or something close; that is OK. */
2918 mant_bits_left = fmt->man_len;
2919 mant_off = fmt->man_start;
2922 special_exponent = exponent == 0 || exponent == fmt->exp_nan;
2924 /* Don't bias zero's, denorms or NaNs. */
2925 if (!special_exponent)
2926 exponent -= fmt->exp_bias;
2928 /* Build the result algebraically. Might go infinite, underflow, etc;
2931 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
2932 increment the exponent by one to account for the integer bit. */
2934 if (!special_exponent)
2936 if (fmt->intbit == floatformat_intbit_no)
2937 dto = ldexp (1.0, exponent);
2942 while (mant_bits_left > 0)
2944 mant_bits = min (mant_bits_left, 32);
2946 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
2947 mant_off, mant_bits);
2949 dto += ldexp ((double) mant, exponent - mant_bits);
2950 exponent -= mant_bits;
2951 mant_off += mant_bits;
2952 mant_bits_left -= mant_bits;
2955 /* Negate it if negative. */
2956 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
2961 static void put_field PARAMS ((unsigned char *, enum floatformat_byteorders,
2967 /* Set a field which starts at START and is LEN bytes long. DATA and
2968 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2970 put_field (data, order, total_len, start, len, stuff_to_put)
2971 unsigned char *data;
2972 enum floatformat_byteorders order;
2973 unsigned int total_len;
2976 unsigned long stuff_to_put;
2978 unsigned int cur_byte;
2981 /* Start at the least significant part of the field. */
2982 cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
2983 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2984 cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1;
2986 ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
2987 *(data + cur_byte) &=
2988 ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1) << (-cur_bitshift));
2989 *(data + cur_byte) |=
2990 (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift);
2991 cur_bitshift += FLOATFORMAT_CHAR_BIT;
2992 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2997 /* Move towards the most significant part of the field. */
2998 while (cur_bitshift < len)
3000 if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
3002 /* This is the last byte. */
3003 *(data + cur_byte) &=
3004 ~((1 << (len - cur_bitshift)) - 1);
3005 *(data + cur_byte) |= (stuff_to_put >> cur_bitshift);
3008 *(data + cur_byte) = ((stuff_to_put >> cur_bitshift)
3009 & ((1 << FLOATFORMAT_CHAR_BIT) - 1));
3010 cur_bitshift += FLOATFORMAT_CHAR_BIT;
3011 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
3018 #ifdef HAVE_LONG_DOUBLE
3019 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
3020 The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
3021 frexp, but operates on the long double data type. */
3023 static long double ldfrexp PARAMS ((long double value, int *eptr));
3026 ldfrexp (value, eptr)
3033 /* Unfortunately, there are no portable functions for extracting the exponent
3034 of a long double, so we have to do it iteratively by multiplying or dividing
3035 by two until the fraction is between 0.5 and 1.0. */
3043 if (value >= tmp) /* Value >= 1.0 */
3044 while (value >= tmp)
3049 else if (value != 0.0l) /* Value < 1.0 and > 0.0 */
3063 #endif /* HAVE_LONG_DOUBLE */
3066 /* The converse: convert the DOUBLEST *FROM to an extended float
3067 and store where TO points. Neither FROM nor TO have any alignment
3071 floatformat_from_doublest (fmt, from, to)
3072 CONST struct floatformat *fmt;
3079 unsigned int mant_bits, mant_off;
3081 unsigned char *uto = (unsigned char *) to;
3083 memcpy (&dfrom, from, sizeof (dfrom));
3084 memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT);
3086 return; /* Result is zero */
3087 if (dfrom != dfrom) /* Result is NaN */
3090 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
3091 fmt->exp_len, fmt->exp_nan);
3092 /* Be sure it's not infinity, but NaN value is irrel */
3093 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
3098 /* If negative, set the sign bit. */
3101 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
3105 if (dfrom + dfrom == dfrom && dfrom != 0.0) /* Result is Infinity */
3107 /* Infinity exponent is same as NaN's. */
3108 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
3109 fmt->exp_len, fmt->exp_nan);
3110 /* Infinity mantissa is all zeroes. */
3111 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
3116 #ifdef HAVE_LONG_DOUBLE
3117 mant = ldfrexp (dfrom, &exponent);
3119 mant = frexp (dfrom, &exponent);
3122 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
3123 exponent + fmt->exp_bias - 1);
3125 mant_bits_left = fmt->man_len;
3126 mant_off = fmt->man_start;
3127 while (mant_bits_left > 0)
3129 unsigned long mant_long;
3130 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
3132 mant *= 4294967296.0;
3133 mant_long = (unsigned long) mant;
3136 /* If the integer bit is implicit, then we need to discard it.
3137 If we are discarding a zero, we should be (but are not) creating
3138 a denormalized number which means adjusting the exponent
3140 if (mant_bits_left == fmt->man_len
3141 && fmt->intbit == floatformat_intbit_no)
3149 /* The bits we want are in the most significant MANT_BITS bits of
3150 mant_long. Move them to the least significant. */
3151 mant_long >>= 32 - mant_bits;
3154 put_field (uto, fmt->byteorder, fmt->totalsize,
3155 mant_off, mant_bits, mant_long);
3156 mant_off += mant_bits;
3157 mant_bits_left -= mant_bits;
3159 if (fmt->byteorder == floatformat_littlebyte_bigword)
3162 unsigned char *swaplow = uto;
3163 unsigned char *swaphigh = uto + 4;
3166 for (count = 0; count < 4; count++)
3169 *swaplow++ = *swaphigh;
3175 /* temporary storage using circular buffer */
3181 static char buf[NUMCELLS][CELLSIZE];
3182 static int cell = 0;
3183 if (++cell >= NUMCELLS)
3188 /* print routines to handle variable size regs, etc.
3190 FIXME: Note that t_addr is a bfd_vma, which is currently either an
3191 unsigned long or unsigned long long, determined at configure time.
3192 If t_addr is an unsigned long long and sizeof (unsigned long long)
3193 is greater than sizeof (unsigned long), then I believe this code will
3194 probably lose, at least for little endian machines. I believe that
3195 it would also be better to eliminate the switch on the absolute size
3196 of t_addr and replace it with a sequence of if statements that compare
3197 sizeof t_addr with sizeof the various types and do the right thing,
3198 which includes knowing whether or not the host supports long long.
3203 /* eliminate warning from compiler on 32-bit systems */
3204 static int thirty_two = 32;
3207 paddr (CORE_ADDR addr)
3209 char *paddr_str = get_cell ();
3210 switch (TARGET_PTR_BIT / 8)
3213 sprintf (paddr_str, "%08lx%08lx",
3214 (unsigned long) (addr >> thirty_two), (unsigned long) (addr & 0xffffffff));
3217 sprintf (paddr_str, "%08lx", (unsigned long) addr);
3220 sprintf (paddr_str, "%04x", (unsigned short) (addr & 0xffff));
3223 sprintf (paddr_str, "%lx", (unsigned long) addr);
3229 paddr_nz (CORE_ADDR addr)
3231 char *paddr_str = get_cell ();
3232 switch (TARGET_PTR_BIT / 8)
3236 unsigned long high = (unsigned long) (addr >> thirty_two);
3238 sprintf (paddr_str, "%lx", (unsigned long) (addr & 0xffffffff));
3240 sprintf (paddr_str, "%lx%08lx",
3241 high, (unsigned long) (addr & 0xffffffff));
3245 sprintf (paddr_str, "%lx", (unsigned long) addr);
3248 sprintf (paddr_str, "%x", (unsigned short) (addr & 0xffff));
3251 sprintf (paddr_str, "%lx", (unsigned long) addr);
3257 decimal2str (char *paddr_str, char *sign, ULONGEST addr)
3259 /* steal code from valprint.c:print_decimal(). Should this worry
3260 about the real size of addr as the above does? */
3261 unsigned long temp[3];
3265 temp[i] = addr % (1000 * 1000 * 1000);
3266 addr /= (1000 * 1000 * 1000);
3269 while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
3273 sprintf (paddr_str, "%s%lu",
3277 sprintf (paddr_str, "%s%lu%09lu",
3278 sign, temp[1], temp[0]);
3281 sprintf (paddr_str, "%s%lu%09lu%09lu",
3282 sign, temp[2], temp[1], temp[0]);
3290 paddr_u (CORE_ADDR addr)
3292 char *paddr_str = get_cell ();
3293 decimal2str (paddr_str, "", addr);
3298 paddr_d (LONGEST addr)
3300 char *paddr_str = get_cell ();
3302 decimal2str (paddr_str, "-", -addr);
3304 decimal2str (paddr_str, "", addr);
3312 char *preg_str = get_cell ();
3313 switch (sizeof (t_reg))
3316 sprintf (preg_str, "%08lx%08lx",
3317 (unsigned long) (reg >> thirty_two), (unsigned long) (reg & 0xffffffff));
3320 sprintf (preg_str, "%08lx", (unsigned long) reg);
3323 sprintf (preg_str, "%04x", (unsigned short) (reg & 0xffff));
3326 sprintf (preg_str, "%lx", (unsigned long) reg);
3335 char *preg_str = get_cell ();
3336 switch (sizeof (t_reg))
3340 unsigned long high = (unsigned long) (reg >> thirty_two);
3342 sprintf (preg_str, "%lx", (unsigned long) (reg & 0xffffffff));
3344 sprintf (preg_str, "%lx%08lx",
3345 high, (unsigned long) (reg & 0xffffffff));
3349 sprintf (preg_str, "%lx", (unsigned long) reg);
3352 sprintf (preg_str, "%x", (unsigned short) (reg & 0xffff));
3355 sprintf (preg_str, "%lx", (unsigned long) reg);
3360 /* Helper functions for INNER_THAN */
3362 core_addr_lessthan (lhs, rhs)
3370 core_addr_greaterthan (lhs, rhs)