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, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
34 /* SunOS's curses.h has a '#define reg register' in it. Thank you Sun. */
45 #include "expression.h"
49 #include <readline/readline.h>
51 /* readline defines this. */
54 void (*error_begin_hook
) PARAMS ((void));
56 /* Prototypes for local functions */
58 static void vfprintf_maybe_filtered
PARAMS ((GDB_FILE
*, const char *,
61 static void fputs_maybe_filtered
PARAMS ((const char *, GDB_FILE
*, int));
63 #if defined (USE_MMALLOC) && !defined (NO_MMCHECK)
64 static void malloc_botch
PARAMS ((void));
68 fatal_dump_core
PARAMS((char *, ...));
71 prompt_for_continue
PARAMS ((void));
74 set_width_command
PARAMS ((char *, int, struct cmd_list_element
*));
77 set_width
PARAMS ((void));
79 /* If this definition isn't overridden by the header files, assume
80 that isatty and fileno exist on this system. */
82 #define ISATTY(FP) (isatty (fileno (FP)))
85 #ifndef GDB_FILE_ISATTY
86 #define GDB_FILE_ISATTY(GDB_FILE_PTR) (gdb_file_isatty(GDB_FILE_PTR))
89 /* Chain of cleanup actions established with make_cleanup,
90 to be executed if an error happens. */
92 static struct cleanup
*cleanup_chain
; /* cleaned up after a failed command */
93 static struct cleanup
*final_cleanup_chain
; /* cleaned up when gdb exits */
94 static struct cleanup
*run_cleanup_chain
; /* cleaned up on each 'run' */
96 /* Nonzero if we have job control. */
100 /* Nonzero means a quit has been requested. */
104 /* Nonzero means quit immediately if Control-C is typed now, rather
105 than waiting until QUIT is executed. Be careful in setting this;
106 code which executes with immediate_quit set has to be very careful
107 about being able to deal with being interrupted at any time. It is
108 almost always better to use QUIT; the only exception I can think of
109 is being able to quit out of a system call (using EINTR loses if
110 the SIGINT happens between the previous QUIT and the system call).
111 To immediately quit in the case in which a SIGINT happens between
112 the previous QUIT and setting immediate_quit (desirable anytime we
113 expect to block), call QUIT after setting immediate_quit. */
117 /* Nonzero means that encoded C++ names should be printed out in their
118 C++ form rather than raw. */
122 /* Nonzero means that encoded C++ names should be printed out in their
123 C++ form even in assembler language displays. If this is set, but
124 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
126 int asm_demangle
= 0;
128 /* Nonzero means that strings with character values >0x7F should be printed
129 as octal escapes. Zero means just print the value (e.g. it's an
130 international character, and the terminal or window can cope.) */
132 int sevenbit_strings
= 0;
134 /* String to be printed before error messages, if any. */
136 char *error_pre_print
;
138 /* String to be printed before quit messages, if any. */
140 char *quit_pre_print
;
142 /* String to be printed before warning messages, if any. */
144 char *warning_pre_print
= "\nwarning: ";
146 int pagination_enabled
= 1;
149 /* Add a new cleanup to the cleanup_chain,
150 and return the previous chain pointer
151 to be passed later to do_cleanups or discard_cleanups.
152 Args are FUNCTION to clean up with, and ARG to pass to it. */
155 make_cleanup (function
, arg
)
156 void (*function
) PARAMS ((PTR
));
159 return make_my_cleanup (&cleanup_chain
, function
, arg
);
163 make_final_cleanup (function
, arg
)
164 void (*function
) PARAMS ((PTR
));
167 return make_my_cleanup (&final_cleanup_chain
, function
, arg
);
171 make_run_cleanup (function
, arg
)
172 void (*function
) PARAMS ((PTR
));
175 return make_my_cleanup (&run_cleanup_chain
, function
, arg
);
182 freeargv ((char**) arg
);
186 make_cleanup_freeargv (arg
)
189 return make_my_cleanup (&cleanup_chain
, do_freeargv
, arg
);
193 make_my_cleanup (pmy_chain
, function
, arg
)
194 struct cleanup
**pmy_chain
;
195 void (*function
) PARAMS ((PTR
));
198 register struct cleanup
*new
199 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
200 register struct cleanup
*old_chain
= *pmy_chain
;
202 new->next
= *pmy_chain
;
203 new->function
= function
;
210 /* Discard cleanups and do the actions they describe
211 until we get back to the point OLD_CHAIN in the cleanup_chain. */
214 do_cleanups (old_chain
)
215 register struct cleanup
*old_chain
;
217 do_my_cleanups (&cleanup_chain
, old_chain
);
221 do_final_cleanups (old_chain
)
222 register struct cleanup
*old_chain
;
224 do_my_cleanups (&final_cleanup_chain
, old_chain
);
228 do_run_cleanups (old_chain
)
229 register struct cleanup
*old_chain
;
231 do_my_cleanups (&run_cleanup_chain
, old_chain
);
235 do_my_cleanups (pmy_chain
, old_chain
)
236 register struct cleanup
**pmy_chain
;
237 register struct cleanup
*old_chain
;
239 register struct cleanup
*ptr
;
240 while ((ptr
= *pmy_chain
) != old_chain
)
242 *pmy_chain
= ptr
->next
; /* Do this first incase recursion */
243 (*ptr
->function
) (ptr
->arg
);
248 /* Discard cleanups, not doing the actions they describe,
249 until we get back to the point OLD_CHAIN in the cleanup_chain. */
252 discard_cleanups (old_chain
)
253 register struct cleanup
*old_chain
;
255 discard_my_cleanups (&cleanup_chain
, old_chain
);
259 discard_final_cleanups (old_chain
)
260 register struct cleanup
*old_chain
;
262 discard_my_cleanups (&final_cleanup_chain
, old_chain
);
266 discard_my_cleanups (pmy_chain
, old_chain
)
267 register struct cleanup
**pmy_chain
;
268 register struct cleanup
*old_chain
;
270 register struct cleanup
*ptr
;
271 while ((ptr
= *pmy_chain
) != old_chain
)
273 *pmy_chain
= ptr
->next
;
278 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
282 return save_my_cleanups (&cleanup_chain
);
286 save_final_cleanups ()
288 return save_my_cleanups (&final_cleanup_chain
);
292 save_my_cleanups (pmy_chain
)
293 struct cleanup
**pmy_chain
;
295 struct cleanup
*old_chain
= *pmy_chain
;
301 /* Restore the cleanup chain from a previously saved chain. */
303 restore_cleanups (chain
)
304 struct cleanup
*chain
;
306 restore_my_cleanups (&cleanup_chain
, chain
);
310 restore_final_cleanups (chain
)
311 struct cleanup
*chain
;
313 restore_my_cleanups (&final_cleanup_chain
, chain
);
317 restore_my_cleanups (pmy_chain
, chain
)
318 struct cleanup
**pmy_chain
;
319 struct cleanup
*chain
;
324 /* This function is useful for cleanups.
328 old_chain = make_cleanup (free_current_contents, &foo);
330 to arrange to free the object thus allocated. */
333 free_current_contents (location
)
339 /* Provide a known function that does nothing, to use as a base for
340 for a possibly long chain of cleanups. This is useful where we
341 use the cleanup chain for handling normal cleanups as well as dealing
342 with cleanups that need to be done as a result of a call to error().
343 In such cases, we may not be certain where the first cleanup is, unless
344 we have a do-nothing one to always use as the base. */
354 /* Print a warning message. Way to use this is to call warning_begin,
355 output the warning message (use unfiltered output to gdb_stderr),
356 ending in a newline. There is not currently a warning_end that you
357 call afterwards, but such a thing might be added if it is useful
358 for a GUI to separate warning messages from other output.
360 FIXME: Why do warnings use unfiltered output and errors filtered?
361 Is this anything other than a historical accident? */
366 target_terminal_ours ();
367 wrap_here(""); /* Force out any buffered output */
368 gdb_flush (gdb_stdout
);
369 if (warning_pre_print
)
370 fprintf_unfiltered (gdb_stderr
, warning_pre_print
);
373 /* Print a warning message.
374 The first argument STRING is the warning message, used as a fprintf string,
375 and the remaining args are passed as arguments to it.
376 The primary difference between warnings and errors is that a warning
377 does not force the return to command level. */
381 #ifdef ANSI_PROTOTYPES
382 warning (const char *string
, ...)
389 #ifdef ANSI_PROTOTYPES
390 va_start (args
, string
);
395 string
= va_arg (args
, char *);
398 (*warning_hook
) (string
, args
);
402 vfprintf_unfiltered (gdb_stderr
, string
, args
);
403 fprintf_unfiltered (gdb_stderr
, "\n");
408 /* Start the printing of an error message. Way to use this is to call
409 this, output the error message (use filtered output to gdb_stderr
410 (FIXME: Some callers, like memory_error, use gdb_stdout)), ending
411 in a newline, and then call return_to_top_level (RETURN_ERROR).
412 error() provides a convenient way to do this for the special case
413 that the error message can be formatted with a single printf call,
414 but this is more general. */
418 if (error_begin_hook
)
421 target_terminal_ours ();
422 wrap_here (""); /* Force out any buffered output */
423 gdb_flush (gdb_stdout
);
425 annotate_error_begin ();
428 fprintf_filtered (gdb_stderr
, error_pre_print
);
431 /* Print an error message and return to command level.
432 The first argument STRING is the error message, used as a fprintf string,
433 and the remaining args are passed as arguments to it. */
437 #ifdef ANSI_PROTOTYPES
438 error (const char *string
, ...)
445 #ifdef ANSI_PROTOTYPES
446 va_start (args
, string
);
455 #ifdef ANSI_PROTOTYPES
456 vfprintf_filtered (gdb_stderr
, string
, args
);
461 string1
= va_arg (args
, char *);
462 vfprintf_filtered (gdb_stderr
, string1
, args
);
465 fprintf_filtered (gdb_stderr
, "\n");
467 return_to_top_level (RETURN_ERROR
);
472 /* Print an error message and exit reporting failure.
473 This is for a error that we cannot continue from.
474 The arguments are printed a la printf.
476 This function cannot be declared volatile (NORETURN) in an
477 ANSI environment because exit() is not declared volatile. */
481 #ifdef ANSI_PROTOTYPES
482 fatal (char *string
, ...)
489 #ifdef ANSI_PROTOTYPES
490 va_start (args
, string
);
494 string
= va_arg (args
, char *);
496 fprintf_unfiltered (gdb_stderr
, "\ngdb: ");
497 vfprintf_unfiltered (gdb_stderr
, string
, args
);
498 fprintf_unfiltered (gdb_stderr
, "\n");
503 /* Print an error message and exit, dumping core.
504 The arguments are printed a la printf (). */
508 #ifdef ANSI_PROTOTYPES
509 fatal_dump_core (char *string
, ...)
511 fatal_dump_core (va_alist
)
516 #ifdef ANSI_PROTOTYPES
517 va_start (args
, string
);
522 string
= va_arg (args
, char *);
524 /* "internal error" is always correct, since GDB should never dump
525 core, no matter what the input. */
526 fprintf_unfiltered (gdb_stderr
, "\ngdb internal error: ");
527 vfprintf_unfiltered (gdb_stderr
, string
, args
);
528 fprintf_unfiltered (gdb_stderr
, "\n");
531 signal (SIGQUIT
, SIG_DFL
);
532 kill (getpid (), SIGQUIT
);
533 /* We should never get here, but just in case... */
537 /* The strerror() function can return NULL for errno values that are
538 out of range. Provide a "safe" version that always returns a
542 safe_strerror (errnum
)
548 if ((msg
= strerror (errnum
)) == NULL
)
550 sprintf (buf
, "(undocumented errno %d)", errnum
);
556 /* The strsignal() function can return NULL for signal values that are
557 out of range. Provide a "safe" version that always returns a
561 safe_strsignal (signo
)
567 if ((msg
= strsignal (signo
)) == NULL
)
569 sprintf (buf
, "(undocumented signal %d)", signo
);
576 /* Print the system error message for errno, and also mention STRING
577 as the file name for which the error was encountered.
578 Then return to command level. */
581 perror_with_name (string
)
587 err
= safe_strerror (errno
);
588 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
589 strcpy (combined
, string
);
590 strcat (combined
, ": ");
591 strcat (combined
, err
);
593 /* I understand setting these is a matter of taste. Still, some people
594 may clear errno but not know about bfd_error. Doing this here is not
596 bfd_set_error (bfd_error_no_error
);
599 error ("%s.", combined
);
602 /* Print the system error message for ERRCODE, and also mention STRING
603 as the file name for which the error was encountered. */
606 print_sys_errmsg (string
, errcode
)
613 err
= safe_strerror (errcode
);
614 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
615 strcpy (combined
, string
);
616 strcat (combined
, ": ");
617 strcat (combined
, err
);
619 /* We want anything which was printed on stdout to come out first, before
621 gdb_flush (gdb_stdout
);
622 fprintf_unfiltered (gdb_stderr
, "%s.\n", combined
);
625 /* Control C eventually causes this to be called, at a convenient time. */
630 serial_t gdb_stdout_serial
= serial_fdopen (1);
632 target_terminal_ours ();
634 /* We want all output to appear now, before we print "Quit". We
635 have 3 levels of buffering we have to flush (it's possible that
636 some of these should be changed to flush the lower-level ones
639 /* 1. The _filtered buffer. */
640 wrap_here ((char *)0);
642 /* 2. The stdio buffer. */
643 gdb_flush (gdb_stdout
);
644 gdb_flush (gdb_stderr
);
646 /* 3. The system-level buffer. */
647 SERIAL_DRAIN_OUTPUT (gdb_stdout_serial
);
648 SERIAL_UN_FDOPEN (gdb_stdout_serial
);
650 annotate_error_begin ();
652 /* Don't use *_filtered; we don't want to prompt the user to continue. */
654 fprintf_unfiltered (gdb_stderr
, quit_pre_print
);
657 /* If there is no terminal switching for this target, then we can't
658 possibly get screwed by the lack of job control. */
659 || current_target
.to_terminal_ours
== NULL
)
660 fprintf_unfiltered (gdb_stderr
, "Quit\n");
662 fprintf_unfiltered (gdb_stderr
,
663 "Quit (expect signal SIGINT when the program is resumed)\n");
664 return_to_top_level (RETURN_QUIT
);
668 #if defined(__GO32__)
670 /* In the absence of signals, poll keyboard for a quit.
671 Called from #define QUIT pollquit() in xm-go32.h. */
686 /* We just ignore it */
687 /* FIXME!! Don't think this actually works! */
688 fprintf_unfiltered (gdb_stderr
, "CTRL-A to quit, CTRL-B to quit harder\n");
693 #elif defined(_MSC_VER) /* should test for wingdb instead? */
696 * Windows translates all keyboard and mouse events
697 * into a message which is appended to the message
698 * queue for the process.
703 int k
= win32pollquit();
710 #else /* !defined(__GO32__) && !defined(_MSC_VER) */
714 /* Done by signals */
717 #endif /* !defined(__GO32__) && !defined(_MSC_VER) */
719 /* Control C comes here */
725 /* Restore the signal handler. Harmless with BSD-style signals, needed
726 for System V-style signals. So just always do it, rather than worrying
727 about USG defines and stuff like that. */
728 signal (signo
, request_quit
);
738 /* Memory management stuff (malloc friends). */
740 /* Make a substitute size_t for non-ANSI compilers. */
742 #ifndef HAVE_STDDEF_H
744 #define size_t unsigned int
748 #if !defined (USE_MMALLOC)
755 return malloc (size
);
759 mrealloc (md
, ptr
, size
)
764 if (ptr
== 0) /* Guard against old realloc's */
765 return malloc (size
);
767 return realloc (ptr
, size
);
778 #endif /* USE_MMALLOC */
780 #if !defined (USE_MMALLOC) || defined (NO_MMCHECK)
788 #else /* Have mmalloc and want corruption checking */
793 fatal_dump_core ("Memory corruption");
796 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
797 by MD, to detect memory corruption. Note that MD may be NULL to specify
798 the default heap that grows via sbrk.
800 Note that for freshly created regions, we must call mmcheckf prior to any
801 mallocs in the region. Otherwise, any region which was allocated prior to
802 installing the checking hooks, which is later reallocated or freed, will
803 fail the checks! The mmcheck function only allows initial hooks to be
804 installed before the first mmalloc. However, anytime after we have called
805 mmcheck the first time to install the checking hooks, we can call it again
806 to update the function pointer to the memory corruption handler.
808 Returns zero on failure, non-zero on success. */
810 #ifndef MMCHECK_FORCE
811 #define MMCHECK_FORCE 0
818 if (!mmcheckf (md
, malloc_botch
, MMCHECK_FORCE
))
820 /* Don't use warning(), which relies on current_target being set
821 to something other than dummy_target, until after
822 initialize_all_files(). */
825 (gdb_stderr
, "warning: failed to install memory consistency checks; ");
827 (gdb_stderr
, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
833 #endif /* Have mmalloc and want corruption checking */
835 /* Called when a memory allocation fails, with the number of bytes of
836 memory requested in SIZE. */
844 fatal ("virtual memory exhausted: can't allocate %ld bytes.", size
);
848 fatal ("virtual memory exhausted.");
852 /* Like mmalloc but get error if no storage available, and protect against
853 the caller wanting to allocate zero bytes. Whether to return NULL for
854 a zero byte request, or translate the request into a request for one
855 byte of zero'd storage, is a religious issue. */
868 else if ((val
= mmalloc (md
, size
)) == NULL
)
875 /* Like mrealloc but get error if no storage available. */
878 xmrealloc (md
, ptr
, size
)
887 val
= mrealloc (md
, ptr
, size
);
891 val
= mmalloc (md
, size
);
900 /* Like malloc but get error if no storage available, and protect against
901 the caller wanting to allocate zero bytes. */
907 return (xmmalloc ((PTR
) NULL
, size
));
910 /* Like mrealloc but get error if no storage available. */
917 return (xmrealloc ((PTR
) NULL
, ptr
, size
));
921 /* My replacement for the read system call.
922 Used like `read' but keeps going if `read' returns too soon. */
925 myread (desc
, addr
, len
)
935 val
= read (desc
, addr
, len
);
946 /* Make a copy of the string at PTR with SIZE characters
947 (and add a null character at the end in the copy).
948 Uses malloc to get the space. Returns the address of the copy. */
951 savestring (ptr
, size
)
955 register char *p
= (char *) xmalloc (size
+ 1);
956 memcpy (p
, ptr
, size
);
962 msavestring (md
, ptr
, size
)
967 register char *p
= (char *) xmmalloc (md
, size
+ 1);
968 memcpy (p
, ptr
, size
);
973 /* The "const" is so it compiles under DGUX (which prototypes strsave
974 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
975 Doesn't real strsave return NULL if out of memory? */
980 return savestring (ptr
, strlen (ptr
));
988 return (msavestring (md
, ptr
, strlen (ptr
)));
992 print_spaces (n
, file
)
994 register GDB_FILE
*file
;
996 fputs_unfiltered (n_spaces (n
), file
);
999 /* Print a host address. */
1002 gdb_print_address (addr
, stream
)
1007 /* We could use the %p conversion specifier to fprintf if we had any
1008 way of knowing whether this host supports it. But the following
1009 should work on the Alpha and on 32 bit machines. */
1011 fprintf_filtered (stream
, "0x%lx", (unsigned long)addr
);
1014 /* Ask user a y-or-n question and return 1 iff answer is yes.
1015 Takes three args which are given to printf to print the question.
1016 The first, a control string, should end in "? ".
1017 It should not say how to answer, because we do that. */
1021 #ifdef ANSI_PROTOTYPES
1022 query (char *ctlstr
, ...)
1029 register int answer
;
1033 #ifdef ANSI_PROTOTYPES
1034 va_start (args
, ctlstr
);
1038 ctlstr
= va_arg (args
, char *);
1043 return query_hook (ctlstr
, args
);
1046 /* Automatically answer "yes" if input is not from a terminal. */
1047 if (!input_from_terminal_p ())
1050 /* FIXME Automatically answer "yes" if called from MacGDB. */
1057 wrap_here (""); /* Flush any buffered output */
1058 gdb_flush (gdb_stdout
);
1060 if (annotation_level
> 1)
1061 printf_filtered ("\n\032\032pre-query\n");
1063 vfprintf_filtered (gdb_stdout
, ctlstr
, args
);
1064 printf_filtered ("(y or n) ");
1066 if (annotation_level
> 1)
1067 printf_filtered ("\n\032\032query\n");
1070 /* If not in MacGDB, move to a new line so the entered line doesn't
1071 have a prompt on the front of it. */
1073 fputs_unfiltered ("\n", gdb_stdout
);
1077 gdb_flush (gdb_stdout
);
1080 if (!tui_version
|| cmdWin
== tuiWinWithFocus())
1082 answer
= fgetc (stdin
);
1086 answer
= (unsigned char)tuiBufferGetc();
1089 clearerr (stdin
); /* in case of C-d */
1090 if (answer
== EOF
) /* C-d */
1095 /* Eat rest of input line, to EOF or newline */
1096 if ((answer
!= '\n') || (tui_version
&& answer
!= '\r'))
1100 if (!tui_version
|| cmdWin
== tuiWinWithFocus())
1102 ans2
= fgetc (stdin
);
1106 ans2
= (unsigned char)tuiBufferGetc();
1110 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
1111 TUIDO(((TuiOpaqueFuncPtr
)tui_vStartNewLines
, 1));
1125 printf_filtered ("Please answer y or n.\n");
1128 if (annotation_level
> 1)
1129 printf_filtered ("\n\032\032post-query\n");
1134 /* Parse a C escape sequence. STRING_PTR points to a variable
1135 containing a pointer to the string to parse. That pointer
1136 should point to the character after the \. That pointer
1137 is updated past the characters we use. The value of the
1138 escape sequence is returned.
1140 A negative value means the sequence \ newline was seen,
1141 which is supposed to be equivalent to nothing at all.
1143 If \ is followed by a null character, we return a negative
1144 value and leave the string pointer pointing at the null character.
1146 If \ is followed by 000, we return 0 and leave the string pointer
1147 after the zeros. A value of 0 does not mean end of string. */
1150 parse_escape (string_ptr
)
1153 register int c
= *(*string_ptr
)++;
1157 return 007; /* Bell (alert) char */
1160 case 'e': /* Escape character */
1178 c
= *(*string_ptr
)++;
1180 c
= parse_escape (string_ptr
);
1183 return (c
& 0200) | (c
& 037);
1194 register int i
= c
- '0';
1195 register int count
= 0;
1198 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
1216 /* Print the character C on STREAM as part of the contents of a literal
1217 string whose delimiter is QUOTER. Note that this routine should only
1218 be call for printing things which are independent of the language
1219 of the program being debugged. */
1222 gdb_printchar (c
, stream
, quoter
)
1228 c
&= 0xFF; /* Avoid sign bit follies */
1230 if ( c
< 0x20 || /* Low control chars */
1231 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
1232 (sevenbit_strings
&& c
>= 0x80)) { /* high order bit set */
1236 fputs_filtered ("\\n", stream
);
1239 fputs_filtered ("\\b", stream
);
1242 fputs_filtered ("\\t", stream
);
1245 fputs_filtered ("\\f", stream
);
1248 fputs_filtered ("\\r", stream
);
1251 fputs_filtered ("\\e", stream
);
1254 fputs_filtered ("\\a", stream
);
1257 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
1261 if (c
== '\\' || c
== quoter
)
1262 fputs_filtered ("\\", stream
);
1263 fprintf_filtered (stream
, "%c", c
);
1268 /* Number of lines per page or UINT_MAX if paging is disabled. */
1269 static unsigned int lines_per_page
;
1270 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
1271 static unsigned int chars_per_line
;
1272 /* Current count of lines printed on this page, chars on this line. */
1273 static unsigned int lines_printed
, chars_printed
;
1275 /* Buffer and start column of buffered text, for doing smarter word-
1276 wrapping. When someone calls wrap_here(), we start buffering output
1277 that comes through fputs_filtered(). If we see a newline, we just
1278 spit it out and forget about the wrap_here(). If we see another
1279 wrap_here(), we spit it out and remember the newer one. If we see
1280 the end of the line, we spit out a newline, the indent, and then
1281 the buffered output. */
1283 /* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
1284 are waiting to be output (they have already been counted in chars_printed).
1285 When wrap_buffer[0] is null, the buffer is empty. */
1286 static char *wrap_buffer
;
1288 /* Pointer in wrap_buffer to the next character to fill. */
1289 static char *wrap_pointer
;
1291 /* String to indent by if the wrap occurs. Must not be NULL if wrap_column
1293 static char *wrap_indent
;
1295 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
1296 is not in effect. */
1297 static int wrap_column
;
1300 /* Inialize the lines and chars per page */
1305 if (tui_version
&& m_winPtrNotNull(cmdWin
))
1307 lines_per_page
= cmdWin
->generic
.height
;
1308 chars_per_line
= cmdWin
->generic
.width
;
1313 /* These defaults will be used if we are unable to get the correct
1314 values from termcap. */
1315 #if defined(__GO32__)
1316 lines_per_page
= ScreenRows();
1317 chars_per_line
= ScreenCols();
1319 lines_per_page
= 24;
1320 chars_per_line
= 80;
1322 #if !defined (MPW) && !defined (_WIN32)
1323 /* No termcap under MPW, although might be cool to do something
1324 by looking at worksheet or console window sizes. */
1325 /* Initialize the screen height and width from termcap. */
1327 char *termtype
= getenv ("TERM");
1329 /* Positive means success, nonpositive means failure. */
1332 /* 2048 is large enough for all known terminals, according to the
1333 GNU termcap manual. */
1334 char term_buffer
[2048];
1338 status
= tgetent (term_buffer
, termtype
);
1342 int running_in_emacs
= getenv ("EMACS") != NULL
;
1344 val
= tgetnum ("li");
1345 if (val
>= 0 && !running_in_emacs
)
1346 lines_per_page
= val
;
1348 /* The number of lines per page is not mentioned
1349 in the terminal description. This probably means
1350 that paging is not useful (e.g. emacs shell window),
1351 so disable paging. */
1352 lines_per_page
= UINT_MAX
;
1354 val
= tgetnum ("co");
1356 chars_per_line
= val
;
1362 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1364 /* If there is a better way to determine the window size, use it. */
1365 SIGWINCH_HANDLER (SIGWINCH
);
1368 /* If the output is not a terminal, don't paginate it. */
1369 if (!GDB_FILE_ISATTY (gdb_stdout
))
1370 lines_per_page
= UINT_MAX
;
1371 } /* the command_line_version */
1378 if (chars_per_line
== 0)
1383 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
1384 wrap_buffer
[0] = '\0';
1387 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
1388 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
1393 set_width_command (args
, from_tty
, c
)
1396 struct cmd_list_element
*c
;
1401 /* Wait, so the user can read what's on the screen. Prompt the user
1402 to continue by pressing RETURN. */
1405 prompt_for_continue ()
1408 char cont_prompt
[120];
1410 if (annotation_level
> 1)
1411 printf_unfiltered ("\n\032\032pre-prompt-for-continue\n");
1413 strcpy (cont_prompt
,
1414 "---Type <return> to continue, or q <return> to quit---");
1415 if (annotation_level
> 1)
1416 strcat (cont_prompt
, "\n\032\032prompt-for-continue\n");
1418 /* We must do this *before* we call gdb_readline, else it will eventually
1419 call us -- thinking that we're trying to print beyond the end of the
1421 reinitialize_more_filter ();
1424 /* On a real operating system, the user can quit with SIGINT.
1427 'q' is provided on all systems so users don't have to change habits
1428 from system to system, and because telling them what to do in
1429 the prompt is more user-friendly than expecting them to think of
1431 /* Call readline, not gdb_readline, because GO32 readline handles control-C
1432 whereas control-C to gdb_readline will cause the user to get dumped
1434 ignore
= readline (cont_prompt
);
1436 if (annotation_level
> 1)
1437 printf_unfiltered ("\n\032\032post-prompt-for-continue\n");
1442 while (*p
== ' ' || *p
== '\t')
1447 request_quit (SIGINT
);
1449 async_request_quit (0);
1455 /* Now we have to do this again, so that GDB will know that it doesn't
1456 need to save the ---Type <return>--- line at the top of the screen. */
1457 reinitialize_more_filter ();
1459 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
1462 /* Reinitialize filter; ie. tell it to reset to original values. */
1465 reinitialize_more_filter ()
1471 /* Indicate that if the next sequence of characters overflows the line,
1472 a newline should be inserted here rather than when it hits the end.
1473 If INDENT is non-null, it is a string to be printed to indent the
1474 wrapped part on the next line. INDENT must remain accessible until
1475 the next call to wrap_here() or until a newline is printed through
1478 If the line is already overfull, we immediately print a newline and
1479 the indentation, and disable further wrapping.
1481 If we don't know the width of lines, but we know the page height,
1482 we must not wrap words, but should still keep track of newlines
1483 that were explicitly printed.
1485 INDENT should not contain tabs, as that will mess up the char count
1486 on the next line. FIXME.
1488 This routine is guaranteed to force out any output which has been
1489 squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
1490 used to force out output from the wrap_buffer. */
1496 /* This should have been allocated, but be paranoid anyway. */
1502 *wrap_pointer
= '\0';
1503 fputs_unfiltered (wrap_buffer
, gdb_stdout
);
1505 wrap_pointer
= wrap_buffer
;
1506 wrap_buffer
[0] = '\0';
1507 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
1511 else if (chars_printed
>= chars_per_line
)
1513 puts_filtered ("\n");
1515 puts_filtered (indent
);
1520 wrap_column
= chars_printed
;
1524 wrap_indent
= indent
;
1528 /* Ensure that whatever gets printed next, using the filtered output
1529 commands, starts at the beginning of the line. I.E. if there is
1530 any pending output for the current line, flush it and start a new
1531 line. Otherwise do nothing. */
1536 if (chars_printed
> 0)
1538 puts_filtered ("\n");
1543 /* ``struct gdb_file'' implementation that maps directly onto
1544 <stdio.h>'s FILE. */
1546 static gdb_file_fputs_ftype stdio_file_fputs
;
1547 static gdb_file_isatty_ftype stdio_file_isatty
;
1548 static gdb_file_delete_ftype stdio_file_delete
;
1549 static struct gdb_file
*stdio_file_new
PARAMS ((FILE *file
, int close_p
));
1550 static gdb_file_flush_ftype stdio_file_flush
;
1552 static int stdio_file_magic
;
1561 static struct gdb_file
*
1562 stdio_file_new (file
, close_p
)
1566 struct gdb_file
*gdb_file
= gdb_file_new ();
1567 struct stdio_file
*stdio
= xmalloc (sizeof (struct stdio_file
));
1568 stdio
->magic
= &stdio_file_magic
;
1570 stdio
->close_p
= close_p
;
1571 set_gdb_file_data (gdb_file
, stdio
, stdio_file_delete
);
1572 set_gdb_file_flush (gdb_file
, stdio_file_flush
);
1573 set_gdb_file_fputs (gdb_file
, stdio_file_fputs
);
1574 set_gdb_file_isatty (gdb_file
, stdio_file_isatty
);
1579 stdio_file_delete (file
)
1580 struct gdb_file
*file
;
1582 struct stdio_file
*stdio
= gdb_file_data (file
);
1583 if (stdio
->magic
!= &stdio_file_magic
)
1584 error ("Internal error: bad magic number");
1587 fclose (stdio
->file
);
1593 stdio_file_flush (file
)
1594 struct gdb_file
*file
;
1596 struct stdio_file
*stdio
= gdb_file_data (file
);
1597 if (stdio
->magic
!= &stdio_file_magic
)
1598 error ("Internal error: bad magic number");
1599 fflush (stdio
->file
);
1603 stdio_file_fputs (linebuffer
, file
)
1604 const char *linebuffer
;
1605 struct gdb_file
*file
;
1607 struct stdio_file
*stdio
= gdb_file_data (file
);
1608 if (stdio
->magic
!= &stdio_file_magic
)
1609 error ("Internal error: bad magic number");
1610 fputs (linebuffer
, stdio
->file
);
1614 stdio_file_isatty (file
)
1615 struct gdb_file
*file
;
1617 struct stdio_file
*stdio
= gdb_file_data (file
);
1618 if (stdio
->magic
!= &stdio_file_magic
)
1619 error ("Internal error: bad magic number");
1620 return (isatty (fileno (stdio
->file
)));
1623 /* Like fdopen(). Create a gdb_file from a previously opened FILE. */
1626 stdio_fileopen (file
)
1629 return stdio_file_new (file
, 0);
1633 /* A ``struct gdb_file'' that is compatible with all the legacy
1636 static gdb_file_flush_ftype tui_file_flush
;
1637 extern gdb_file_fputs_ftype tui_file_fputs
;
1638 static gdb_file_isatty_ftype tui_file_isatty
;
1639 static gdb_file_rewind_ftype tui_file_rewind
;
1640 static gdb_file_put_ftype tui_file_put
;
1641 static gdb_file_delete_ftype tui_file_delete
;
1642 static struct gdb_file
*tui_file_new
PARAMS ((void));
1643 static int tui_file_magic
;
1645 static struct gdb_file
*
1648 struct tui_stream
*tui
= xmalloc (sizeof (struct tui_stream
));
1649 struct gdb_file
*file
= gdb_file_new ();
1650 set_gdb_file_data (file
, tui
, tui_file_delete
);
1651 set_gdb_file_flush (file
, tui_file_flush
);
1652 set_gdb_file_fputs (file
, tui_file_fputs
);
1653 set_gdb_file_isatty (file
, tui_file_isatty
);
1654 set_gdb_file_rewind (file
, tui_file_rewind
);
1655 set_gdb_file_put (file
, tui_file_put
);
1656 tui
->ts_magic
= &tui_file_magic
;
1661 tui_file_delete (file
)
1662 struct gdb_file
*file
;
1664 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1665 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1666 error ("Internal error: bad magic number");
1667 if ((tmpstream
->ts_streamtype
== astring
) &&
1668 (tmpstream
->ts_strbuf
!= NULL
))
1670 free (tmpstream
->ts_strbuf
);
1676 tui_fileopen (stream
)
1679 struct gdb_file
*file
= tui_file_new ();
1680 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1681 tmpstream
->ts_streamtype
= afile
;
1682 tmpstream
->ts_filestream
= stream
;
1683 tmpstream
->ts_strbuf
= NULL
;
1684 tmpstream
->ts_buflen
= 0;
1689 tui_file_isatty (file
)
1690 struct gdb_file
*file
;
1692 struct tui_stream
*stream
= gdb_file_data (file
);
1693 if (stream
->ts_magic
!= &tui_file_magic
)
1694 error ("Internal error: bad magic number");
1695 if (stream
->ts_streamtype
== afile
)
1696 return (isatty(fileno(stream
->ts_filestream
)));
1701 tui_file_rewind (file
)
1702 struct gdb_file
*file
;
1704 struct tui_stream
*stream
= gdb_file_data (file
);
1705 if (stream
->ts_magic
!= &tui_file_magic
)
1706 error ("Internal error: bad magic number");
1707 stream
->ts_strbuf
[0] = '\0';
1711 tui_file_put (file
, dest
)
1712 struct gdb_file
*file
;
1713 struct gdb_file
*dest
;
1715 struct tui_stream
*stream
= gdb_file_data (file
);
1716 if (stream
->ts_magic
!= &tui_file_magic
)
1717 error ("Internal error: bad magic number");
1718 if (stream
->ts_streamtype
== astring
)
1720 fputs_unfiltered (stream
->ts_strbuf
, dest
);
1725 gdb_file_init_astring (n
)
1728 struct gdb_file
*file
= tui_file_new ();
1729 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1730 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1731 error ("Internal error: bad magic number");
1733 tmpstream
->ts_streamtype
= astring
;
1734 tmpstream
->ts_filestream
= NULL
;
1737 tmpstream
->ts_strbuf
= xmalloc ((n
+ 1)*sizeof(char));
1738 tmpstream
->ts_strbuf
[0] = '\0';
1741 tmpstream
->ts_strbuf
= NULL
;
1742 tmpstream
->ts_buflen
= n
;
1748 gdb_file_deallocate (streamptr
)
1749 GDB_FILE
**streamptr
;
1751 gdb_file_delete (*streamptr
);
1756 gdb_file_get_strbuf (file
)
1759 struct tui_stream
*stream
= gdb_file_data (file
);
1760 if (stream
->ts_magic
!= &tui_file_magic
)
1761 error ("Internal error: bad magic number");
1762 return (stream
->ts_strbuf
);
1765 /* adjust the length of the buffer by the amount necessary
1766 to accomodate appending a string of length N to the buffer contents */
1768 gdb_file_adjust_strbuf (n
, file
)
1772 struct tui_stream
*stream
= gdb_file_data (file
);
1774 if (stream
->ts_magic
!= &tui_file_magic
)
1775 error ("Internal error: bad magic number");
1777 if (stream
->ts_streamtype
!= astring
)
1780 if (stream
->ts_strbuf
)
1782 /* There is already a buffer allocated */
1783 non_null_chars
= strlen(stream
->ts_strbuf
);
1785 if (n
> (stream
->ts_buflen
- non_null_chars
- 1))
1787 stream
->ts_buflen
= n
+ non_null_chars
+ 1;
1788 stream
->ts_strbuf
= xrealloc (stream
->ts_strbuf
, stream
->ts_buflen
);
1792 /* No buffer yet, so allocate one of the desired size */
1793 stream
->ts_strbuf
= xmalloc ((n
+ 1) * sizeof (char));
1797 gdb_fopen (name
, mode
)
1801 FILE *f
= fopen (name
, mode
);
1804 return stdio_file_new (f
, 1);
1808 tui_file_flush (file
)
1811 struct tui_stream
*stream
= gdb_file_data (file
);
1812 if (stream
->ts_magic
!= &tui_file_magic
)
1813 error ("Internal error: bad magic number");
1815 && (file
== gdb_stdout
1816 || file
== gdb_stderr
))
1822 fflush (stream
->ts_filestream
);
1826 gdb_fclose(streamptr
)
1827 GDB_FILE
**streamptr
;
1829 gdb_file_delete (*streamptr
);
1834 /* Implement the ``struct gdb_file'' object. */
1836 static gdb_file_isatty_ftype null_file_isatty
;
1837 static gdb_file_fputs_ftype null_file_fputs
;
1838 static gdb_file_flush_ftype null_file_flush
;
1839 static gdb_file_delete_ftype null_file_delete
;
1840 static gdb_file_rewind_ftype null_file_rewind
;
1841 static gdb_file_put_ftype null_file_put
;
1845 gdb_file_flush_ftype
*to_flush
;
1846 gdb_file_fputs_ftype
*to_fputs
;
1847 gdb_file_delete_ftype
*to_delete
;
1848 gdb_file_isatty_ftype
*to_isatty
;
1849 gdb_file_rewind_ftype
*to_rewind
;
1850 gdb_file_put_ftype
*to_put
;
1857 struct gdb_file
*file
= xmalloc (sizeof (struct gdb_file
));
1858 set_gdb_file_data (file
, NULL
, null_file_delete
);
1859 set_gdb_file_flush (file
, null_file_flush
);
1860 set_gdb_file_fputs (file
, null_file_fputs
);
1861 set_gdb_file_isatty (file
, null_file_isatty
);
1862 set_gdb_file_rewind (file
, null_file_rewind
);
1863 set_gdb_file_put (file
, null_file_put
);
1868 gdb_file_delete (file
)
1869 struct gdb_file
*file
;
1871 file
->to_delete (file
);
1876 null_file_isatty (file
)
1877 struct gdb_file
*file
;
1883 null_file_rewind (file
)
1884 struct gdb_file
*file
;
1890 null_file_put (file
, src
)
1891 struct gdb_file
*file
;
1892 struct gdb_file
*src
;
1898 null_file_flush (file
)
1899 struct gdb_file
*file
;
1905 null_file_fputs (buf
, file
)
1907 struct gdb_file
*file
;
1913 null_file_delete (file
)
1914 struct gdb_file
*file
;
1920 gdb_file_data (file
)
1921 struct gdb_file
*file
;
1923 return file
->to_data
;
1928 struct gdb_file
*file
;
1930 file
->to_flush (file
);
1934 gdb_file_isatty (file
)
1935 struct gdb_file
*file
;
1937 return file
->to_isatty (file
);
1941 gdb_file_rewind (file
)
1942 struct gdb_file
*file
;
1944 file
->to_rewind (file
);
1948 gdb_file_put (file
, dest
)
1949 struct gdb_file
*file
;
1950 struct gdb_file
*dest
;
1952 file
->to_put (file
, dest
);
1956 fputs_unfiltered (buf
, file
)
1958 struct gdb_file
*file
;
1960 file
->to_fputs (buf
, file
);
1964 set_gdb_file_flush (file
, flush
)
1965 struct gdb_file
*file
;
1966 gdb_file_flush_ftype
*flush
;
1968 file
->to_flush
= flush
;
1972 set_gdb_file_isatty (file
, isatty
)
1973 struct gdb_file
*file
;
1974 gdb_file_isatty_ftype
*isatty
;
1976 file
->to_isatty
= isatty
;
1980 set_gdb_file_rewind (file
, rewind
)
1981 struct gdb_file
*file
;
1982 gdb_file_rewind_ftype
*rewind
;
1984 file
->to_rewind
= rewind
;
1988 set_gdb_file_put (file
, put
)
1989 struct gdb_file
*file
;
1990 gdb_file_put_ftype
*put
;
1996 set_gdb_file_fputs (file
, fputs
)
1997 struct gdb_file
*file
;
1998 gdb_file_fputs_ftype
*fputs
;
2000 file
->to_fputs
= fputs
;
2004 set_gdb_file_data (file
, data
, delete)
2005 struct gdb_file
*file
;
2007 gdb_file_delete_ftype
*delete;
2009 file
->to_data
= data
;
2010 file
->to_delete
= delete;
2013 /* Like fputs but if FILTER is true, pause after every screenful.
2015 Regardless of FILTER can wrap at points other than the final
2016 character of a line.
2018 Unlike fputs, fputs_maybe_filtered does not return a value.
2019 It is OK for LINEBUFFER to be NULL, in which case just don't print
2022 Note that a longjmp to top level may occur in this routine (only if
2023 FILTER is true) (since prompt_for_continue may do so) so this
2024 routine should not be called when cleanups are not in place. */
2027 fputs_maybe_filtered (linebuffer
, stream
, filter
)
2028 const char *linebuffer
;
2032 const char *lineptr
;
2034 if (linebuffer
== 0)
2037 /* Don't do any filtering if it is disabled. */
2038 if ((stream
!= gdb_stdout
) || !pagination_enabled
2039 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
2041 fputs_unfiltered (linebuffer
, stream
);
2045 /* Go through and output each character. Show line extension
2046 when this is necessary; prompt user for new page when this is
2049 lineptr
= linebuffer
;
2052 /* Possible new page. */
2054 (lines_printed
>= lines_per_page
- 1))
2055 prompt_for_continue ();
2057 while (*lineptr
&& *lineptr
!= '\n')
2059 /* Print a single line. */
2060 if (*lineptr
== '\t')
2063 *wrap_pointer
++ = '\t';
2065 fputc_unfiltered ('\t', stream
);
2066 /* Shifting right by 3 produces the number of tab stops
2067 we have already passed, and then adding one and
2068 shifting left 3 advances to the next tab stop. */
2069 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
2075 *wrap_pointer
++ = *lineptr
;
2077 fputc_unfiltered (*lineptr
, stream
);
2082 if (chars_printed
>= chars_per_line
)
2084 unsigned int save_chars
= chars_printed
;
2088 /* If we aren't actually wrapping, don't output newline --
2089 if chars_per_line is right, we probably just overflowed
2090 anyway; if it's wrong, let us keep going. */
2092 fputc_unfiltered ('\n', stream
);
2094 /* Possible new page. */
2095 if (lines_printed
>= lines_per_page
- 1)
2096 prompt_for_continue ();
2098 /* Now output indentation and wrapped string */
2101 fputs_unfiltered (wrap_indent
, stream
);
2102 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
2103 fputs_unfiltered (wrap_buffer
, stream
); /* and eject it */
2104 /* FIXME, this strlen is what prevents wrap_indent from
2105 containing tabs. However, if we recurse to print it
2106 and count its chars, we risk trouble if wrap_indent is
2107 longer than (the user settable) chars_per_line.
2108 Note also that this can set chars_printed > chars_per_line
2109 if we are printing a long string. */
2110 chars_printed
= strlen (wrap_indent
)
2111 + (save_chars
- wrap_column
);
2112 wrap_pointer
= wrap_buffer
; /* Reset buffer */
2113 wrap_buffer
[0] = '\0';
2114 wrap_column
= 0; /* And disable fancy wrap */
2119 if (*lineptr
== '\n')
2122 wrap_here ((char *)0); /* Spit out chars, cancel further wraps */
2124 fputc_unfiltered ('\n', stream
);
2131 fputs_filtered (linebuffer
, stream
)
2132 const char *linebuffer
;
2135 fputs_maybe_filtered (linebuffer
, stream
, 1);
2139 putchar_unfiltered (c
)
2146 fputs_unfiltered (buf
, gdb_stdout
);
2151 fputc_unfiltered (c
, stream
)
2159 fputs_unfiltered (buf
, stream
);
2164 fputc_filtered (c
, stream
)
2172 fputs_filtered (buf
, stream
);
2176 /* puts_debug is like fputs_unfiltered, except it prints special
2177 characters in printable fashion. */
2180 puts_debug (prefix
, string
, suffix
)
2187 /* Print prefix and suffix after each line. */
2188 static int new_line
= 1;
2189 static int return_p
= 0;
2190 static char *prev_prefix
= "";
2191 static char *prev_suffix
= "";
2193 if (*string
== '\n')
2196 /* If the prefix is changing, print the previous suffix, a new line,
2197 and the new prefix. */
2198 if ((return_p
|| (strcmp(prev_prefix
, prefix
) != 0)) && !new_line
)
2200 fputs_unfiltered (prev_suffix
, gdb_stderr
);
2201 fputs_unfiltered ("\n", gdb_stderr
);
2202 fputs_unfiltered (prefix
, gdb_stderr
);
2205 /* Print prefix if we printed a newline during the previous call. */
2209 fputs_unfiltered (prefix
, gdb_stderr
);
2212 prev_prefix
= prefix
;
2213 prev_suffix
= suffix
;
2215 /* Output characters in a printable format. */
2216 while ((ch
= *string
++) != '\0')
2222 fputc_unfiltered (ch
, gdb_stderr
);
2225 fprintf_unfiltered (gdb_stderr
, "\\x%02x", ch
& 0xff);
2228 case '\\': fputs_unfiltered ("\\\\", gdb_stderr
); break;
2229 case '\b': fputs_unfiltered ("\\b", gdb_stderr
); break;
2230 case '\f': fputs_unfiltered ("\\f", gdb_stderr
); break;
2231 case '\n': new_line
= 1;
2232 fputs_unfiltered ("\\n", gdb_stderr
); break;
2233 case '\r': fputs_unfiltered ("\\r", gdb_stderr
); break;
2234 case '\t': fputs_unfiltered ("\\t", gdb_stderr
); break;
2235 case '\v': fputs_unfiltered ("\\v", gdb_stderr
); break;
2238 return_p
= ch
== '\r';
2241 /* Print suffix if we printed a newline. */
2244 fputs_unfiltered (suffix
, gdb_stderr
);
2245 fputs_unfiltered ("\n", gdb_stderr
);
2250 /* Print a variable number of ARGS using format FORMAT. If this
2251 information is going to put the amount written (since the last call
2252 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
2253 call prompt_for_continue to get the users permision to continue.
2255 Unlike fprintf, this function does not return a value.
2257 We implement three variants, vfprintf (takes a vararg list and stream),
2258 fprintf (takes a stream to write on), and printf (the usual).
2260 Note also that a longjmp to top level may occur in this routine
2261 (since prompt_for_continue may do so) so this routine should not be
2262 called when cleanups are not in place. */
2265 vfprintf_maybe_filtered (stream
, format
, args
, filter
)
2272 struct cleanup
*old_cleanups
;
2274 vasprintf (&linebuffer
, format
, args
);
2275 if (linebuffer
== NULL
)
2277 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2280 old_cleanups
= make_cleanup (free
, linebuffer
);
2281 fputs_maybe_filtered (linebuffer
, stream
, filter
);
2282 do_cleanups (old_cleanups
);
2287 vfprintf_filtered (stream
, format
, args
)
2292 vfprintf_maybe_filtered (stream
, format
, args
, 1);
2296 vfprintf_unfiltered (stream
, format
, args
)
2302 struct cleanup
*old_cleanups
;
2304 vasprintf (&linebuffer
, format
, args
);
2305 if (linebuffer
== NULL
)
2307 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2310 old_cleanups
= make_cleanup (free
, linebuffer
);
2311 fputs_unfiltered (linebuffer
, stream
);
2312 do_cleanups (old_cleanups
);
2316 vprintf_filtered (format
, args
)
2320 vfprintf_maybe_filtered (gdb_stdout
, format
, args
, 1);
2324 vprintf_unfiltered (format
, args
)
2328 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2333 #ifdef ANSI_PROTOTYPES
2334 fprintf_filtered (GDB_FILE
*stream
, const char *format
, ...)
2336 fprintf_filtered (va_alist
)
2341 #ifdef ANSI_PROTOTYPES
2342 va_start (args
, format
);
2348 stream
= va_arg (args
, GDB_FILE
*);
2349 format
= va_arg (args
, char *);
2351 vfprintf_filtered (stream
, format
, args
);
2357 #ifdef ANSI_PROTOTYPES
2358 fprintf_unfiltered (GDB_FILE
*stream
, const char *format
, ...)
2360 fprintf_unfiltered (va_alist
)
2365 #ifdef ANSI_PROTOTYPES
2366 va_start (args
, format
);
2372 stream
= va_arg (args
, GDB_FILE
*);
2373 format
= va_arg (args
, char *);
2375 vfprintf_unfiltered (stream
, format
, args
);
2379 /* Like fprintf_filtered, but prints its result indented.
2380 Called as fprintfi_filtered (spaces, stream, format, ...); */
2384 #ifdef ANSI_PROTOTYPES
2385 fprintfi_filtered (int spaces
, GDB_FILE
*stream
, const char *format
, ...)
2387 fprintfi_filtered (va_alist
)
2392 #ifdef ANSI_PROTOTYPES
2393 va_start (args
, format
);
2400 spaces
= va_arg (args
, int);
2401 stream
= va_arg (args
, GDB_FILE
*);
2402 format
= va_arg (args
, char *);
2404 print_spaces_filtered (spaces
, stream
);
2406 vfprintf_filtered (stream
, format
, args
);
2413 #ifdef ANSI_PROTOTYPES
2414 printf_filtered (const char *format
, ...)
2416 printf_filtered (va_alist
)
2421 #ifdef ANSI_PROTOTYPES
2422 va_start (args
, format
);
2427 format
= va_arg (args
, char *);
2429 vfprintf_filtered (gdb_stdout
, format
, args
);
2436 #ifdef ANSI_PROTOTYPES
2437 printf_unfiltered (const char *format
, ...)
2439 printf_unfiltered (va_alist
)
2444 #ifdef ANSI_PROTOTYPES
2445 va_start (args
, format
);
2450 format
= va_arg (args
, char *);
2452 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2456 /* Like printf_filtered, but prints it's result indented.
2457 Called as printfi_filtered (spaces, format, ...); */
2461 #ifdef ANSI_PROTOTYPES
2462 printfi_filtered (int spaces
, const char *format
, ...)
2464 printfi_filtered (va_alist
)
2469 #ifdef ANSI_PROTOTYPES
2470 va_start (args
, format
);
2476 spaces
= va_arg (args
, int);
2477 format
= va_arg (args
, char *);
2479 print_spaces_filtered (spaces
, gdb_stdout
);
2480 vfprintf_filtered (gdb_stdout
, format
, args
);
2484 /* Easy -- but watch out!
2486 This routine is *not* a replacement for puts()! puts() appends a newline.
2487 This one doesn't, and had better not! */
2490 puts_filtered (string
)
2493 fputs_filtered (string
, gdb_stdout
);
2497 puts_unfiltered (string
)
2500 fputs_unfiltered (string
, gdb_stdout
);
2503 /* Return a pointer to N spaces and a null. The pointer is good
2504 until the next call to here. */
2510 static char *spaces
= 0;
2511 static int max_spaces
= -1;
2517 spaces
= (char *) xmalloc (n
+1);
2518 for (t
= spaces
+n
; t
!= spaces
;)
2524 return spaces
+ max_spaces
- n
;
2527 /* Print N spaces. */
2529 print_spaces_filtered (n
, stream
)
2533 fputs_filtered (n_spaces (n
), stream
);
2536 /* C++ demangler stuff. */
2538 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
2539 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
2540 If the name is not mangled, or the language for the name is unknown, or
2541 demangling is off, the name is printed in its "raw" form. */
2544 fprintf_symbol_filtered (stream
, name
, lang
, arg_mode
)
2554 /* If user wants to see raw output, no problem. */
2557 fputs_filtered (name
, stream
);
2563 case language_cplus
:
2564 demangled
= cplus_demangle (name
, arg_mode
);
2567 demangled
= cplus_demangle (name
, arg_mode
| DMGL_JAVA
);
2569 case language_chill
:
2570 demangled
= chill_demangle (name
);
2576 fputs_filtered (demangled
? demangled
: name
, stream
);
2577 if (demangled
!= NULL
)
2585 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
2586 differences in whitespace. Returns 0 if they match, non-zero if they
2587 don't (slightly different than strcmp()'s range of return values).
2589 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
2590 This "feature" is useful when searching for matching C++ function names
2591 (such as if the user types 'break FOO', where FOO is a mangled C++
2595 strcmp_iw (string1
, string2
)
2596 const char *string1
;
2597 const char *string2
;
2599 while ((*string1
!= '\0') && (*string2
!= '\0'))
2601 while (isspace (*string1
))
2605 while (isspace (*string2
))
2609 if (*string1
!= *string2
)
2613 if (*string1
!= '\0')
2619 return (*string1
!= '\0' && *string1
!= '(') || (*string2
!= '\0');
2625 ** Answer whether string_to_compare is a full or partial match to
2626 ** template_string. The partial match must be in sequence starting
2630 subset_compare (string_to_compare
, template_string
)
2631 char *string_to_compare
;
2632 char *template_string
;
2635 if (template_string
!= (char *)NULL
&& string_to_compare
!= (char *)NULL
&&
2636 strlen(string_to_compare
) <= strlen(template_string
))
2637 match
= (strncmp(template_string
,
2639 strlen(string_to_compare
)) == 0);
2646 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2648 pagination_on_command (arg
, from_tty
)
2652 pagination_enabled
= 1;
2655 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2657 pagination_off_command (arg
, from_tty
)
2661 pagination_enabled
= 0;
2668 struct cmd_list_element
*c
;
2670 c
= add_set_cmd ("width", class_support
, var_uinteger
,
2671 (char *)&chars_per_line
,
2672 "Set number of characters gdb thinks are in a line.",
2674 add_show_from_set (c
, &showlist
);
2675 c
->function
.sfunc
= set_width_command
;
2678 (add_set_cmd ("height", class_support
,
2679 var_uinteger
, (char *)&lines_per_page
,
2680 "Set number of lines gdb thinks are in a page.", &setlist
),
2685 /* If the output is not a terminal, don't paginate it. */
2686 if (!GDB_FILE_ISATTY (gdb_stdout
))
2687 lines_per_page
= UINT_MAX
;
2689 set_width_command ((char *)NULL
, 0, c
);
2692 (add_set_cmd ("demangle", class_support
, var_boolean
,
2694 "Set demangling of encoded C++ names when displaying symbols.",
2699 (add_set_cmd ("pagination", class_support
,
2700 var_boolean
, (char *)&pagination_enabled
,
2701 "Set state of pagination.", &setlist
),
2705 add_com("am", class_support
, pagination_on_command
,
2706 "Enable pagination");
2707 add_com("sm", class_support
, pagination_off_command
,
2708 "Disable pagination");
2712 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
2713 (char *)&sevenbit_strings
,
2714 "Set printing of 8-bit characters in strings as \\nnn.",
2719 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
2720 (char *)&asm_demangle
,
2721 "Set demangling of C++ names in disassembly listings.",
2726 /* Machine specific function to handle SIGWINCH signal. */
2728 #ifdef SIGWINCH_HANDLER_BODY
2729 SIGWINCH_HANDLER_BODY
2732 /* Support for converting target fp numbers into host DOUBLEST format. */
2734 /* XXX - This code should really be in libiberty/floatformat.c, however
2735 configuration issues with libiberty made this very difficult to do in the
2738 #include "floatformat.h"
2739 #include <math.h> /* ldexp */
2741 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
2742 going to bother with trying to muck around with whether it is defined in
2743 a system header, what we do if not, etc. */
2744 #define FLOATFORMAT_CHAR_BIT 8
2746 static unsigned long get_field
PARAMS ((unsigned char *,
2747 enum floatformat_byteorders
,
2752 /* Extract a field which starts at START and is LEN bytes long. DATA and
2753 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2754 static unsigned long
2755 get_field (data
, order
, total_len
, start
, len
)
2756 unsigned char *data
;
2757 enum floatformat_byteorders order
;
2758 unsigned int total_len
;
2762 unsigned long result
;
2763 unsigned int cur_byte
;
2766 /* Start at the least significant part of the field. */
2767 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2768 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2769 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2771 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2772 result
= *(data
+ cur_byte
) >> (-cur_bitshift
);
2773 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2774 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2779 /* Move towards the most significant part of the field. */
2780 while (cur_bitshift
< len
)
2782 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
2783 /* This is the last byte; zero out the bits which are not part of
2786 (*(data
+ cur_byte
) & ((1 << (len
- cur_bitshift
)) - 1))
2789 result
|= *(data
+ cur_byte
) << cur_bitshift
;
2790 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2791 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2799 /* Convert from FMT to a DOUBLEST.
2800 FROM is the address of the extended float.
2801 Store the DOUBLEST in *TO. */
2804 floatformat_to_doublest (fmt
, from
, to
)
2805 const struct floatformat
*fmt
;
2809 unsigned char *ufrom
= (unsigned char *)from
;
2813 unsigned int mant_bits
, mant_off
;
2815 int special_exponent
; /* It's a NaN, denorm or zero */
2817 /* If the mantissa bits are not contiguous from one end of the
2818 mantissa to the other, we need to make a private copy of the
2819 source bytes that is in the right order since the unpacking
2820 algorithm assumes that the bits are contiguous.
2822 Swap the bytes individually rather than accessing them through
2823 "long *" since we have no guarantee that they start on a long
2824 alignment, and also sizeof(long) for the host could be different
2825 than sizeof(long) for the target. FIXME: Assumes sizeof(long)
2826 for the target is 4. */
2828 if (fmt
-> byteorder
== floatformat_littlebyte_bigword
)
2830 static unsigned char *newfrom
;
2831 unsigned char *swapin
, *swapout
;
2834 longswaps
= fmt
-> totalsize
/ FLOATFORMAT_CHAR_BIT
;
2837 if (newfrom
== NULL
)
2839 newfrom
= (unsigned char *) xmalloc (fmt
-> totalsize
);
2844 while (longswaps
-- > 0)
2846 /* This is ugly, but efficient */
2847 *swapout
++ = swapin
[4];
2848 *swapout
++ = swapin
[5];
2849 *swapout
++ = swapin
[6];
2850 *swapout
++ = swapin
[7];
2851 *swapout
++ = swapin
[0];
2852 *swapout
++ = swapin
[1];
2853 *swapout
++ = swapin
[2];
2854 *swapout
++ = swapin
[3];
2859 exponent
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2860 fmt
->exp_start
, fmt
->exp_len
);
2861 /* Note that if exponent indicates a NaN, we can't really do anything useful
2862 (not knowing if the host has NaN's, or how to build one). So it will
2863 end up as an infinity or something close; that is OK. */
2865 mant_bits_left
= fmt
->man_len
;
2866 mant_off
= fmt
->man_start
;
2869 special_exponent
= exponent
== 0 || exponent
== fmt
->exp_nan
;
2871 /* Don't bias zero's, denorms or NaNs. */
2872 if (!special_exponent
)
2873 exponent
-= fmt
->exp_bias
;
2875 /* Build the result algebraically. Might go infinite, underflow, etc;
2878 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
2879 increment the exponent by one to account for the integer bit. */
2881 if (!special_exponent
)
2883 if (fmt
->intbit
== floatformat_intbit_no
)
2884 dto
= ldexp (1.0, exponent
);
2889 while (mant_bits_left
> 0)
2891 mant_bits
= min (mant_bits_left
, 32);
2893 mant
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2894 mant_off
, mant_bits
);
2896 dto
+= ldexp ((double)mant
, exponent
- mant_bits
);
2897 exponent
-= mant_bits
;
2898 mant_off
+= mant_bits
;
2899 mant_bits_left
-= mant_bits
;
2902 /* Negate it if negative. */
2903 if (get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1))
2908 static void put_field
PARAMS ((unsigned char *, enum floatformat_byteorders
,
2914 /* Set a field which starts at START and is LEN bytes long. DATA and
2915 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2917 put_field (data
, order
, total_len
, start
, len
, stuff_to_put
)
2918 unsigned char *data
;
2919 enum floatformat_byteorders order
;
2920 unsigned int total_len
;
2923 unsigned long stuff_to_put
;
2925 unsigned int cur_byte
;
2928 /* Start at the least significant part of the field. */
2929 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2930 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2931 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2933 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2934 *(data
+ cur_byte
) &=
2935 ~(((1 << ((start
+ len
) % FLOATFORMAT_CHAR_BIT
)) - 1) << (-cur_bitshift
));
2936 *(data
+ cur_byte
) |=
2937 (stuff_to_put
& ((1 << FLOATFORMAT_CHAR_BIT
) - 1)) << (-cur_bitshift
);
2938 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2939 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2944 /* Move towards the most significant part of the field. */
2945 while (cur_bitshift
< len
)
2947 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
2949 /* This is the last byte. */
2950 *(data
+ cur_byte
) &=
2951 ~((1 << (len
- cur_bitshift
)) - 1);
2952 *(data
+ cur_byte
) |= (stuff_to_put
>> cur_bitshift
);
2955 *(data
+ cur_byte
) = ((stuff_to_put
>> cur_bitshift
)
2956 & ((1 << FLOATFORMAT_CHAR_BIT
) - 1));
2957 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2958 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2965 #ifdef HAVE_LONG_DOUBLE
2966 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
2967 The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
2968 frexp, but operates on the long double data type. */
2970 static long double ldfrexp
PARAMS ((long double value
, int *eptr
));
2973 ldfrexp (value
, eptr
)
2980 /* Unfortunately, there are no portable functions for extracting the exponent
2981 of a long double, so we have to do it iteratively by multiplying or dividing
2982 by two until the fraction is between 0.5 and 1.0. */
2990 if (value
>= tmp
) /* Value >= 1.0 */
2991 while (value
>= tmp
)
2996 else if (value
!= 0.0l) /* Value < 1.0 and > 0.0 */
3010 #endif /* HAVE_LONG_DOUBLE */
3013 /* The converse: convert the DOUBLEST *FROM to an extended float
3014 and store where TO points. Neither FROM nor TO have any alignment
3018 floatformat_from_doublest (fmt
, from
, to
)
3019 CONST
struct floatformat
*fmt
;
3026 unsigned int mant_bits
, mant_off
;
3028 unsigned char *uto
= (unsigned char *)to
;
3030 memcpy (&dfrom
, from
, sizeof (dfrom
));
3031 memset (uto
, 0, fmt
->totalsize
/ FLOATFORMAT_CHAR_BIT
);
3033 return; /* Result is zero */
3034 if (dfrom
!= dfrom
) /* Result is NaN */
3037 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3038 fmt
->exp_len
, fmt
->exp_nan
);
3039 /* Be sure it's not infinity, but NaN value is irrel */
3040 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3045 /* If negative, set the sign bit. */
3048 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1, 1);
3052 if (dfrom
+ dfrom
== dfrom
&& dfrom
!= 0.0) /* Result is Infinity */
3054 /* Infinity exponent is same as NaN's. */
3055 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3056 fmt
->exp_len
, fmt
->exp_nan
);
3057 /* Infinity mantissa is all zeroes. */
3058 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3063 #ifdef HAVE_LONG_DOUBLE
3064 mant
= ldfrexp (dfrom
, &exponent
);
3066 mant
= frexp (dfrom
, &exponent
);
3069 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
, fmt
->exp_len
,
3070 exponent
+ fmt
->exp_bias
- 1);
3072 mant_bits_left
= fmt
->man_len
;
3073 mant_off
= fmt
->man_start
;
3074 while (mant_bits_left
> 0)
3076 unsigned long mant_long
;
3077 mant_bits
= mant_bits_left
< 32 ? mant_bits_left
: 32;
3079 mant
*= 4294967296.0;
3080 mant_long
= (unsigned long)mant
;
3083 /* If the integer bit is implicit, then we need to discard it.
3084 If we are discarding a zero, we should be (but are not) creating
3085 a denormalized number which means adjusting the exponent
3087 if (mant_bits_left
== fmt
->man_len
3088 && fmt
->intbit
== floatformat_intbit_no
)
3096 /* The bits we want are in the most significant MANT_BITS bits of
3097 mant_long. Move them to the least significant. */
3098 mant_long
>>= 32 - mant_bits
;
3101 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
,
3102 mant_off
, mant_bits
, mant_long
);
3103 mant_off
+= mant_bits
;
3104 mant_bits_left
-= mant_bits
;
3106 if (fmt
-> byteorder
== floatformat_littlebyte_bigword
)
3109 unsigned char *swaplow
= uto
;
3110 unsigned char *swaphigh
= uto
+ 4;
3113 for (count
= 0; count
< 4; count
++)
3116 *swaplow
++ = *swaphigh
;
3122 /* temporary storage using circular buffer */
3128 static char buf
[NUMCELLS
][CELLSIZE
];
3130 if (++cell
>=NUMCELLS
) cell
=0;
3134 /* print routines to handle variable size regs, etc.
3136 FIXME: Note that t_addr is a bfd_vma, which is currently either an
3137 unsigned long or unsigned long long, determined at configure time.
3138 If t_addr is an unsigned long long and sizeof (unsigned long long)
3139 is greater than sizeof (unsigned long), then I believe this code will
3140 probably lose, at least for little endian machines. I believe that
3141 it would also be better to eliminate the switch on the absolute size
3142 of t_addr and replace it with a sequence of if statements that compare
3143 sizeof t_addr with sizeof the various types and do the right thing,
3144 which includes knowing whether or not the host supports long long.
3149 static int thirty_two
= 32; /* eliminate warning from compiler on 32-bit systems */
3155 char *paddr_str
=get_cell();
3156 switch (sizeof(t_addr
))
3159 sprintf (paddr_str
, "%08lx%08lx",
3160 (unsigned long) (addr
>> thirty_two
), (unsigned long) (addr
& 0xffffffff));
3163 sprintf (paddr_str
, "%08lx", (unsigned long) addr
);
3166 sprintf (paddr_str
, "%04x", (unsigned short) (addr
& 0xffff));
3169 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3178 char *preg_str
=get_cell();
3179 switch (sizeof(t_reg
))
3182 sprintf (preg_str
, "%08lx%08lx",
3183 (unsigned long) (reg
>> thirty_two
), (unsigned long) (reg
& 0xffffffff));
3186 sprintf (preg_str
, "%08lx", (unsigned long) reg
);
3189 sprintf (preg_str
, "%04x", (unsigned short) (reg
& 0xffff));
3192 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3201 char *paddr_str
=get_cell();
3202 switch (sizeof(t_addr
))
3206 unsigned long high
= (unsigned long) (addr
>> thirty_two
);
3208 sprintf (paddr_str
, "%lx", (unsigned long) (addr
& 0xffffffff));
3210 sprintf (paddr_str
, "%lx%08lx",
3211 high
, (unsigned long) (addr
& 0xffffffff));
3215 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3218 sprintf (paddr_str
, "%x", (unsigned short) (addr
& 0xffff));
3221 sprintf (paddr_str
,"%lx", (unsigned long) addr
);
3230 char *preg_str
=get_cell();
3231 switch (sizeof(t_reg
))
3235 unsigned long high
= (unsigned long) (reg
>> thirty_two
);
3237 sprintf (preg_str
, "%lx", (unsigned long) (reg
& 0xffffffff));
3239 sprintf (preg_str
, "%lx%08lx",
3240 high
, (unsigned long) (reg
& 0xffffffff));
3244 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3247 sprintf (preg_str
, "%x", (unsigned short) (reg
& 0xffff));
3250 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3255 /* Helper functions for INNER_THAN */
3257 core_addr_lessthan (lhs
, rhs
)
3265 core_addr_greaterthan (lhs
, rhs
)