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_host_address (void *addr, struct gdb_file *stream)
1002 /* We could use the %p conversion specifier to fprintf if we had any
1003 way of knowing whether this host supports it. But the following
1004 should work on the Alpha and on 32 bit machines. */
1006 fprintf_filtered (stream, "0x%lx", (unsigned long) addr);
1009 /* Ask user a y-or-n question and return 1 iff answer is yes.
1010 Takes three args which are given to printf to print the question.
1011 The first, a control string, should end in "? ".
1012 It should not say how to answer, because we do that. */
1016 query (char *ctlstr,...)
1019 register int answer;
1023 va_start (args, ctlstr);
1027 return query_hook (ctlstr, args);
1030 /* Automatically answer "yes" if input is not from a terminal. */
1031 if (!input_from_terminal_p ())
1034 /* FIXME Automatically answer "yes" if called from MacGDB. */
1041 wrap_here (""); /* Flush any buffered output */
1042 gdb_flush (gdb_stdout);
1044 if (annotation_level > 1)
1045 printf_filtered ("\n\032\032pre-query\n");
1047 vfprintf_filtered (gdb_stdout, ctlstr, args);
1048 printf_filtered ("(y or n) ");
1050 if (annotation_level > 1)
1051 printf_filtered ("\n\032\032query\n");
1054 /* If not in MacGDB, move to a new line so the entered line doesn't
1055 have a prompt on the front of it. */
1057 fputs_unfiltered ("\n", gdb_stdout);
1061 gdb_flush (gdb_stdout);
1064 if (!tui_version || cmdWin == tuiWinWithFocus ())
1066 answer = fgetc (stdin);
1069 answer = (unsigned char) tuiBufferGetc ();
1072 clearerr (stdin); /* in case of C-d */
1073 if (answer == EOF) /* C-d */
1078 /* Eat rest of input line, to EOF or newline */
1079 if ((answer != '\n') || (tui_version && answer != '\r'))
1083 if (!tui_version || cmdWin == tuiWinWithFocus ())
1085 ans2 = fgetc (stdin);
1088 ans2 = (unsigned char) tuiBufferGetc ();
1092 while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
1093 TUIDO (((TuiOpaqueFuncPtr) tui_vStartNewLines, 1));
1107 printf_filtered ("Please answer y or n.\n");
1110 if (annotation_level > 1)
1111 printf_filtered ("\n\032\032post-query\n");
1116 /* Parse a C escape sequence. STRING_PTR points to a variable
1117 containing a pointer to the string to parse. That pointer
1118 should point to the character after the \. That pointer
1119 is updated past the characters we use. The value of the
1120 escape sequence is returned.
1122 A negative value means the sequence \ newline was seen,
1123 which is supposed to be equivalent to nothing at all.
1125 If \ is followed by a null character, we return a negative
1126 value and leave the string pointer pointing at the null character.
1128 If \ is followed by 000, we return 0 and leave the string pointer
1129 after the zeros. A value of 0 does not mean end of string. */
1132 parse_escape (string_ptr)
1135 register int c = *(*string_ptr)++;
1139 return 007; /* Bell (alert) char */
1142 case 'e': /* Escape character */
1160 c = *(*string_ptr)++;
1162 c = parse_escape (string_ptr);
1165 return (c & 0200) | (c & 037);
1176 register int i = c - '0';
1177 register int count = 0;
1180 if ((c = *(*string_ptr)++) >= '0' && c <= '7')
1198 /* Print the character C on STREAM as part of the contents of a literal
1199 string whose delimiter is QUOTER. Note that this routine should only
1200 be call for printing things which are independent of the language
1201 of the program being debugged. */
1203 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));
1206 printchar (c, do_fputs, do_fprintf, stream, quoter)
1208 void (*do_fputs) PARAMS ((const char *, GDB_FILE*));
1209 void (*do_fprintf) PARAMS ((GDB_FILE*, const char *, ...));
1214 c &= 0xFF; /* Avoid sign bit follies */
1216 if (c < 0x20 || /* Low control chars */
1217 (c >= 0x7F && c < 0xA0) || /* DEL, High controls */
1218 (sevenbit_strings && c >= 0x80))
1219 { /* high order bit set */
1223 do_fputs ("\\n", stream);
1226 do_fputs ("\\b", stream);
1229 do_fputs ("\\t", stream);
1232 do_fputs ("\\f", stream);
1235 do_fputs ("\\r", stream);
1238 do_fputs ("\\e", stream);
1241 do_fputs ("\\a", stream);
1244 do_fprintf (stream, "\\%.3o", (unsigned int) c);
1250 if (c == '\\' || c == quoter)
1251 do_fputs ("\\", stream);
1252 do_fprintf (stream, "%c", c);
1256 /* Print the character C on STREAM as part of the contents of a
1257 literal string whose delimiter is QUOTER. Note that these routines
1258 should only be call for printing things which are independent of
1259 the language of the program being debugged. */
1262 fputstr_filtered (str, quoter, stream)
1268 printchar (*str++, fputs_filtered, fprintf_filtered, stream, quoter);
1272 fputstr_unfiltered (str, quoter, stream)
1278 printchar (*str++, fputs_unfiltered, fprintf_unfiltered, stream, quoter);
1282 fputstrn_unfiltered (str, n, quoter, stream)
1289 for (i = 0; i < n; i++)
1290 printchar (str[i], fputs_unfiltered, fprintf_unfiltered, stream, quoter);
1295 /* Number of lines per page or UINT_MAX if paging is disabled. */
1296 static unsigned int lines_per_page;
1297 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
1298 static unsigned int chars_per_line;
1299 /* Current count of lines printed on this page, chars on this line. */
1300 static unsigned int lines_printed, chars_printed;
1302 /* Buffer and start column of buffered text, for doing smarter word-
1303 wrapping. When someone calls wrap_here(), we start buffering output
1304 that comes through fputs_filtered(). If we see a newline, we just
1305 spit it out and forget about the wrap_here(). If we see another
1306 wrap_here(), we spit it out and remember the newer one. If we see
1307 the end of the line, we spit out a newline, the indent, and then
1308 the buffered output. */
1310 /* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
1311 are waiting to be output (they have already been counted in chars_printed).
1312 When wrap_buffer[0] is null, the buffer is empty. */
1313 static char *wrap_buffer;
1315 /* Pointer in wrap_buffer to the next character to fill. */
1316 static char *wrap_pointer;
1318 /* String to indent by if the wrap occurs. Must not be NULL if wrap_column
1320 static char *wrap_indent;
1322 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
1323 is not in effect. */
1324 static int wrap_column;
1327 /* Inialize the lines and chars per page */
1332 if (tui_version && m_winPtrNotNull (cmdWin))
1334 lines_per_page = cmdWin->generic.height;
1335 chars_per_line = cmdWin->generic.width;
1340 /* These defaults will be used if we are unable to get the correct
1341 values from termcap. */
1342 #if defined(__GO32__)
1343 lines_per_page = ScreenRows ();
1344 chars_per_line = ScreenCols ();
1346 lines_per_page = 24;
1347 chars_per_line = 80;
1349 #if !defined (MPW) && !defined (_WIN32)
1350 /* No termcap under MPW, although might be cool to do something
1351 by looking at worksheet or console window sizes. */
1352 /* Initialize the screen height and width from termcap. */
1354 char *termtype = getenv ("TERM");
1356 /* Positive means success, nonpositive means failure. */
1359 /* 2048 is large enough for all known terminals, according to the
1360 GNU termcap manual. */
1361 char term_buffer[2048];
1365 status = tgetent (term_buffer, termtype);
1369 int running_in_emacs = getenv ("EMACS") != NULL;
1371 val = tgetnum ("li");
1372 if (val >= 0 && !running_in_emacs)
1373 lines_per_page = val;
1375 /* The number of lines per page is not mentioned
1376 in the terminal description. This probably means
1377 that paging is not useful (e.g. emacs shell window),
1378 so disable paging. */
1379 lines_per_page = UINT_MAX;
1381 val = tgetnum ("co");
1383 chars_per_line = val;
1389 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1391 /* If there is a better way to determine the window size, use it. */
1392 SIGWINCH_HANDLER (SIGWINCH);
1395 /* If the output is not a terminal, don't paginate it. */
1396 if (!GDB_FILE_ISATTY (gdb_stdout))
1397 lines_per_page = UINT_MAX;
1398 } /* the command_line_version */
1405 if (chars_per_line == 0)
1410 wrap_buffer = (char *) xmalloc (chars_per_line + 2);
1411 wrap_buffer[0] = '\0';
1414 wrap_buffer = (char *) xrealloc (wrap_buffer, chars_per_line + 2);
1415 wrap_pointer = wrap_buffer; /* Start it at the beginning */
1420 set_width_command (args, from_tty, c)
1423 struct cmd_list_element *c;
1428 /* Wait, so the user can read what's on the screen. Prompt the user
1429 to continue by pressing RETURN. */
1432 prompt_for_continue ()
1435 char cont_prompt[120];
1437 if (annotation_level > 1)
1438 printf_unfiltered ("\n\032\032pre-prompt-for-continue\n");
1440 strcpy (cont_prompt,
1441 "---Type <return> to continue, or q <return> to quit---");
1442 if (annotation_level > 1)
1443 strcat (cont_prompt, "\n\032\032prompt-for-continue\n");
1445 /* We must do this *before* we call gdb_readline, else it will eventually
1446 call us -- thinking that we're trying to print beyond the end of the
1448 reinitialize_more_filter ();
1451 /* On a real operating system, the user can quit with SIGINT.
1454 'q' is provided on all systems so users don't have to change habits
1455 from system to system, and because telling them what to do in
1456 the prompt is more user-friendly than expecting them to think of
1458 /* Call readline, not gdb_readline, because GO32 readline handles control-C
1459 whereas control-C to gdb_readline will cause the user to get dumped
1461 ignore = readline (cont_prompt);
1463 if (annotation_level > 1)
1464 printf_unfiltered ("\n\032\032post-prompt-for-continue\n");
1469 while (*p == ' ' || *p == '\t')
1474 request_quit (SIGINT);
1476 async_request_quit (0);
1482 /* Now we have to do this again, so that GDB will know that it doesn't
1483 need to save the ---Type <return>--- line at the top of the screen. */
1484 reinitialize_more_filter ();
1486 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
1489 /* Reinitialize filter; ie. tell it to reset to original values. */
1492 reinitialize_more_filter ()
1498 /* Indicate that if the next sequence of characters overflows the line,
1499 a newline should be inserted here rather than when it hits the end.
1500 If INDENT is non-null, it is a string to be printed to indent the
1501 wrapped part on the next line. INDENT must remain accessible until
1502 the next call to wrap_here() or until a newline is printed through
1505 If the line is already overfull, we immediately print a newline and
1506 the indentation, and disable further wrapping.
1508 If we don't know the width of lines, but we know the page height,
1509 we must not wrap words, but should still keep track of newlines
1510 that were explicitly printed.
1512 INDENT should not contain tabs, as that will mess up the char count
1513 on the next line. FIXME.
1515 This routine is guaranteed to force out any output which has been
1516 squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
1517 used to force out output from the wrap_buffer. */
1523 /* This should have been allocated, but be paranoid anyway. */
1529 *wrap_pointer = '\0';
1530 fputs_unfiltered (wrap_buffer, gdb_stdout);
1532 wrap_pointer = wrap_buffer;
1533 wrap_buffer[0] = '\0';
1534 if (chars_per_line == UINT_MAX) /* No line overflow checking */
1538 else if (chars_printed >= chars_per_line)
1540 puts_filtered ("\n");
1542 puts_filtered (indent);
1547 wrap_column = chars_printed;
1551 wrap_indent = indent;
1555 /* Ensure that whatever gets printed next, using the filtered output
1556 commands, starts at the beginning of the line. I.E. if there is
1557 any pending output for the current line, flush it and start a new
1558 line. Otherwise do nothing. */
1563 if (chars_printed > 0)
1565 puts_filtered ("\n");
1570 /* ``struct gdb_file'' implementation that maps directly onto
1571 <stdio.h>'s FILE. */
1573 static gdb_file_fputs_ftype stdio_file_fputs;
1574 static gdb_file_isatty_ftype stdio_file_isatty;
1575 static gdb_file_delete_ftype stdio_file_delete;
1576 static struct gdb_file *stdio_file_new PARAMS ((FILE * file, int close_p));
1577 static gdb_file_flush_ftype stdio_file_flush;
1579 static int stdio_file_magic;
1588 static struct gdb_file *
1589 stdio_file_new (file, close_p)
1593 struct gdb_file *gdb_file = gdb_file_new ();
1594 struct stdio_file *stdio = xmalloc (sizeof (struct stdio_file));
1595 stdio->magic = &stdio_file_magic;
1597 stdio->close_p = close_p;
1598 set_gdb_file_data (gdb_file, stdio, stdio_file_delete);
1599 set_gdb_file_flush (gdb_file, stdio_file_flush);
1600 set_gdb_file_fputs (gdb_file, stdio_file_fputs);
1601 set_gdb_file_isatty (gdb_file, stdio_file_isatty);
1606 stdio_file_delete (file)
1607 struct gdb_file *file;
1609 struct stdio_file *stdio = gdb_file_data (file);
1610 if (stdio->magic != &stdio_file_magic)
1611 error ("Internal error: bad magic number");
1614 fclose (stdio->file);
1620 stdio_file_flush (file)
1621 struct gdb_file *file;
1623 struct stdio_file *stdio = gdb_file_data (file);
1624 if (stdio->magic != &stdio_file_magic)
1625 error ("Internal error: bad magic number");
1626 fflush (stdio->file);
1630 stdio_file_fputs (linebuffer, file)
1631 const char *linebuffer;
1632 struct gdb_file *file;
1634 struct stdio_file *stdio = gdb_file_data (file);
1635 if (stdio->magic != &stdio_file_magic)
1636 error ("Internal error: bad magic number");
1637 fputs (linebuffer, stdio->file);
1641 stdio_file_isatty (file)
1642 struct gdb_file *file;
1644 struct stdio_file *stdio = gdb_file_data (file);
1645 if (stdio->magic != &stdio_file_magic)
1646 error ("Internal error: bad magic number");
1647 return (isatty (fileno (stdio->file)));
1650 /* Like fdopen(). Create a gdb_file from a previously opened FILE. */
1653 stdio_fileopen (file)
1656 return stdio_file_new (file, 0);
1660 /* A ``struct gdb_file'' that is compatible with all the legacy
1674 enum streamtype ts_streamtype;
1675 FILE *ts_filestream;
1680 static gdb_file_flush_ftype tui_file_flush;
1681 extern gdb_file_fputs_ftype tui_file_fputs;
1682 static gdb_file_isatty_ftype tui_file_isatty;
1683 static gdb_file_rewind_ftype tui_file_rewind;
1684 static gdb_file_put_ftype tui_file_put;
1685 static gdb_file_delete_ftype tui_file_delete;
1686 static struct gdb_file *tui_file_new PARAMS ((void));
1687 static int tui_file_magic;
1689 static struct gdb_file *
1692 struct tui_stream *tui = xmalloc (sizeof (struct tui_stream));
1693 struct gdb_file *file = gdb_file_new ();
1694 set_gdb_file_data (file, tui, tui_file_delete);
1695 set_gdb_file_flush (file, tui_file_flush);
1696 set_gdb_file_fputs (file, tui_file_fputs);
1697 set_gdb_file_isatty (file, tui_file_isatty);
1698 set_gdb_file_rewind (file, tui_file_rewind);
1699 set_gdb_file_put (file, tui_file_put);
1700 tui->ts_magic = &tui_file_magic;
1705 tui_file_delete (file)
1706 struct gdb_file *file;
1708 struct tui_stream *tmpstream = gdb_file_data (file);
1709 if (tmpstream->ts_magic != &tui_file_magic)
1710 error ("Internal error: bad magic number");
1711 if ((tmpstream->ts_streamtype == astring) &&
1712 (tmpstream->ts_strbuf != NULL))
1714 free (tmpstream->ts_strbuf);
1720 tui_fileopen (stream)
1723 struct gdb_file *file = tui_file_new ();
1724 struct tui_stream *tmpstream = gdb_file_data (file);
1725 tmpstream->ts_streamtype = afile;
1726 tmpstream->ts_filestream = stream;
1727 tmpstream->ts_strbuf = NULL;
1728 tmpstream->ts_buflen = 0;
1733 tui_file_isatty (file)
1734 struct gdb_file *file;
1736 struct tui_stream *stream = gdb_file_data (file);
1737 if (stream->ts_magic != &tui_file_magic)
1738 error ("Internal error: bad magic number");
1739 if (stream->ts_streamtype == afile)
1740 return (isatty (fileno (stream->ts_filestream)));
1746 tui_file_rewind (file)
1747 struct gdb_file *file;
1749 struct tui_stream *stream = gdb_file_data (file);
1750 if (stream->ts_magic != &tui_file_magic)
1751 error ("Internal error: bad magic number");
1752 stream->ts_strbuf[0] = '\0';
1756 tui_file_put (file, dest)
1757 struct gdb_file *file;
1758 struct gdb_file *dest;
1760 struct tui_stream *stream = gdb_file_data (file);
1761 if (stream->ts_magic != &tui_file_magic)
1762 error ("Internal error: bad magic number");
1763 if (stream->ts_streamtype == astring)
1765 fputs_unfiltered (stream->ts_strbuf, dest);
1769 /* All TUI I/O sent to the *_filtered and *_unfiltered functions
1770 eventually ends up here. The fputs_unfiltered_hook is primarily
1771 used by GUIs to collect all output and send it to the GUI, instead
1772 of the controlling terminal. Only output to gdb_stdout and
1773 gdb_stderr are sent to the hook. Everything else is sent on to
1774 fputs to allow file I/O to be handled appropriately. */
1776 /* FIXME: Should be broken up and moved to a TUI specific file. */
1779 tui_file_fputs (linebuffer, file)
1780 const char *linebuffer;
1783 struct tui_stream *stream = gdb_file_data (file);
1785 extern int tui_owns_terminal;
1787 /* If anything (GUI, TUI) wants to capture GDB output, this is
1788 * the place... the way to do it is to set up
1789 * fputs_unfiltered_hook.
1790 * Our TUI ("gdb -tui") used to hook output, but in the
1791 * new (XDB style) scheme, we do not do that anymore... - RT
1793 if (fputs_unfiltered_hook
1794 && (file == gdb_stdout
1795 || file == gdb_stderr))
1796 fputs_unfiltered_hook (linebuffer, file);
1800 if (tui_version && tui_owns_terminal)
1802 /* If we get here somehow while updating the TUI (from
1803 * within a tuiDo(), then we need to temporarily
1804 * set up the terminal for GDB output. This probably just
1805 * happens on error output.
1808 if (stream->ts_streamtype == astring)
1810 gdb_file_adjust_strbuf (strlen (linebuffer), stream);
1811 strcat (stream->ts_strbuf, linebuffer);
1815 tuiTermUnsetup (0, (tui_version) ? cmdWin->detail.commandInfo.curch : 0);
1816 fputs (linebuffer, stream->ts_filestream);
1818 if (linebuffer[strlen (linebuffer) - 1] == '\n')
1819 tuiClearCommandCharCount ();
1821 tuiIncrCommandCharCountBy (strlen (linebuffer));
1826 /* The normal case - just do a fputs() */
1827 if (stream->ts_streamtype == astring)
1829 gdb_file_adjust_strbuf (strlen (linebuffer), stream);
1830 strcat (stream->ts_strbuf, linebuffer);
1833 fputs (linebuffer, stream->ts_filestream);
1838 if (stream->ts_streamtype == astring)
1840 gdb_file_adjust_strbuf (strlen (linebuffer), file);
1841 strcat (stream->ts_strbuf, linebuffer);
1844 fputs (linebuffer, stream->ts_filestream);
1850 gdb_file_init_astring (n)
1853 struct gdb_file *file = tui_file_new ();
1854 struct tui_stream *tmpstream = gdb_file_data (file);
1855 if (tmpstream->ts_magic != &tui_file_magic)
1856 error ("Internal error: bad magic number");
1858 tmpstream->ts_streamtype = astring;
1859 tmpstream->ts_filestream = NULL;
1862 tmpstream->ts_strbuf = xmalloc ((n + 1) * sizeof (char));
1863 tmpstream->ts_strbuf[0] = '\0';
1866 tmpstream->ts_strbuf = NULL;
1867 tmpstream->ts_buflen = n;
1873 gdb_file_deallocate (streamptr)
1874 GDB_FILE **streamptr;
1876 gdb_file_delete (*streamptr);
1881 gdb_file_get_strbuf (file)
1884 struct tui_stream *stream = gdb_file_data (file);
1885 if (stream->ts_magic != &tui_file_magic)
1886 error ("Internal error: bad magic number");
1887 return (stream->ts_strbuf);
1890 /* adjust the length of the buffer by the amount necessary
1891 to accomodate appending a string of length N to the buffer contents */
1893 gdb_file_adjust_strbuf (n, file)
1897 struct tui_stream *stream = gdb_file_data (file);
1899 if (stream->ts_magic != &tui_file_magic)
1900 error ("Internal error: bad magic number");
1902 if (stream->ts_streamtype != astring)
1905 if (stream->ts_strbuf)
1907 /* There is already a buffer allocated */
1908 non_null_chars = strlen (stream->ts_strbuf);
1910 if (n > (stream->ts_buflen - non_null_chars - 1))
1912 stream->ts_buflen = n + non_null_chars + 1;
1913 stream->ts_strbuf = xrealloc (stream->ts_strbuf, stream->ts_buflen);
1917 /* No buffer yet, so allocate one of the desired size */
1918 stream->ts_strbuf = xmalloc ((n + 1) * sizeof (char));
1922 gdb_fopen (name, mode)
1926 FILE *f = fopen (name, mode);
1929 return stdio_file_new (f, 1);
1933 tui_file_flush (file)
1936 struct tui_stream *stream = gdb_file_data (file);
1937 if (stream->ts_magic != &tui_file_magic)
1938 error ("Internal error: bad magic number");
1940 && (file == gdb_stdout
1941 || file == gdb_stderr))
1947 fflush (stream->ts_filestream);
1951 gdb_fclose (streamptr)
1952 GDB_FILE **streamptr;
1954 gdb_file_delete (*streamptr);
1959 /* Implement the ``struct gdb_file'' object. */
1961 static gdb_file_isatty_ftype null_file_isatty;
1962 static gdb_file_fputs_ftype null_file_fputs;
1963 static gdb_file_flush_ftype null_file_flush;
1964 static gdb_file_delete_ftype null_file_delete;
1965 static gdb_file_rewind_ftype null_file_rewind;
1966 static gdb_file_put_ftype null_file_put;
1970 gdb_file_flush_ftype *to_flush;
1971 gdb_file_fputs_ftype *to_fputs;
1972 gdb_file_delete_ftype *to_delete;
1973 gdb_file_isatty_ftype *to_isatty;
1974 gdb_file_rewind_ftype *to_rewind;
1975 gdb_file_put_ftype *to_put;
1982 struct gdb_file *file = xmalloc (sizeof (struct gdb_file));
1983 set_gdb_file_data (file, NULL, null_file_delete);
1984 set_gdb_file_flush (file, null_file_flush);
1985 set_gdb_file_fputs (file, null_file_fputs);
1986 set_gdb_file_isatty (file, null_file_isatty);
1987 set_gdb_file_rewind (file, null_file_rewind);
1988 set_gdb_file_put (file, null_file_put);
1993 gdb_file_delete (file)
1994 struct gdb_file *file;
1996 file->to_delete (file);
2001 null_file_isatty (file)
2002 struct gdb_file *file;
2008 null_file_rewind (file)
2009 struct gdb_file *file;
2015 null_file_put (file, src)
2016 struct gdb_file *file;
2017 struct gdb_file *src;
2023 null_file_flush (file)
2024 struct gdb_file *file;
2030 null_file_fputs (buf, file)
2032 struct gdb_file *file;
2038 null_file_delete (file)
2039 struct gdb_file *file;
2045 gdb_file_data (file)
2046 struct gdb_file *file;
2048 return file->to_data;
2053 struct gdb_file *file;
2055 file->to_flush (file);
2059 gdb_file_isatty (file)
2060 struct gdb_file *file;
2062 return file->to_isatty (file);
2066 gdb_file_rewind (file)
2067 struct gdb_file *file;
2069 file->to_rewind (file);
2073 gdb_file_put (file, dest)
2074 struct gdb_file *file;
2075 struct gdb_file *dest;
2077 file->to_put (file, dest);
2081 fputs_unfiltered (buf, file)
2083 struct gdb_file *file;
2085 file->to_fputs (buf, file);
2089 set_gdb_file_flush (file, flush)
2090 struct gdb_file *file;
2091 gdb_file_flush_ftype *flush;
2093 file->to_flush = flush;
2097 set_gdb_file_isatty (file, isatty)
2098 struct gdb_file *file;
2099 gdb_file_isatty_ftype *isatty;
2101 file->to_isatty = isatty;
2105 set_gdb_file_rewind (file, rewind)
2106 struct gdb_file *file;
2107 gdb_file_rewind_ftype *rewind;
2109 file->to_rewind = rewind;
2113 set_gdb_file_put (file, put)
2114 struct gdb_file *file;
2115 gdb_file_put_ftype *put;
2121 set_gdb_file_fputs (file, fputs)
2122 struct gdb_file *file;
2123 gdb_file_fputs_ftype *fputs;
2125 file->to_fputs = fputs;
2129 set_gdb_file_data (file, data, delete)
2130 struct gdb_file *file;
2132 gdb_file_delete_ftype *delete;
2134 file->to_data = data;
2135 file->to_delete = delete;
2138 /* Like fputs but if FILTER is true, pause after every screenful.
2140 Regardless of FILTER can wrap at points other than the final
2141 character of a line.
2143 Unlike fputs, fputs_maybe_filtered does not return a value.
2144 It is OK for LINEBUFFER to be NULL, in which case just don't print
2147 Note that a longjmp to top level may occur in this routine (only if
2148 FILTER is true) (since prompt_for_continue may do so) so this
2149 routine should not be called when cleanups are not in place. */
2152 fputs_maybe_filtered (linebuffer, stream, filter)
2153 const char *linebuffer;
2157 const char *lineptr;
2159 if (linebuffer == 0)
2162 /* Don't do any filtering if it is disabled. */
2163 if ((stream != gdb_stdout) || !pagination_enabled
2164 || (lines_per_page == UINT_MAX && chars_per_line == UINT_MAX))
2166 fputs_unfiltered (linebuffer, stream);
2170 /* Go through and output each character. Show line extension
2171 when this is necessary; prompt user for new page when this is
2174 lineptr = linebuffer;
2177 /* Possible new page. */
2179 (lines_printed >= lines_per_page - 1))
2180 prompt_for_continue ();
2182 while (*lineptr && *lineptr != '\n')
2184 /* Print a single line. */
2185 if (*lineptr == '\t')
2188 *wrap_pointer++ = '\t';
2190 fputc_unfiltered ('\t', stream);
2191 /* Shifting right by 3 produces the number of tab stops
2192 we have already passed, and then adding one and
2193 shifting left 3 advances to the next tab stop. */
2194 chars_printed = ((chars_printed >> 3) + 1) << 3;
2200 *wrap_pointer++ = *lineptr;
2202 fputc_unfiltered (*lineptr, stream);
2207 if (chars_printed >= chars_per_line)
2209 unsigned int save_chars = chars_printed;
2213 /* If we aren't actually wrapping, don't output newline --
2214 if chars_per_line is right, we probably just overflowed
2215 anyway; if it's wrong, let us keep going. */
2217 fputc_unfiltered ('\n', stream);
2219 /* Possible new page. */
2220 if (lines_printed >= lines_per_page - 1)
2221 prompt_for_continue ();
2223 /* Now output indentation and wrapped string */
2226 fputs_unfiltered (wrap_indent, stream);
2227 *wrap_pointer = '\0'; /* Null-terminate saved stuff */
2228 fputs_unfiltered (wrap_buffer, stream); /* and eject it */
2229 /* FIXME, this strlen is what prevents wrap_indent from
2230 containing tabs. However, if we recurse to print it
2231 and count its chars, we risk trouble if wrap_indent is
2232 longer than (the user settable) chars_per_line.
2233 Note also that this can set chars_printed > chars_per_line
2234 if we are printing a long string. */
2235 chars_printed = strlen (wrap_indent)
2236 + (save_chars - wrap_column);
2237 wrap_pointer = wrap_buffer; /* Reset buffer */
2238 wrap_buffer[0] = '\0';
2239 wrap_column = 0; /* And disable fancy wrap */
2244 if (*lineptr == '\n')
2247 wrap_here ((char *) 0); /* Spit out chars, cancel further wraps */
2249 fputc_unfiltered ('\n', stream);
2256 fputs_filtered (linebuffer, stream)
2257 const char *linebuffer;
2260 fputs_maybe_filtered (linebuffer, stream, 1);
2264 putchar_unfiltered (c)
2271 fputs_unfiltered (buf, gdb_stdout);
2276 fputc_unfiltered (c, stream)
2284 fputs_unfiltered (buf, stream);
2289 fputc_filtered (c, stream)
2297 fputs_filtered (buf, stream);
2301 /* puts_debug is like fputs_unfiltered, except it prints special
2302 characters in printable fashion. */
2305 puts_debug (prefix, string, suffix)
2312 /* Print prefix and suffix after each line. */
2313 static int new_line = 1;
2314 static int return_p = 0;
2315 static char *prev_prefix = "";
2316 static char *prev_suffix = "";
2318 if (*string == '\n')
2321 /* If the prefix is changing, print the previous suffix, a new line,
2322 and the new prefix. */
2323 if ((return_p || (strcmp (prev_prefix, prefix) != 0)) && !new_line)
2325 fputs_unfiltered (prev_suffix, gdb_stdlog);
2326 fputs_unfiltered ("\n", gdb_stdlog);
2327 fputs_unfiltered (prefix, gdb_stdlog);
2330 /* Print prefix if we printed a newline during the previous call. */
2334 fputs_unfiltered (prefix, gdb_stdlog);
2337 prev_prefix = prefix;
2338 prev_suffix = suffix;
2340 /* Output characters in a printable format. */
2341 while ((ch = *string++) != '\0')
2347 fputc_unfiltered (ch, gdb_stdlog);
2350 fprintf_unfiltered (gdb_stdlog, "\\x%02x", ch & 0xff);
2354 fputs_unfiltered ("\\\\", gdb_stdlog);
2357 fputs_unfiltered ("\\b", gdb_stdlog);
2360 fputs_unfiltered ("\\f", gdb_stdlog);
2364 fputs_unfiltered ("\\n", gdb_stdlog);
2367 fputs_unfiltered ("\\r", gdb_stdlog);
2370 fputs_unfiltered ("\\t", gdb_stdlog);
2373 fputs_unfiltered ("\\v", gdb_stdlog);
2377 return_p = ch == '\r';
2380 /* Print suffix if we printed a newline. */
2383 fputs_unfiltered (suffix, gdb_stdlog);
2384 fputs_unfiltered ("\n", gdb_stdlog);
2389 /* Print a variable number of ARGS using format FORMAT. If this
2390 information is going to put the amount written (since the last call
2391 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
2392 call prompt_for_continue to get the users permision to continue.
2394 Unlike fprintf, this function does not return a value.
2396 We implement three variants, vfprintf (takes a vararg list and stream),
2397 fprintf (takes a stream to write on), and printf (the usual).
2399 Note also that a longjmp to top level may occur in this routine
2400 (since prompt_for_continue may do so) so this routine should not be
2401 called when cleanups are not in place. */
2404 vfprintf_maybe_filtered (stream, format, args, filter)
2411 struct cleanup *old_cleanups;
2413 vasprintf (&linebuffer, format, args);
2414 if (linebuffer == NULL)
2416 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);
2419 old_cleanups = make_cleanup (free, linebuffer);
2420 fputs_maybe_filtered (linebuffer, stream, filter);
2421 do_cleanups (old_cleanups);
2426 vfprintf_filtered (stream, format, args)
2431 vfprintf_maybe_filtered (stream, format, args, 1);
2435 vfprintf_unfiltered (stream, format, args)
2441 struct cleanup *old_cleanups;
2443 vasprintf (&linebuffer, format, args);
2444 if (linebuffer == NULL)
2446 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr);
2449 old_cleanups = make_cleanup (free, linebuffer);
2450 fputs_unfiltered (linebuffer, stream);
2451 do_cleanups (old_cleanups);
2455 vprintf_filtered (format, args)
2459 vfprintf_maybe_filtered (gdb_stdout, format, args, 1);
2463 vprintf_unfiltered (format, args)
2467 vfprintf_unfiltered (gdb_stdout, format, args);
2471 fprintf_filtered (GDB_FILE * stream, const char *format,...)
2474 va_start (args, format);
2475 vfprintf_filtered (stream, format, args);
2480 fprintf_unfiltered (GDB_FILE * stream, const char *format,...)
2483 va_start (args, format);
2484 vfprintf_unfiltered (stream, format, args);
2488 /* Like fprintf_filtered, but prints its result indented.
2489 Called as fprintfi_filtered (spaces, stream, format, ...); */
2492 fprintfi_filtered (int spaces, GDB_FILE * stream, const char *format,...)
2495 va_start (args, format);
2496 print_spaces_filtered (spaces, stream);
2498 vfprintf_filtered (stream, format, args);
2504 printf_filtered (const char *format,...)
2507 va_start (args, format);
2508 vfprintf_filtered (gdb_stdout, format, args);
2514 printf_unfiltered (const char *format,...)
2517 va_start (args, format);
2518 vfprintf_unfiltered (gdb_stdout, format, args);
2522 /* Like printf_filtered, but prints it's result indented.
2523 Called as printfi_filtered (spaces, format, ...); */
2526 printfi_filtered (int spaces, const char *format,...)
2529 va_start (args, format);
2530 print_spaces_filtered (spaces, gdb_stdout);
2531 vfprintf_filtered (gdb_stdout, format, args);
2535 /* Easy -- but watch out!
2537 This routine is *not* a replacement for puts()! puts() appends a newline.
2538 This one doesn't, and had better not! */
2541 puts_filtered (string)
2544 fputs_filtered (string, gdb_stdout);
2548 puts_unfiltered (string)
2551 fputs_unfiltered (string, gdb_stdout);
2554 /* Return a pointer to N spaces and a null. The pointer is good
2555 until the next call to here. */
2561 static char *spaces = 0;
2562 static int max_spaces = -1;
2568 spaces = (char *) xmalloc (n + 1);
2569 for (t = spaces + n; t != spaces;)
2575 return spaces + max_spaces - n;
2578 /* Print N spaces. */
2580 print_spaces_filtered (n, stream)
2584 fputs_filtered (n_spaces (n), stream);
2587 /* C++ demangler stuff. */
2589 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
2590 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
2591 If the name is not mangled, or the language for the name is unknown, or
2592 demangling is off, the name is printed in its "raw" form. */
2595 fprintf_symbol_filtered (stream, name, lang, arg_mode)
2605 /* If user wants to see raw output, no problem. */
2608 fputs_filtered (name, stream);
2614 case language_cplus:
2615 demangled = cplus_demangle (name, arg_mode);
2618 demangled = cplus_demangle (name, arg_mode | DMGL_JAVA);
2620 case language_chill:
2621 demangled = chill_demangle (name);
2627 fputs_filtered (demangled ? demangled : name, stream);
2628 if (demangled != NULL)
2636 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
2637 differences in whitespace. Returns 0 if they match, non-zero if they
2638 don't (slightly different than strcmp()'s range of return values).
2640 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
2641 This "feature" is useful when searching for matching C++ function names
2642 (such as if the user types 'break FOO', where FOO is a mangled C++
2646 strcmp_iw (string1, string2)
2647 const char *string1;
2648 const char *string2;
2650 while ((*string1 != '\0') && (*string2 != '\0'))
2652 while (isspace (*string1))
2656 while (isspace (*string2))
2660 if (*string1 != *string2)
2664 if (*string1 != '\0')
2670 return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
2676 ** Answer whether string_to_compare is a full or partial match to
2677 ** template_string. The partial match must be in sequence starting
2681 subset_compare (string_to_compare, template_string)
2682 char *string_to_compare;
2683 char *template_string;
2686 if (template_string != (char *) NULL && string_to_compare != (char *) NULL &&
2687 strlen (string_to_compare) <= strlen (template_string))
2688 match = (strncmp (template_string,
2690 strlen (string_to_compare)) == 0);
2697 static void pagination_on_command PARAMS ((char *arg, int from_tty));
2699 pagination_on_command (arg, from_tty)
2703 pagination_enabled = 1;
2706 static void pagination_on_command PARAMS ((char *arg, int from_tty));
2708 pagination_off_command (arg, from_tty)
2712 pagination_enabled = 0;
2719 struct cmd_list_element *c;
2721 c = add_set_cmd ("width", class_support, var_uinteger,
2722 (char *) &chars_per_line,
2723 "Set number of characters gdb thinks are in a line.",
2725 add_show_from_set (c, &showlist);
2726 c->function.sfunc = set_width_command;
2729 (add_set_cmd ("height", class_support,
2730 var_uinteger, (char *) &lines_per_page,
2731 "Set number of lines gdb thinks are in a page.", &setlist),
2736 /* If the output is not a terminal, don't paginate it. */
2737 if (!GDB_FILE_ISATTY (gdb_stdout))
2738 lines_per_page = UINT_MAX;
2740 set_width_command ((char *) NULL, 0, c);
2743 (add_set_cmd ("demangle", class_support, var_boolean,
2745 "Set demangling of encoded C++ names when displaying symbols.",
2750 (add_set_cmd ("pagination", class_support,
2751 var_boolean, (char *) &pagination_enabled,
2752 "Set state of pagination.", &setlist),
2756 add_com ("am", class_support, pagination_on_command,
2757 "Enable pagination");
2758 add_com ("sm", class_support, pagination_off_command,
2759 "Disable pagination");
2763 (add_set_cmd ("sevenbit-strings", class_support, var_boolean,
2764 (char *) &sevenbit_strings,
2765 "Set printing of 8-bit characters in strings as \\nnn.",
2770 (add_set_cmd ("asm-demangle", class_support, var_boolean,
2771 (char *) &asm_demangle,
2772 "Set demangling of C++ names in disassembly listings.",
2777 /* Machine specific function to handle SIGWINCH signal. */
2779 #ifdef SIGWINCH_HANDLER_BODY
2780 SIGWINCH_HANDLER_BODY
2783 /* Support for converting target fp numbers into host DOUBLEST format. */
2785 /* XXX - This code should really be in libiberty/floatformat.c, however
2786 configuration issues with libiberty made this very difficult to do in the
2789 #include "floatformat.h"
2790 #include <math.h> /* ldexp */
2792 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
2793 going to bother with trying to muck around with whether it is defined in
2794 a system header, what we do if not, etc. */
2795 #define FLOATFORMAT_CHAR_BIT 8
2797 static unsigned long get_field PARAMS ((unsigned char *,
2798 enum floatformat_byteorders,
2803 /* Extract a field which starts at START and is LEN bytes long. DATA and
2804 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2805 static unsigned long
2806 get_field (data, order, total_len, start, len)
2807 unsigned char *data;
2808 enum floatformat_byteorders order;
2809 unsigned int total_len;
2813 unsigned long result;
2814 unsigned int cur_byte;
2817 /* Start at the least significant part of the field. */
2818 cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
2819 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2820 cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1;
2822 ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
2823 result = *(data + cur_byte) >> (-cur_bitshift);
2824 cur_bitshift += FLOATFORMAT_CHAR_BIT;
2825 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2830 /* Move towards the most significant part of the field. */
2831 while (cur_bitshift < len)
2833 if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
2834 /* This is the last byte; zero out the bits which are not part of
2837 (*(data + cur_byte) & ((1 << (len - cur_bitshift)) - 1))
2840 result |= *(data + cur_byte) << cur_bitshift;
2841 cur_bitshift += FLOATFORMAT_CHAR_BIT;
2842 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2850 /* Convert from FMT to a DOUBLEST.
2851 FROM is the address of the extended float.
2852 Store the DOUBLEST in *TO. */
2855 floatformat_to_doublest (fmt, from, to)
2856 const struct floatformat *fmt;
2860 unsigned char *ufrom = (unsigned char *) from;
2864 unsigned int mant_bits, mant_off;
2866 int special_exponent; /* It's a NaN, denorm or zero */
2868 /* If the mantissa bits are not contiguous from one end of the
2869 mantissa to the other, we need to make a private copy of the
2870 source bytes that is in the right order since the unpacking
2871 algorithm assumes that the bits are contiguous.
2873 Swap the bytes individually rather than accessing them through
2874 "long *" since we have no guarantee that they start on a long
2875 alignment, and also sizeof(long) for the host could be different
2876 than sizeof(long) for the target. FIXME: Assumes sizeof(long)
2877 for the target is 4. */
2879 if (fmt->byteorder == floatformat_littlebyte_bigword)
2881 static unsigned char *newfrom;
2882 unsigned char *swapin, *swapout;
2885 longswaps = fmt->totalsize / FLOATFORMAT_CHAR_BIT;
2888 if (newfrom == NULL)
2890 newfrom = (unsigned char *) xmalloc (fmt->totalsize);
2895 while (longswaps-- > 0)
2897 /* This is ugly, but efficient */
2898 *swapout++ = swapin[4];
2899 *swapout++ = swapin[5];
2900 *swapout++ = swapin[6];
2901 *swapout++ = swapin[7];
2902 *swapout++ = swapin[0];
2903 *swapout++ = swapin[1];
2904 *swapout++ = swapin[2];
2905 *swapout++ = swapin[3];
2910 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
2911 fmt->exp_start, fmt->exp_len);
2912 /* Note that if exponent indicates a NaN, we can't really do anything useful
2913 (not knowing if the host has NaN's, or how to build one). So it will
2914 end up as an infinity or something close; that is OK. */
2916 mant_bits_left = fmt->man_len;
2917 mant_off = fmt->man_start;
2920 special_exponent = exponent == 0 || exponent == fmt->exp_nan;
2922 /* Don't bias zero's, denorms or NaNs. */
2923 if (!special_exponent)
2924 exponent -= fmt->exp_bias;
2926 /* Build the result algebraically. Might go infinite, underflow, etc;
2929 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
2930 increment the exponent by one to account for the integer bit. */
2932 if (!special_exponent)
2934 if (fmt->intbit == floatformat_intbit_no)
2935 dto = ldexp (1.0, exponent);
2940 while (mant_bits_left > 0)
2942 mant_bits = min (mant_bits_left, 32);
2944 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
2945 mant_off, mant_bits);
2947 dto += ldexp ((double) mant, exponent - mant_bits);
2948 exponent -= mant_bits;
2949 mant_off += mant_bits;
2950 mant_bits_left -= mant_bits;
2953 /* Negate it if negative. */
2954 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
2959 static void put_field PARAMS ((unsigned char *, enum floatformat_byteorders,
2965 /* Set a field which starts at START and is LEN bytes long. DATA and
2966 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2968 put_field (data, order, total_len, start, len, stuff_to_put)
2969 unsigned char *data;
2970 enum floatformat_byteorders order;
2971 unsigned int total_len;
2974 unsigned long stuff_to_put;
2976 unsigned int cur_byte;
2979 /* Start at the least significant part of the field. */
2980 cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
2981 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2982 cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1;
2984 ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
2985 *(data + cur_byte) &=
2986 ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1) << (-cur_bitshift));
2987 *(data + cur_byte) |=
2988 (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift);
2989 cur_bitshift += FLOATFORMAT_CHAR_BIT;
2990 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
2995 /* Move towards the most significant part of the field. */
2996 while (cur_bitshift < len)
2998 if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
3000 /* This is the last byte. */
3001 *(data + cur_byte) &=
3002 ~((1 << (len - cur_bitshift)) - 1);
3003 *(data + cur_byte) |= (stuff_to_put >> cur_bitshift);
3006 *(data + cur_byte) = ((stuff_to_put >> cur_bitshift)
3007 & ((1 << FLOATFORMAT_CHAR_BIT) - 1));
3008 cur_bitshift += FLOATFORMAT_CHAR_BIT;
3009 if (order == floatformat_little || order == floatformat_littlebyte_bigword)
3016 #ifdef HAVE_LONG_DOUBLE
3017 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
3018 The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
3019 frexp, but operates on the long double data type. */
3021 static long double ldfrexp PARAMS ((long double value, int *eptr));
3024 ldfrexp (value, eptr)
3031 /* Unfortunately, there are no portable functions for extracting the exponent
3032 of a long double, so we have to do it iteratively by multiplying or dividing
3033 by two until the fraction is between 0.5 and 1.0. */
3041 if (value >= tmp) /* Value >= 1.0 */
3042 while (value >= tmp)
3047 else if (value != 0.0l) /* Value < 1.0 and > 0.0 */
3061 #endif /* HAVE_LONG_DOUBLE */
3064 /* The converse: convert the DOUBLEST *FROM to an extended float
3065 and store where TO points. Neither FROM nor TO have any alignment
3069 floatformat_from_doublest (fmt, from, to)
3070 CONST struct floatformat *fmt;
3077 unsigned int mant_bits, mant_off;
3079 unsigned char *uto = (unsigned char *) to;
3081 memcpy (&dfrom, from, sizeof (dfrom));
3082 memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT);
3084 return; /* Result is zero */
3085 if (dfrom != dfrom) /* Result is NaN */
3088 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
3089 fmt->exp_len, fmt->exp_nan);
3090 /* Be sure it's not infinity, but NaN value is irrel */
3091 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
3096 /* If negative, set the sign bit. */
3099 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
3103 if (dfrom + dfrom == dfrom && dfrom != 0.0) /* Result is Infinity */
3105 /* Infinity exponent is same as NaN's. */
3106 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
3107 fmt->exp_len, fmt->exp_nan);
3108 /* Infinity mantissa is all zeroes. */
3109 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
3114 #ifdef HAVE_LONG_DOUBLE
3115 mant = ldfrexp (dfrom, &exponent);
3117 mant = frexp (dfrom, &exponent);
3120 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
3121 exponent + fmt->exp_bias - 1);
3123 mant_bits_left = fmt->man_len;
3124 mant_off = fmt->man_start;
3125 while (mant_bits_left > 0)
3127 unsigned long mant_long;
3128 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
3130 mant *= 4294967296.0;
3131 mant_long = (unsigned long) mant;
3134 /* If the integer bit is implicit, then we need to discard it.
3135 If we are discarding a zero, we should be (but are not) creating
3136 a denormalized number which means adjusting the exponent
3138 if (mant_bits_left == fmt->man_len
3139 && fmt->intbit == floatformat_intbit_no)
3147 /* The bits we want are in the most significant MANT_BITS bits of
3148 mant_long. Move them to the least significant. */
3149 mant_long >>= 32 - mant_bits;
3152 put_field (uto, fmt->byteorder, fmt->totalsize,
3153 mant_off, mant_bits, mant_long);
3154 mant_off += mant_bits;
3155 mant_bits_left -= mant_bits;
3157 if (fmt->byteorder == floatformat_littlebyte_bigword)
3160 unsigned char *swaplow = uto;
3161 unsigned char *swaphigh = uto + 4;
3164 for (count = 0; count < 4; count++)
3167 *swaplow++ = *swaphigh;
3173 /* temporary storage using circular buffer */
3179 static char buf[NUMCELLS][CELLSIZE];
3180 static int cell = 0;
3181 if (++cell >= NUMCELLS)
3186 /* print routines to handle variable size regs, etc.
3188 FIXME: Note that t_addr is a bfd_vma, which is currently either an
3189 unsigned long or unsigned long long, determined at configure time.
3190 If t_addr is an unsigned long long and sizeof (unsigned long long)
3191 is greater than sizeof (unsigned long), then I believe this code will
3192 probably lose, at least for little endian machines. I believe that
3193 it would also be better to eliminate the switch on the absolute size
3194 of t_addr and replace it with a sequence of if statements that compare
3195 sizeof t_addr with sizeof the various types and do the right thing,
3196 which includes knowing whether or not the host supports long long.
3204 return (TARGET_PTR_BIT / 8 * 2);
3208 /* eliminate warning from compiler on 32-bit systems */
3209 static int thirty_two = 32;
3212 paddr (CORE_ADDR addr)
3214 char *paddr_str = get_cell ();
3215 switch (TARGET_PTR_BIT / 8)
3218 sprintf (paddr_str, "%08lx%08lx",
3219 (unsigned long) (addr >> thirty_two), (unsigned long) (addr & 0xffffffff));
3222 sprintf (paddr_str, "%08lx", (unsigned long) addr);
3225 sprintf (paddr_str, "%04x", (unsigned short) (addr & 0xffff));
3228 sprintf (paddr_str, "%lx", (unsigned long) addr);
3234 paddr_nz (CORE_ADDR addr)
3236 char *paddr_str = get_cell ();
3237 switch (TARGET_PTR_BIT / 8)
3241 unsigned long high = (unsigned long) (addr >> thirty_two);
3243 sprintf (paddr_str, "%lx", (unsigned long) (addr & 0xffffffff));
3245 sprintf (paddr_str, "%lx%08lx",
3246 high, (unsigned long) (addr & 0xffffffff));
3250 sprintf (paddr_str, "%lx", (unsigned long) addr);
3253 sprintf (paddr_str, "%x", (unsigned short) (addr & 0xffff));
3256 sprintf (paddr_str, "%lx", (unsigned long) addr);
3262 decimal2str (char *paddr_str, char *sign, ULONGEST addr)
3264 /* steal code from valprint.c:print_decimal(). Should this worry
3265 about the real size of addr as the above does? */
3266 unsigned long temp[3];
3270 temp[i] = addr % (1000 * 1000 * 1000);
3271 addr /= (1000 * 1000 * 1000);
3274 while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
3278 sprintf (paddr_str, "%s%lu",
3282 sprintf (paddr_str, "%s%lu%09lu",
3283 sign, temp[1], temp[0]);
3286 sprintf (paddr_str, "%s%lu%09lu%09lu",
3287 sign, temp[2], temp[1], temp[0]);
3295 paddr_u (CORE_ADDR addr)
3297 char *paddr_str = get_cell ();
3298 decimal2str (paddr_str, "", addr);
3303 paddr_d (LONGEST addr)
3305 char *paddr_str = get_cell ();
3307 decimal2str (paddr_str, "-", -addr);
3309 decimal2str (paddr_str, "", addr);
3317 char *preg_str = get_cell ();
3318 switch (sizeof (t_reg))
3321 sprintf (preg_str, "%08lx%08lx",
3322 (unsigned long) (reg >> thirty_two), (unsigned long) (reg & 0xffffffff));
3325 sprintf (preg_str, "%08lx", (unsigned long) reg);
3328 sprintf (preg_str, "%04x", (unsigned short) (reg & 0xffff));
3331 sprintf (preg_str, "%lx", (unsigned long) reg);
3340 char *preg_str = get_cell ();
3341 switch (sizeof (t_reg))
3345 unsigned long high = (unsigned long) (reg >> thirty_two);
3347 sprintf (preg_str, "%lx", (unsigned long) (reg & 0xffffffff));
3349 sprintf (preg_str, "%lx%08lx",
3350 high, (unsigned long) (reg & 0xffffffff));
3354 sprintf (preg_str, "%lx", (unsigned long) reg);
3357 sprintf (preg_str, "%x", (unsigned short) (reg & 0xffff));
3360 sprintf (preg_str, "%lx", (unsigned long) reg);
3365 /* Helper functions for INNER_THAN */
3367 core_addr_lessthan (lhs, rhs)
3375 core_addr_greaterthan (lhs, rhs)