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"
35 /* SunOS's curses.h has a '#define reg register' in it. Thank you Sun. */
46 #include "expression.h"
50 #include <readline/readline.h>
52 /* readline defines this. */
55 void (*error_begin_hook
) PARAMS ((void));
57 /* Prototypes for local functions */
59 static void vfprintf_maybe_filtered
PARAMS ((GDB_FILE
*, const char *,
62 static void fputs_maybe_filtered
PARAMS ((const char *, GDB_FILE
*, int));
64 #if defined (USE_MMALLOC) && !defined (NO_MMCHECK)
65 static void malloc_botch
PARAMS ((void));
69 prompt_for_continue
PARAMS ((void));
72 set_width_command
PARAMS ((char *, int, struct cmd_list_element
*));
75 set_width
PARAMS ((void));
77 /* If this definition isn't overridden by the header files, assume
78 that isatty and fileno exist on this system. */
80 #define ISATTY(FP) (isatty (fileno (FP)))
83 #ifndef GDB_FILE_ISATTY
84 #define GDB_FILE_ISATTY(GDB_FILE_PTR) (gdb_file_isatty(GDB_FILE_PTR))
87 /* Chain of cleanup actions established with make_cleanup,
88 to be executed if an error happens. */
90 static struct cleanup
*cleanup_chain
; /* cleaned up after a failed command */
91 static struct cleanup
*final_cleanup_chain
; /* cleaned up when gdb exits */
92 static struct cleanup
*run_cleanup_chain
; /* cleaned up on each 'run' */
93 static struct cleanup
*exec_cleanup_chain
; /* cleaned up on each execution command */
95 /* Pointer to what is left to do for an execution command after the
96 target stops. Used only in asynchronous mode, by targets that
97 support async execution. The finish and until commands use it. So
98 does the target extended-remote command. */
99 struct continuation
*cmd_continuation
;
101 /* Nonzero if we have job control. */
105 /* Nonzero means a quit has been requested. */
109 /* Nonzero means quit immediately if Control-C is typed now, rather
110 than waiting until QUIT is executed. Be careful in setting this;
111 code which executes with immediate_quit set has to be very careful
112 about being able to deal with being interrupted at any time. It is
113 almost always better to use QUIT; the only exception I can think of
114 is being able to quit out of a system call (using EINTR loses if
115 the SIGINT happens between the previous QUIT and the system call).
116 To immediately quit in the case in which a SIGINT happens between
117 the previous QUIT and setting immediate_quit (desirable anytime we
118 expect to block), call QUIT after setting immediate_quit. */
122 /* Nonzero means that encoded C++ names should be printed out in their
123 C++ form rather than raw. */
127 /* Nonzero means that encoded C++ names should be printed out in their
128 C++ form even in assembler language displays. If this is set, but
129 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
131 int asm_demangle
= 0;
133 /* Nonzero means that strings with character values >0x7F should be printed
134 as octal escapes. Zero means just print the value (e.g. it's an
135 international character, and the terminal or window can cope.) */
137 int sevenbit_strings
= 0;
139 /* String to be printed before error messages, if any. */
141 char *error_pre_print
;
143 /* String to be printed before quit messages, if any. */
145 char *quit_pre_print
;
147 /* String to be printed before warning messages, if any. */
149 char *warning_pre_print
= "\nwarning: ";
151 int pagination_enabled
= 1;
154 /* Add a new cleanup to the cleanup_chain,
155 and return the previous chain pointer
156 to be passed later to do_cleanups or discard_cleanups.
157 Args are FUNCTION to clean up with, and ARG to pass to it. */
160 make_cleanup (function
, arg
)
161 void (*function
) PARAMS ((PTR
));
164 return make_my_cleanup (&cleanup_chain
, function
, arg
);
168 make_final_cleanup (function
, arg
)
169 void (*function
) PARAMS ((PTR
));
172 return make_my_cleanup (&final_cleanup_chain
, function
, arg
);
176 make_run_cleanup (function
, arg
)
177 void (*function
) PARAMS ((PTR
));
180 return make_my_cleanup (&run_cleanup_chain
, function
, arg
);
184 make_exec_cleanup (function
, arg
)
185 void (*function
) PARAMS ((PTR
));
188 return make_my_cleanup (&exec_cleanup_chain
, function
, arg
);
195 freeargv ((char **) arg
);
199 make_cleanup_freeargv (arg
)
202 return make_my_cleanup (&cleanup_chain
, do_freeargv
, arg
);
206 make_my_cleanup (pmy_chain
, function
, arg
)
207 struct cleanup
**pmy_chain
;
208 void (*function
) PARAMS ((PTR
));
211 register struct cleanup
*new
212 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
213 register struct cleanup
*old_chain
= *pmy_chain
;
215 new->next
= *pmy_chain
;
216 new->function
= function
;
223 /* Discard cleanups and do the actions they describe
224 until we get back to the point OLD_CHAIN in the cleanup_chain. */
227 do_cleanups (old_chain
)
228 register struct cleanup
*old_chain
;
230 do_my_cleanups (&cleanup_chain
, old_chain
);
234 do_final_cleanups (old_chain
)
235 register struct cleanup
*old_chain
;
237 do_my_cleanups (&final_cleanup_chain
, old_chain
);
241 do_run_cleanups (old_chain
)
242 register struct cleanup
*old_chain
;
244 do_my_cleanups (&run_cleanup_chain
, old_chain
);
248 do_exec_cleanups (old_chain
)
249 register struct cleanup
*old_chain
;
251 do_my_cleanups (&exec_cleanup_chain
, old_chain
);
255 do_my_cleanups (pmy_chain
, old_chain
)
256 register struct cleanup
**pmy_chain
;
257 register struct cleanup
*old_chain
;
259 register struct cleanup
*ptr
;
260 while ((ptr
= *pmy_chain
) != old_chain
)
262 *pmy_chain
= ptr
->next
; /* Do this first incase recursion */
263 (*ptr
->function
) (ptr
->arg
);
268 /* Discard cleanups, not doing the actions they describe,
269 until we get back to the point OLD_CHAIN in the cleanup_chain. */
272 discard_cleanups (old_chain
)
273 register struct cleanup
*old_chain
;
275 discard_my_cleanups (&cleanup_chain
, old_chain
);
279 discard_final_cleanups (old_chain
)
280 register struct cleanup
*old_chain
;
282 discard_my_cleanups (&final_cleanup_chain
, old_chain
);
286 discard_my_cleanups (pmy_chain
, old_chain
)
287 register struct cleanup
**pmy_chain
;
288 register struct cleanup
*old_chain
;
290 register struct cleanup
*ptr
;
291 while ((ptr
= *pmy_chain
) != old_chain
)
293 *pmy_chain
= ptr
->next
;
298 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
302 return save_my_cleanups (&cleanup_chain
);
306 save_final_cleanups ()
308 return save_my_cleanups (&final_cleanup_chain
);
312 save_my_cleanups (pmy_chain
)
313 struct cleanup
**pmy_chain
;
315 struct cleanup
*old_chain
= *pmy_chain
;
321 /* Restore the cleanup chain from a previously saved chain. */
323 restore_cleanups (chain
)
324 struct cleanup
*chain
;
326 restore_my_cleanups (&cleanup_chain
, chain
);
330 restore_final_cleanups (chain
)
331 struct cleanup
*chain
;
333 restore_my_cleanups (&final_cleanup_chain
, chain
);
337 restore_my_cleanups (pmy_chain
, chain
)
338 struct cleanup
**pmy_chain
;
339 struct cleanup
*chain
;
344 /* This function is useful for cleanups.
348 old_chain = make_cleanup (free_current_contents, &foo);
350 to arrange to free the object thus allocated. */
353 free_current_contents (location
)
359 /* Provide a known function that does nothing, to use as a base for
360 for a possibly long chain of cleanups. This is useful where we
361 use the cleanup chain for handling normal cleanups as well as dealing
362 with cleanups that need to be done as a result of a call to error().
363 In such cases, we may not be certain where the first cleanup is, unless
364 we have a do-nothing one to always use as the base. */
373 /* Add a continuation to the continuation list, the gloabl list
376 add_continuation (continuation_hook
, arg_list
)
377 void (*continuation_hook
) PARAMS ((struct continuation_arg
*));
378 struct continuation_arg
*arg_list
;
380 struct continuation
*continuation_ptr
;
382 continuation_ptr
= (struct continuation
*) xmalloc (sizeof (struct continuation
));
383 continuation_ptr
->continuation_hook
= continuation_hook
;
384 continuation_ptr
->arg_list
= arg_list
;
385 continuation_ptr
->next
= cmd_continuation
;
386 cmd_continuation
= continuation_ptr
;
389 /* Walk down the cmd_continuation list, and execute all the
392 do_all_continuations ()
394 struct continuation
*continuation_ptr
;
396 while (cmd_continuation
)
398 (cmd_continuation
->continuation_hook
) (cmd_continuation
->arg_list
);
399 continuation_ptr
= cmd_continuation
;
400 cmd_continuation
= continuation_ptr
->next
;
401 free (continuation_ptr
);
406 /* Print a warning message. Way to use this is to call warning_begin,
407 output the warning message (use unfiltered output to gdb_stderr),
408 ending in a newline. There is not currently a warning_end that you
409 call afterwards, but such a thing might be added if it is useful
410 for a GUI to separate warning messages from other output.
412 FIXME: Why do warnings use unfiltered output and errors filtered?
413 Is this anything other than a historical accident? */
418 target_terminal_ours ();
419 wrap_here (""); /* Force out any buffered output */
420 gdb_flush (gdb_stdout
);
421 if (warning_pre_print
)
422 fprintf_unfiltered (gdb_stderr
, warning_pre_print
);
425 /* Print a warning message.
426 The first argument STRING is the warning message, used as a fprintf string,
427 and the remaining args are passed as arguments to it.
428 The primary difference between warnings and errors is that a warning
429 does not force the return to command level. */
432 warning (const char *string
,...)
435 va_start (args
, string
);
437 (*warning_hook
) (string
, args
);
441 vfprintf_unfiltered (gdb_stderr
, string
, args
);
442 fprintf_unfiltered (gdb_stderr
, "\n");
447 /* Start the printing of an error message. Way to use this is to call
448 this, output the error message (use filtered output to gdb_stderr
449 (FIXME: Some callers, like memory_error, use gdb_stdout)), ending
450 in a newline, and then call return_to_top_level (RETURN_ERROR).
451 error() provides a convenient way to do this for the special case
452 that the error message can be formatted with a single printf call,
453 but this is more general. */
457 if (error_begin_hook
)
460 target_terminal_ours ();
461 wrap_here (""); /* Force out any buffered output */
462 gdb_flush (gdb_stdout
);
464 annotate_error_begin ();
467 fprintf_filtered (gdb_stderr
, error_pre_print
);
470 /* Print an error message and return to command level.
471 The first argument STRING is the error message, used as a fprintf string,
472 and the remaining args are passed as arguments to it. */
475 error (const char *string
,...)
478 va_start (args
, string
);
484 vfprintf_filtered (gdb_stderr
, string
, args
);
485 fprintf_filtered (gdb_stderr
, "\n");
487 return_to_top_level (RETURN_ERROR
);
492 /* Print a message reporting an internal error. Ask the user if they
493 want to continue, dump core, or just exit. */
496 internal_error (char *string
, ...)
498 static char msg
[] = "Internal GDB error: recursive internal error.\n";
499 static int dejavu
= 0;
504 /* don't allow infinite error recursion. */
512 fputs_unfiltered (msg
, gdb_stderr
);
516 write (STDERR_FILENO
, msg
, sizeof (msg
));
520 /* Try to get the message out */
521 fputs_unfiltered ("gdb-internal-error: ", gdb_stderr
);
522 va_start (args
, string
);
523 vfprintf_unfiltered (gdb_stderr
, string
, args
);
525 fputs_unfiltered ("\n", gdb_stderr
);
527 /* Default (no case) is to quit GDB. When in batch mode this
528 lessens the likelhood of GDB going into an infinate loop. */
529 continue_p
= query ("\
530 An internal GDB error was detected. This may make make further\n\
531 debugging unreliable. Continue this debugging session? ");
533 /* Default (no case) is to not dump core. Lessen the chance of GDB
534 leaving random core files around. */
535 dump_core_p
= query ("\
536 Create a core file containing the current state of GDB? ");
555 return_to_top_level (RETURN_ERROR
);
558 /* The strerror() function can return NULL for errno values that are
559 out of range. Provide a "safe" version that always returns a
563 safe_strerror (errnum
)
569 if ((msg
= strerror (errnum
)) == NULL
)
571 sprintf (buf
, "(undocumented errno %d)", errnum
);
577 /* The strsignal() function can return NULL for signal values that are
578 out of range. Provide a "safe" version that always returns a
582 safe_strsignal (signo
)
588 if ((msg
= strsignal (signo
)) == NULL
)
590 sprintf (buf
, "(undocumented signal %d)", signo
);
597 /* Print the system error message for errno, and also mention STRING
598 as the file name for which the error was encountered.
599 Then return to command level. */
602 perror_with_name (string
)
608 err
= safe_strerror (errno
);
609 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
610 strcpy (combined
, string
);
611 strcat (combined
, ": ");
612 strcat (combined
, err
);
614 /* I understand setting these is a matter of taste. Still, some people
615 may clear errno but not know about bfd_error. Doing this here is not
617 bfd_set_error (bfd_error_no_error
);
620 error ("%s.", combined
);
623 /* Print the system error message for ERRCODE, and also mention STRING
624 as the file name for which the error was encountered. */
627 print_sys_errmsg (string
, errcode
)
634 err
= safe_strerror (errcode
);
635 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
636 strcpy (combined
, string
);
637 strcat (combined
, ": ");
638 strcat (combined
, err
);
640 /* We want anything which was printed on stdout to come out first, before
642 gdb_flush (gdb_stdout
);
643 fprintf_unfiltered (gdb_stderr
, "%s.\n", combined
);
646 /* Control C eventually causes this to be called, at a convenient time. */
651 serial_t gdb_stdout_serial
= serial_fdopen (1);
653 target_terminal_ours ();
655 /* We want all output to appear now, before we print "Quit". We
656 have 3 levels of buffering we have to flush (it's possible that
657 some of these should be changed to flush the lower-level ones
660 /* 1. The _filtered buffer. */
661 wrap_here ((char *) 0);
663 /* 2. The stdio buffer. */
664 gdb_flush (gdb_stdout
);
665 gdb_flush (gdb_stderr
);
667 /* 3. The system-level buffer. */
668 SERIAL_DRAIN_OUTPUT (gdb_stdout_serial
);
669 SERIAL_UN_FDOPEN (gdb_stdout_serial
);
671 annotate_error_begin ();
673 /* Don't use *_filtered; we don't want to prompt the user to continue. */
675 fprintf_unfiltered (gdb_stderr
, quit_pre_print
);
678 /* No steenking SIGINT will ever be coming our way when the
679 program is resumed. Don't lie. */
680 fprintf_unfiltered (gdb_stderr
, "Quit\n");
683 /* If there is no terminal switching for this target, then we can't
684 possibly get screwed by the lack of job control. */
685 || current_target
.to_terminal_ours
== NULL
)
686 fprintf_unfiltered (gdb_stderr
, "Quit\n");
688 fprintf_unfiltered (gdb_stderr
,
689 "Quit (expect signal SIGINT when the program is resumed)\n");
691 return_to_top_level (RETURN_QUIT
);
695 #if defined(_MSC_VER) /* should test for wingdb instead? */
698 * Windows translates all keyboard and mouse events
699 * into a message which is appended to the message
700 * queue for the process.
706 int k
= win32pollquit ();
713 #else /* !defined(__GO32__) && !defined(_MSC_VER) */
718 /* Done by signals */
721 #endif /* !defined(__GO32__) && !defined(_MSC_VER) */
723 /* Control C comes here */
729 /* Restore the signal handler. Harmless with BSD-style signals, needed
730 for System V-style signals. So just always do it, rather than worrying
731 about USG defines and stuff like that. */
732 signal (signo
, request_quit
);
742 /* Memory management stuff (malloc friends). */
744 /* Make a substitute size_t for non-ANSI compilers. */
746 #ifndef HAVE_STDDEF_H
748 #define size_t unsigned int
752 #if !defined (USE_MMALLOC)
759 return malloc (size
);
763 mrealloc (md
, ptr
, size
)
768 if (ptr
== 0) /* Guard against old realloc's */
769 return malloc (size
);
771 return realloc (ptr
, size
);
782 #endif /* USE_MMALLOC */
784 #if !defined (USE_MMALLOC) || defined (NO_MMCHECK)
792 #else /* Have mmalloc and want corruption checking */
797 fprintf_unfiltered (gdb_stderr
, "Memory corruption\n");
801 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
802 by MD, to detect memory corruption. Note that MD may be NULL to specify
803 the default heap that grows via sbrk.
805 Note that for freshly created regions, we must call mmcheckf prior to any
806 mallocs in the region. Otherwise, any region which was allocated prior to
807 installing the checking hooks, which is later reallocated or freed, will
808 fail the checks! The mmcheck function only allows initial hooks to be
809 installed before the first mmalloc. However, anytime after we have called
810 mmcheck the first time to install the checking hooks, we can call it again
811 to update the function pointer to the memory corruption handler.
813 Returns zero on failure, non-zero on success. */
815 #ifndef MMCHECK_FORCE
816 #define MMCHECK_FORCE 0
823 if (!mmcheckf (md
, malloc_botch
, MMCHECK_FORCE
))
825 /* Don't use warning(), which relies on current_target being set
826 to something other than dummy_target, until after
827 initialize_all_files(). */
830 (gdb_stderr
, "warning: failed to install memory consistency checks; ");
832 (gdb_stderr
, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
838 #endif /* Have mmalloc and want corruption checking */
840 /* Called when a memory allocation fails, with the number of bytes of
841 memory requested in SIZE. */
849 internal_error ("virtual memory exhausted: can't allocate %ld bytes.", size
);
853 internal_error ("virtual memory exhausted.");
857 /* Like mmalloc but get error if no storage available, and protect against
858 the caller wanting to allocate zero bytes. Whether to return NULL for
859 a zero byte request, or translate the request into a request for one
860 byte of zero'd storage, is a religious issue. */
873 else if ((val
= mmalloc (md
, size
)) == NULL
)
880 /* Like mrealloc but get error if no storage available. */
883 xmrealloc (md
, ptr
, size
)
892 val
= mrealloc (md
, ptr
, size
);
896 val
= mmalloc (md
, size
);
905 /* Like malloc but get error if no storage available, and protect against
906 the caller wanting to allocate zero bytes. */
912 return (xmmalloc ((PTR
) NULL
, size
));
915 /* Like mrealloc but get error if no storage available. */
922 return (xmrealloc ((PTR
) NULL
, ptr
, size
));
926 /* My replacement for the read system call.
927 Used like `read' but keeps going if `read' returns too soon. */
930 myread (desc
, addr
, len
)
940 val
= read (desc
, addr
, len
);
951 /* Make a copy of the string at PTR with SIZE characters
952 (and add a null character at the end in the copy).
953 Uses malloc to get the space. Returns the address of the copy. */
956 savestring (ptr
, size
)
960 register char *p
= (char *) xmalloc (size
+ 1);
961 memcpy (p
, ptr
, size
);
967 msavestring (md
, ptr
, size
)
972 register char *p
= (char *) xmmalloc (md
, size
+ 1);
973 memcpy (p
, ptr
, size
);
978 /* The "const" is so it compiles under DGUX (which prototypes strsave
979 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
980 Doesn't real strsave return NULL if out of memory? */
985 return savestring (ptr
, strlen (ptr
));
993 return (msavestring (md
, ptr
, strlen (ptr
)));
997 print_spaces (n
, file
)
999 register GDB_FILE
*file
;
1001 fputs_unfiltered (n_spaces (n
), file
);
1004 /* Print a host address. */
1007 gdb_print_address (addr
, stream
)
1012 /* We could use the %p conversion specifier to fprintf if we had any
1013 way of knowing whether this host supports it. But the following
1014 should work on the Alpha and on 32 bit machines. */
1016 fprintf_filtered (stream
, "0x%lx", (unsigned long) addr
);
1019 /* Ask user a y-or-n question and return 1 iff answer is yes.
1020 Takes three args which are given to printf to print the question.
1021 The first, a control string, should end in "? ".
1022 It should not say how to answer, because we do that. */
1026 query (char *ctlstr
,...)
1029 register int answer
;
1033 va_start (args
, ctlstr
);
1037 return query_hook (ctlstr
, args
);
1040 /* Automatically answer "yes" if input is not from a terminal. */
1041 if (!input_from_terminal_p ())
1044 /* FIXME Automatically answer "yes" if called from MacGDB. */
1051 wrap_here (""); /* Flush any buffered output */
1052 gdb_flush (gdb_stdout
);
1054 if (annotation_level
> 1)
1055 printf_filtered ("\n\032\032pre-query\n");
1057 vfprintf_filtered (gdb_stdout
, ctlstr
, args
);
1058 printf_filtered ("(y or n) ");
1060 if (annotation_level
> 1)
1061 printf_filtered ("\n\032\032query\n");
1064 /* If not in MacGDB, move to a new line so the entered line doesn't
1065 have a prompt on the front of it. */
1067 fputs_unfiltered ("\n", gdb_stdout
);
1071 gdb_flush (gdb_stdout
);
1074 if (!tui_version
|| cmdWin
== tuiWinWithFocus ())
1076 answer
= fgetc (stdin
);
1079 answer
= (unsigned char) tuiBufferGetc ();
1082 clearerr (stdin
); /* in case of C-d */
1083 if (answer
== EOF
) /* C-d */
1088 /* Eat rest of input line, to EOF or newline */
1089 if ((answer
!= '\n') || (tui_version
&& answer
!= '\r'))
1093 if (!tui_version
|| cmdWin
== tuiWinWithFocus ())
1095 ans2
= fgetc (stdin
);
1098 ans2
= (unsigned char) tuiBufferGetc ();
1102 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
1103 TUIDO (((TuiOpaqueFuncPtr
) tui_vStartNewLines
, 1));
1117 printf_filtered ("Please answer y or n.\n");
1120 if (annotation_level
> 1)
1121 printf_filtered ("\n\032\032post-query\n");
1126 /* Parse a C escape sequence. STRING_PTR points to a variable
1127 containing a pointer to the string to parse. That pointer
1128 should point to the character after the \. That pointer
1129 is updated past the characters we use. The value of the
1130 escape sequence is returned.
1132 A negative value means the sequence \ newline was seen,
1133 which is supposed to be equivalent to nothing at all.
1135 If \ is followed by a null character, we return a negative
1136 value and leave the string pointer pointing at the null character.
1138 If \ is followed by 000, we return 0 and leave the string pointer
1139 after the zeros. A value of 0 does not mean end of string. */
1142 parse_escape (string_ptr
)
1145 register int c
= *(*string_ptr
)++;
1149 return 007; /* Bell (alert) char */
1152 case 'e': /* Escape character */
1170 c
= *(*string_ptr
)++;
1172 c
= parse_escape (string_ptr
);
1175 return (c
& 0200) | (c
& 037);
1186 register int i
= c
- '0';
1187 register int count
= 0;
1190 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
1208 /* Print the character C on STREAM as part of the contents of a literal
1209 string whose delimiter is QUOTER. Note that this routine should only
1210 be call for printing things which are independent of the language
1211 of the program being debugged. */
1213 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
));
1216 printchar (c
, do_fputs
, do_fprintf
, stream
, quoter
)
1218 void (*do_fputs
) PARAMS ((const char *, GDB_FILE
*));
1219 void (*do_fprintf
) PARAMS ((GDB_FILE
*, const char *, ...));
1224 c
&= 0xFF; /* Avoid sign bit follies */
1226 if (c
< 0x20 || /* Low control chars */
1227 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
1228 (sevenbit_strings
&& c
>= 0x80))
1229 { /* high order bit set */
1233 do_fputs ("\\n", stream
);
1236 do_fputs ("\\b", stream
);
1239 do_fputs ("\\t", stream
);
1242 do_fputs ("\\f", stream
);
1245 do_fputs ("\\r", stream
);
1248 do_fputs ("\\e", stream
);
1251 do_fputs ("\\a", stream
);
1254 do_fprintf (stream
, "\\%.3o", (unsigned int) c
);
1260 if (c
== '\\' || c
== quoter
)
1261 do_fputs ("\\", stream
);
1262 do_fprintf (stream
, "%c", c
);
1266 /* Print the character C on STREAM as part of the contents of a
1267 literal string whose delimiter is QUOTER. Note that these routines
1268 should only be call for printing things which are independent of
1269 the language of the program being debugged. */
1272 fputstr_filtered (str
, quoter
, stream
)
1278 printchar (*str
++, fputs_filtered
, fprintf_filtered
, stream
, quoter
);
1282 fputstr_unfiltered (str
, quoter
, stream
)
1288 printchar (*str
++, fputs_unfiltered
, fprintf_unfiltered
, stream
, quoter
);
1292 fputstrn_unfiltered (str
, n
, quoter
, stream
)
1299 for (i
= 0; i
< n
; i
++)
1300 printchar (str
[i
], fputs_unfiltered
, fprintf_unfiltered
, stream
, quoter
);
1305 /* Number of lines per page or UINT_MAX if paging is disabled. */
1306 static unsigned int lines_per_page
;
1307 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
1308 static unsigned int chars_per_line
;
1309 /* Current count of lines printed on this page, chars on this line. */
1310 static unsigned int lines_printed
, chars_printed
;
1312 /* Buffer and start column of buffered text, for doing smarter word-
1313 wrapping. When someone calls wrap_here(), we start buffering output
1314 that comes through fputs_filtered(). If we see a newline, we just
1315 spit it out and forget about the wrap_here(). If we see another
1316 wrap_here(), we spit it out and remember the newer one. If we see
1317 the end of the line, we spit out a newline, the indent, and then
1318 the buffered output. */
1320 /* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
1321 are waiting to be output (they have already been counted in chars_printed).
1322 When wrap_buffer[0] is null, the buffer is empty. */
1323 static char *wrap_buffer
;
1325 /* Pointer in wrap_buffer to the next character to fill. */
1326 static char *wrap_pointer
;
1328 /* String to indent by if the wrap occurs. Must not be NULL if wrap_column
1330 static char *wrap_indent
;
1332 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
1333 is not in effect. */
1334 static int wrap_column
;
1337 /* Inialize the lines and chars per page */
1342 if (tui_version
&& m_winPtrNotNull (cmdWin
))
1344 lines_per_page
= cmdWin
->generic
.height
;
1345 chars_per_line
= cmdWin
->generic
.width
;
1350 /* These defaults will be used if we are unable to get the correct
1351 values from termcap. */
1352 #if defined(__GO32__)
1353 lines_per_page
= ScreenRows ();
1354 chars_per_line
= ScreenCols ();
1356 lines_per_page
= 24;
1357 chars_per_line
= 80;
1359 #if !defined (MPW) && !defined (_WIN32)
1360 /* No termcap under MPW, although might be cool to do something
1361 by looking at worksheet or console window sizes. */
1362 /* Initialize the screen height and width from termcap. */
1364 char *termtype
= getenv ("TERM");
1366 /* Positive means success, nonpositive means failure. */
1369 /* 2048 is large enough for all known terminals, according to the
1370 GNU termcap manual. */
1371 char term_buffer
[2048];
1375 status
= tgetent (term_buffer
, termtype
);
1379 int running_in_emacs
= getenv ("EMACS") != NULL
;
1381 val
= tgetnum ("li");
1382 if (val
>= 0 && !running_in_emacs
)
1383 lines_per_page
= val
;
1385 /* The number of lines per page is not mentioned
1386 in the terminal description. This probably means
1387 that paging is not useful (e.g. emacs shell window),
1388 so disable paging. */
1389 lines_per_page
= UINT_MAX
;
1391 val
= tgetnum ("co");
1393 chars_per_line
= val
;
1399 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1401 /* If there is a better way to determine the window size, use it. */
1402 SIGWINCH_HANDLER (SIGWINCH
);
1405 /* If the output is not a terminal, don't paginate it. */
1406 if (!GDB_FILE_ISATTY (gdb_stdout
))
1407 lines_per_page
= UINT_MAX
;
1408 } /* the command_line_version */
1415 if (chars_per_line
== 0)
1420 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
1421 wrap_buffer
[0] = '\0';
1424 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
1425 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
1430 set_width_command (args
, from_tty
, c
)
1433 struct cmd_list_element
*c
;
1438 /* Wait, so the user can read what's on the screen. Prompt the user
1439 to continue by pressing RETURN. */
1442 prompt_for_continue ()
1445 char cont_prompt
[120];
1447 if (annotation_level
> 1)
1448 printf_unfiltered ("\n\032\032pre-prompt-for-continue\n");
1450 strcpy (cont_prompt
,
1451 "---Type <return> to continue, or q <return> to quit---");
1452 if (annotation_level
> 1)
1453 strcat (cont_prompt
, "\n\032\032prompt-for-continue\n");
1455 /* We must do this *before* we call gdb_readline, else it will eventually
1456 call us -- thinking that we're trying to print beyond the end of the
1458 reinitialize_more_filter ();
1461 /* On a real operating system, the user can quit with SIGINT.
1464 'q' is provided on all systems so users don't have to change habits
1465 from system to system, and because telling them what to do in
1466 the prompt is more user-friendly than expecting them to think of
1468 /* Call readline, not gdb_readline, because GO32 readline handles control-C
1469 whereas control-C to gdb_readline will cause the user to get dumped
1471 ignore
= readline (cont_prompt
);
1473 if (annotation_level
> 1)
1474 printf_unfiltered ("\n\032\032post-prompt-for-continue\n");
1479 while (*p
== ' ' || *p
== '\t')
1484 request_quit (SIGINT
);
1486 async_request_quit (0);
1492 /* Now we have to do this again, so that GDB will know that it doesn't
1493 need to save the ---Type <return>--- line at the top of the screen. */
1494 reinitialize_more_filter ();
1496 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
1499 /* Reinitialize filter; ie. tell it to reset to original values. */
1502 reinitialize_more_filter ()
1508 /* Indicate that if the next sequence of characters overflows the line,
1509 a newline should be inserted here rather than when it hits the end.
1510 If INDENT is non-null, it is a string to be printed to indent the
1511 wrapped part on the next line. INDENT must remain accessible until
1512 the next call to wrap_here() or until a newline is printed through
1515 If the line is already overfull, we immediately print a newline and
1516 the indentation, and disable further wrapping.
1518 If we don't know the width of lines, but we know the page height,
1519 we must not wrap words, but should still keep track of newlines
1520 that were explicitly printed.
1522 INDENT should not contain tabs, as that will mess up the char count
1523 on the next line. FIXME.
1525 This routine is guaranteed to force out any output which has been
1526 squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
1527 used to force out output from the wrap_buffer. */
1533 /* This should have been allocated, but be paranoid anyway. */
1539 *wrap_pointer
= '\0';
1540 fputs_unfiltered (wrap_buffer
, gdb_stdout
);
1542 wrap_pointer
= wrap_buffer
;
1543 wrap_buffer
[0] = '\0';
1544 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
1548 else if (chars_printed
>= chars_per_line
)
1550 puts_filtered ("\n");
1552 puts_filtered (indent
);
1557 wrap_column
= chars_printed
;
1561 wrap_indent
= indent
;
1565 /* Ensure that whatever gets printed next, using the filtered output
1566 commands, starts at the beginning of the line. I.E. if there is
1567 any pending output for the current line, flush it and start a new
1568 line. Otherwise do nothing. */
1573 if (chars_printed
> 0)
1575 puts_filtered ("\n");
1580 /* ``struct gdb_file'' implementation that maps directly onto
1581 <stdio.h>'s FILE. */
1583 static gdb_file_fputs_ftype stdio_file_fputs
;
1584 static gdb_file_isatty_ftype stdio_file_isatty
;
1585 static gdb_file_delete_ftype stdio_file_delete
;
1586 static struct gdb_file
*stdio_file_new
PARAMS ((FILE * file
, int close_p
));
1587 static gdb_file_flush_ftype stdio_file_flush
;
1589 static int stdio_file_magic
;
1598 static struct gdb_file
*
1599 stdio_file_new (file
, close_p
)
1603 struct gdb_file
*gdb_file
= gdb_file_new ();
1604 struct stdio_file
*stdio
= xmalloc (sizeof (struct stdio_file
));
1605 stdio
->magic
= &stdio_file_magic
;
1607 stdio
->close_p
= close_p
;
1608 set_gdb_file_data (gdb_file
, stdio
, stdio_file_delete
);
1609 set_gdb_file_flush (gdb_file
, stdio_file_flush
);
1610 set_gdb_file_fputs (gdb_file
, stdio_file_fputs
);
1611 set_gdb_file_isatty (gdb_file
, stdio_file_isatty
);
1616 stdio_file_delete (file
)
1617 struct gdb_file
*file
;
1619 struct stdio_file
*stdio
= gdb_file_data (file
);
1620 if (stdio
->magic
!= &stdio_file_magic
)
1621 error ("Internal error: bad magic number");
1624 fclose (stdio
->file
);
1630 stdio_file_flush (file
)
1631 struct gdb_file
*file
;
1633 struct stdio_file
*stdio
= gdb_file_data (file
);
1634 if (stdio
->magic
!= &stdio_file_magic
)
1635 error ("Internal error: bad magic number");
1636 fflush (stdio
->file
);
1640 stdio_file_fputs (linebuffer
, file
)
1641 const char *linebuffer
;
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 fputs (linebuffer
, stdio
->file
);
1651 stdio_file_isatty (file
)
1652 struct gdb_file
*file
;
1654 struct stdio_file
*stdio
= gdb_file_data (file
);
1655 if (stdio
->magic
!= &stdio_file_magic
)
1656 error ("Internal error: bad magic number");
1657 return (isatty (fileno (stdio
->file
)));
1660 /* Like fdopen(). Create a gdb_file from a previously opened FILE. */
1663 stdio_fileopen (file
)
1666 return stdio_file_new (file
, 0);
1670 /* A ``struct gdb_file'' that is compatible with all the legacy
1673 static gdb_file_flush_ftype tui_file_flush
;
1674 extern gdb_file_fputs_ftype tui_file_fputs
;
1675 static gdb_file_isatty_ftype tui_file_isatty
;
1676 static gdb_file_rewind_ftype tui_file_rewind
;
1677 static gdb_file_put_ftype tui_file_put
;
1678 static gdb_file_delete_ftype tui_file_delete
;
1679 static struct gdb_file
*tui_file_new
PARAMS ((void));
1680 static int tui_file_magic
;
1682 static struct gdb_file
*
1685 struct tui_stream
*tui
= xmalloc (sizeof (struct tui_stream
));
1686 struct gdb_file
*file
= gdb_file_new ();
1687 set_gdb_file_data (file
, tui
, tui_file_delete
);
1688 set_gdb_file_flush (file
, tui_file_flush
);
1689 set_gdb_file_fputs (file
, tui_file_fputs
);
1690 set_gdb_file_isatty (file
, tui_file_isatty
);
1691 set_gdb_file_rewind (file
, tui_file_rewind
);
1692 set_gdb_file_put (file
, tui_file_put
);
1693 tui
->ts_magic
= &tui_file_magic
;
1698 tui_file_delete (file
)
1699 struct gdb_file
*file
;
1701 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1702 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1703 error ("Internal error: bad magic number");
1704 if ((tmpstream
->ts_streamtype
== astring
) &&
1705 (tmpstream
->ts_strbuf
!= NULL
))
1707 free (tmpstream
->ts_strbuf
);
1713 tui_fileopen (stream
)
1716 struct gdb_file
*file
= tui_file_new ();
1717 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1718 tmpstream
->ts_streamtype
= afile
;
1719 tmpstream
->ts_filestream
= stream
;
1720 tmpstream
->ts_strbuf
= NULL
;
1721 tmpstream
->ts_buflen
= 0;
1726 tui_file_isatty (file
)
1727 struct gdb_file
*file
;
1729 struct tui_stream
*stream
= gdb_file_data (file
);
1730 if (stream
->ts_magic
!= &tui_file_magic
)
1731 error ("Internal error: bad magic number");
1732 if (stream
->ts_streamtype
== afile
)
1733 return (isatty (fileno (stream
->ts_filestream
)));
1739 tui_file_rewind (file
)
1740 struct gdb_file
*file
;
1742 struct tui_stream
*stream
= gdb_file_data (file
);
1743 if (stream
->ts_magic
!= &tui_file_magic
)
1744 error ("Internal error: bad magic number");
1745 stream
->ts_strbuf
[0] = '\0';
1749 tui_file_put (file
, dest
)
1750 struct gdb_file
*file
;
1751 struct gdb_file
*dest
;
1753 struct tui_stream
*stream
= gdb_file_data (file
);
1754 if (stream
->ts_magic
!= &tui_file_magic
)
1755 error ("Internal error: bad magic number");
1756 if (stream
->ts_streamtype
== astring
)
1758 fputs_unfiltered (stream
->ts_strbuf
, dest
);
1763 gdb_file_init_astring (n
)
1766 struct gdb_file
*file
= tui_file_new ();
1767 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1768 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1769 error ("Internal error: bad magic number");
1771 tmpstream
->ts_streamtype
= astring
;
1772 tmpstream
->ts_filestream
= NULL
;
1775 tmpstream
->ts_strbuf
= xmalloc ((n
+ 1) * sizeof (char));
1776 tmpstream
->ts_strbuf
[0] = '\0';
1779 tmpstream
->ts_strbuf
= NULL
;
1780 tmpstream
->ts_buflen
= n
;
1786 gdb_file_deallocate (streamptr
)
1787 GDB_FILE
**streamptr
;
1789 gdb_file_delete (*streamptr
);
1794 gdb_file_get_strbuf (file
)
1797 struct tui_stream
*stream
= gdb_file_data (file
);
1798 if (stream
->ts_magic
!= &tui_file_magic
)
1799 error ("Internal error: bad magic number");
1800 return (stream
->ts_strbuf
);
1803 /* adjust the length of the buffer by the amount necessary
1804 to accomodate appending a string of length N to the buffer contents */
1806 gdb_file_adjust_strbuf (n
, file
)
1810 struct tui_stream
*stream
= gdb_file_data (file
);
1812 if (stream
->ts_magic
!= &tui_file_magic
)
1813 error ("Internal error: bad magic number");
1815 if (stream
->ts_streamtype
!= astring
)
1818 if (stream
->ts_strbuf
)
1820 /* There is already a buffer allocated */
1821 non_null_chars
= strlen (stream
->ts_strbuf
);
1823 if (n
> (stream
->ts_buflen
- non_null_chars
- 1))
1825 stream
->ts_buflen
= n
+ non_null_chars
+ 1;
1826 stream
->ts_strbuf
= xrealloc (stream
->ts_strbuf
, stream
->ts_buflen
);
1830 /* No buffer yet, so allocate one of the desired size */
1831 stream
->ts_strbuf
= xmalloc ((n
+ 1) * sizeof (char));
1835 gdb_fopen (name
, mode
)
1839 FILE *f
= fopen (name
, mode
);
1842 return stdio_file_new (f
, 1);
1846 tui_file_flush (file
)
1849 struct tui_stream
*stream
= gdb_file_data (file
);
1850 if (stream
->ts_magic
!= &tui_file_magic
)
1851 error ("Internal error: bad magic number");
1853 && (file
== gdb_stdout
1854 || file
== gdb_stderr
))
1860 fflush (stream
->ts_filestream
);
1864 gdb_fclose (streamptr
)
1865 GDB_FILE
**streamptr
;
1867 gdb_file_delete (*streamptr
);
1872 /* Implement the ``struct gdb_file'' object. */
1874 static gdb_file_isatty_ftype null_file_isatty
;
1875 static gdb_file_fputs_ftype null_file_fputs
;
1876 static gdb_file_flush_ftype null_file_flush
;
1877 static gdb_file_delete_ftype null_file_delete
;
1878 static gdb_file_rewind_ftype null_file_rewind
;
1879 static gdb_file_put_ftype null_file_put
;
1883 gdb_file_flush_ftype
*to_flush
;
1884 gdb_file_fputs_ftype
*to_fputs
;
1885 gdb_file_delete_ftype
*to_delete
;
1886 gdb_file_isatty_ftype
*to_isatty
;
1887 gdb_file_rewind_ftype
*to_rewind
;
1888 gdb_file_put_ftype
*to_put
;
1895 struct gdb_file
*file
= xmalloc (sizeof (struct gdb_file
));
1896 set_gdb_file_data (file
, NULL
, null_file_delete
);
1897 set_gdb_file_flush (file
, null_file_flush
);
1898 set_gdb_file_fputs (file
, null_file_fputs
);
1899 set_gdb_file_isatty (file
, null_file_isatty
);
1900 set_gdb_file_rewind (file
, null_file_rewind
);
1901 set_gdb_file_put (file
, null_file_put
);
1906 gdb_file_delete (file
)
1907 struct gdb_file
*file
;
1909 file
->to_delete (file
);
1914 null_file_isatty (file
)
1915 struct gdb_file
*file
;
1921 null_file_rewind (file
)
1922 struct gdb_file
*file
;
1928 null_file_put (file
, src
)
1929 struct gdb_file
*file
;
1930 struct gdb_file
*src
;
1936 null_file_flush (file
)
1937 struct gdb_file
*file
;
1943 null_file_fputs (buf
, file
)
1945 struct gdb_file
*file
;
1951 null_file_delete (file
)
1952 struct gdb_file
*file
;
1958 gdb_file_data (file
)
1959 struct gdb_file
*file
;
1961 return file
->to_data
;
1966 struct gdb_file
*file
;
1968 file
->to_flush (file
);
1972 gdb_file_isatty (file
)
1973 struct gdb_file
*file
;
1975 return file
->to_isatty (file
);
1979 gdb_file_rewind (file
)
1980 struct gdb_file
*file
;
1982 file
->to_rewind (file
);
1986 gdb_file_put (file
, dest
)
1987 struct gdb_file
*file
;
1988 struct gdb_file
*dest
;
1990 file
->to_put (file
, dest
);
1994 fputs_unfiltered (buf
, file
)
1996 struct gdb_file
*file
;
1998 file
->to_fputs (buf
, file
);
2002 set_gdb_file_flush (file
, flush
)
2003 struct gdb_file
*file
;
2004 gdb_file_flush_ftype
*flush
;
2006 file
->to_flush
= flush
;
2010 set_gdb_file_isatty (file
, isatty
)
2011 struct gdb_file
*file
;
2012 gdb_file_isatty_ftype
*isatty
;
2014 file
->to_isatty
= isatty
;
2018 set_gdb_file_rewind (file
, rewind
)
2019 struct gdb_file
*file
;
2020 gdb_file_rewind_ftype
*rewind
;
2022 file
->to_rewind
= rewind
;
2026 set_gdb_file_put (file
, put
)
2027 struct gdb_file
*file
;
2028 gdb_file_put_ftype
*put
;
2034 set_gdb_file_fputs (file
, fputs
)
2035 struct gdb_file
*file
;
2036 gdb_file_fputs_ftype
*fputs
;
2038 file
->to_fputs
= fputs
;
2042 set_gdb_file_data (file
, data
, delete)
2043 struct gdb_file
*file
;
2045 gdb_file_delete_ftype
*delete;
2047 file
->to_data
= data
;
2048 file
->to_delete
= delete;
2051 /* Like fputs but if FILTER is true, pause after every screenful.
2053 Regardless of FILTER can wrap at points other than the final
2054 character of a line.
2056 Unlike fputs, fputs_maybe_filtered does not return a value.
2057 It is OK for LINEBUFFER to be NULL, in which case just don't print
2060 Note that a longjmp to top level may occur in this routine (only if
2061 FILTER is true) (since prompt_for_continue may do so) so this
2062 routine should not be called when cleanups are not in place. */
2065 fputs_maybe_filtered (linebuffer
, stream
, filter
)
2066 const char *linebuffer
;
2070 const char *lineptr
;
2072 if (linebuffer
== 0)
2075 /* Don't do any filtering if it is disabled. */
2076 if ((stream
!= gdb_stdout
) || !pagination_enabled
2077 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
2079 fputs_unfiltered (linebuffer
, stream
);
2083 /* Go through and output each character. Show line extension
2084 when this is necessary; prompt user for new page when this is
2087 lineptr
= linebuffer
;
2090 /* Possible new page. */
2092 (lines_printed
>= lines_per_page
- 1))
2093 prompt_for_continue ();
2095 while (*lineptr
&& *lineptr
!= '\n')
2097 /* Print a single line. */
2098 if (*lineptr
== '\t')
2101 *wrap_pointer
++ = '\t';
2103 fputc_unfiltered ('\t', stream
);
2104 /* Shifting right by 3 produces the number of tab stops
2105 we have already passed, and then adding one and
2106 shifting left 3 advances to the next tab stop. */
2107 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
2113 *wrap_pointer
++ = *lineptr
;
2115 fputc_unfiltered (*lineptr
, stream
);
2120 if (chars_printed
>= chars_per_line
)
2122 unsigned int save_chars
= chars_printed
;
2126 /* If we aren't actually wrapping, don't output newline --
2127 if chars_per_line is right, we probably just overflowed
2128 anyway; if it's wrong, let us keep going. */
2130 fputc_unfiltered ('\n', stream
);
2132 /* Possible new page. */
2133 if (lines_printed
>= lines_per_page
- 1)
2134 prompt_for_continue ();
2136 /* Now output indentation and wrapped string */
2139 fputs_unfiltered (wrap_indent
, stream
);
2140 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
2141 fputs_unfiltered (wrap_buffer
, stream
); /* and eject it */
2142 /* FIXME, this strlen is what prevents wrap_indent from
2143 containing tabs. However, if we recurse to print it
2144 and count its chars, we risk trouble if wrap_indent is
2145 longer than (the user settable) chars_per_line.
2146 Note also that this can set chars_printed > chars_per_line
2147 if we are printing a long string. */
2148 chars_printed
= strlen (wrap_indent
)
2149 + (save_chars
- wrap_column
);
2150 wrap_pointer
= wrap_buffer
; /* Reset buffer */
2151 wrap_buffer
[0] = '\0';
2152 wrap_column
= 0; /* And disable fancy wrap */
2157 if (*lineptr
== '\n')
2160 wrap_here ((char *) 0); /* Spit out chars, cancel further wraps */
2162 fputc_unfiltered ('\n', stream
);
2169 fputs_filtered (linebuffer
, stream
)
2170 const char *linebuffer
;
2173 fputs_maybe_filtered (linebuffer
, stream
, 1);
2177 putchar_unfiltered (c
)
2184 fputs_unfiltered (buf
, gdb_stdout
);
2189 fputc_unfiltered (c
, stream
)
2197 fputs_unfiltered (buf
, stream
);
2202 fputc_filtered (c
, stream
)
2210 fputs_filtered (buf
, stream
);
2214 /* puts_debug is like fputs_unfiltered, except it prints special
2215 characters in printable fashion. */
2218 puts_debug (prefix
, string
, suffix
)
2225 /* Print prefix and suffix after each line. */
2226 static int new_line
= 1;
2227 static int return_p
= 0;
2228 static char *prev_prefix
= "";
2229 static char *prev_suffix
= "";
2231 if (*string
== '\n')
2234 /* If the prefix is changing, print the previous suffix, a new line,
2235 and the new prefix. */
2236 if ((return_p
|| (strcmp (prev_prefix
, prefix
) != 0)) && !new_line
)
2238 fputs_unfiltered (prev_suffix
, gdb_stdlog
);
2239 fputs_unfiltered ("\n", gdb_stdlog
);
2240 fputs_unfiltered (prefix
, gdb_stdlog
);
2243 /* Print prefix if we printed a newline during the previous call. */
2247 fputs_unfiltered (prefix
, gdb_stdlog
);
2250 prev_prefix
= prefix
;
2251 prev_suffix
= suffix
;
2253 /* Output characters in a printable format. */
2254 while ((ch
= *string
++) != '\0')
2260 fputc_unfiltered (ch
, gdb_stdlog
);
2263 fprintf_unfiltered (gdb_stdlog
, "\\x%02x", ch
& 0xff);
2267 fputs_unfiltered ("\\\\", gdb_stdlog
);
2270 fputs_unfiltered ("\\b", gdb_stdlog
);
2273 fputs_unfiltered ("\\f", gdb_stdlog
);
2277 fputs_unfiltered ("\\n", gdb_stdlog
);
2280 fputs_unfiltered ("\\r", gdb_stdlog
);
2283 fputs_unfiltered ("\\t", gdb_stdlog
);
2286 fputs_unfiltered ("\\v", gdb_stdlog
);
2290 return_p
= ch
== '\r';
2293 /* Print suffix if we printed a newline. */
2296 fputs_unfiltered (suffix
, gdb_stdlog
);
2297 fputs_unfiltered ("\n", gdb_stdlog
);
2302 /* Print a variable number of ARGS using format FORMAT. If this
2303 information is going to put the amount written (since the last call
2304 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
2305 call prompt_for_continue to get the users permision to continue.
2307 Unlike fprintf, this function does not return a value.
2309 We implement three variants, vfprintf (takes a vararg list and stream),
2310 fprintf (takes a stream to write on), and printf (the usual).
2312 Note also that a longjmp to top level may occur in this routine
2313 (since prompt_for_continue may do so) so this routine should not be
2314 called when cleanups are not in place. */
2317 vfprintf_maybe_filtered (stream
, format
, args
, filter
)
2324 struct cleanup
*old_cleanups
;
2326 vasprintf (&linebuffer
, format
, args
);
2327 if (linebuffer
== NULL
)
2329 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2332 old_cleanups
= make_cleanup (free
, linebuffer
);
2333 fputs_maybe_filtered (linebuffer
, stream
, filter
);
2334 do_cleanups (old_cleanups
);
2339 vfprintf_filtered (stream
, format
, args
)
2344 vfprintf_maybe_filtered (stream
, format
, args
, 1);
2348 vfprintf_unfiltered (stream
, format
, args
)
2354 struct cleanup
*old_cleanups
;
2356 vasprintf (&linebuffer
, format
, args
);
2357 if (linebuffer
== NULL
)
2359 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2362 old_cleanups
= make_cleanup (free
, linebuffer
);
2363 fputs_unfiltered (linebuffer
, stream
);
2364 do_cleanups (old_cleanups
);
2368 vprintf_filtered (format
, args
)
2372 vfprintf_maybe_filtered (gdb_stdout
, format
, args
, 1);
2376 vprintf_unfiltered (format
, args
)
2380 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2384 fprintf_filtered (GDB_FILE
* stream
, const char *format
,...)
2387 va_start (args
, format
);
2388 vfprintf_filtered (stream
, format
, args
);
2393 fprintf_unfiltered (GDB_FILE
* stream
, const char *format
,...)
2396 va_start (args
, format
);
2397 vfprintf_unfiltered (stream
, format
, args
);
2401 /* Like fprintf_filtered, but prints its result indented.
2402 Called as fprintfi_filtered (spaces, stream, format, ...); */
2405 fprintfi_filtered (int spaces
, GDB_FILE
* stream
, const char *format
,...)
2408 va_start (args
, format
);
2409 print_spaces_filtered (spaces
, stream
);
2411 vfprintf_filtered (stream
, format
, args
);
2417 printf_filtered (const char *format
,...)
2420 va_start (args
, format
);
2421 vfprintf_filtered (gdb_stdout
, format
, args
);
2427 printf_unfiltered (const char *format
,...)
2430 va_start (args
, format
);
2431 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2435 /* Like printf_filtered, but prints it's result indented.
2436 Called as printfi_filtered (spaces, format, ...); */
2439 printfi_filtered (int spaces
, const char *format
,...)
2442 va_start (args
, format
);
2443 print_spaces_filtered (spaces
, gdb_stdout
);
2444 vfprintf_filtered (gdb_stdout
, format
, args
);
2448 /* Easy -- but watch out!
2450 This routine is *not* a replacement for puts()! puts() appends a newline.
2451 This one doesn't, and had better not! */
2454 puts_filtered (string
)
2457 fputs_filtered (string
, gdb_stdout
);
2461 puts_unfiltered (string
)
2464 fputs_unfiltered (string
, gdb_stdout
);
2467 /* Return a pointer to N spaces and a null. The pointer is good
2468 until the next call to here. */
2474 static char *spaces
= 0;
2475 static int max_spaces
= -1;
2481 spaces
= (char *) xmalloc (n
+ 1);
2482 for (t
= spaces
+ n
; t
!= spaces
;)
2488 return spaces
+ max_spaces
- n
;
2491 /* Print N spaces. */
2493 print_spaces_filtered (n
, stream
)
2497 fputs_filtered (n_spaces (n
), stream
);
2500 /* C++ demangler stuff. */
2502 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
2503 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
2504 If the name is not mangled, or the language for the name is unknown, or
2505 demangling is off, the name is printed in its "raw" form. */
2508 fprintf_symbol_filtered (stream
, name
, lang
, arg_mode
)
2518 /* If user wants to see raw output, no problem. */
2521 fputs_filtered (name
, stream
);
2527 case language_cplus
:
2528 demangled
= cplus_demangle (name
, arg_mode
);
2531 demangled
= cplus_demangle (name
, arg_mode
| DMGL_JAVA
);
2533 case language_chill
:
2534 demangled
= chill_demangle (name
);
2540 fputs_filtered (demangled
? demangled
: name
, stream
);
2541 if (demangled
!= NULL
)
2549 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
2550 differences in whitespace. Returns 0 if they match, non-zero if they
2551 don't (slightly different than strcmp()'s range of return values).
2553 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
2554 This "feature" is useful when searching for matching C++ function names
2555 (such as if the user types 'break FOO', where FOO is a mangled C++
2559 strcmp_iw (string1
, string2
)
2560 const char *string1
;
2561 const char *string2
;
2563 while ((*string1
!= '\0') && (*string2
!= '\0'))
2565 while (isspace (*string1
))
2569 while (isspace (*string2
))
2573 if (*string1
!= *string2
)
2577 if (*string1
!= '\0')
2583 return (*string1
!= '\0' && *string1
!= '(') || (*string2
!= '\0');
2589 ** Answer whether string_to_compare is a full or partial match to
2590 ** template_string. The partial match must be in sequence starting
2594 subset_compare (string_to_compare
, template_string
)
2595 char *string_to_compare
;
2596 char *template_string
;
2599 if (template_string
!= (char *) NULL
&& string_to_compare
!= (char *) NULL
&&
2600 strlen (string_to_compare
) <= strlen (template_string
))
2601 match
= (strncmp (template_string
,
2603 strlen (string_to_compare
)) == 0);
2610 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2612 pagination_on_command (arg
, from_tty
)
2616 pagination_enabled
= 1;
2619 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2621 pagination_off_command (arg
, from_tty
)
2625 pagination_enabled
= 0;
2632 struct cmd_list_element
*c
;
2634 c
= add_set_cmd ("width", class_support
, var_uinteger
,
2635 (char *) &chars_per_line
,
2636 "Set number of characters gdb thinks are in a line.",
2638 add_show_from_set (c
, &showlist
);
2639 c
->function
.sfunc
= set_width_command
;
2642 (add_set_cmd ("height", class_support
,
2643 var_uinteger
, (char *) &lines_per_page
,
2644 "Set number of lines gdb thinks are in a page.", &setlist
),
2649 /* If the output is not a terminal, don't paginate it. */
2650 if (!GDB_FILE_ISATTY (gdb_stdout
))
2651 lines_per_page
= UINT_MAX
;
2653 set_width_command ((char *) NULL
, 0, c
);
2656 (add_set_cmd ("demangle", class_support
, var_boolean
,
2658 "Set demangling of encoded C++ names when displaying symbols.",
2663 (add_set_cmd ("pagination", class_support
,
2664 var_boolean
, (char *) &pagination_enabled
,
2665 "Set state of pagination.", &setlist
),
2669 add_com ("am", class_support
, pagination_on_command
,
2670 "Enable pagination");
2671 add_com ("sm", class_support
, pagination_off_command
,
2672 "Disable pagination");
2676 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
2677 (char *) &sevenbit_strings
,
2678 "Set printing of 8-bit characters in strings as \\nnn.",
2683 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
2684 (char *) &asm_demangle
,
2685 "Set demangling of C++ names in disassembly listings.",
2690 /* Machine specific function to handle SIGWINCH signal. */
2692 #ifdef SIGWINCH_HANDLER_BODY
2693 SIGWINCH_HANDLER_BODY
2696 /* Support for converting target fp numbers into host DOUBLEST format. */
2698 /* XXX - This code should really be in libiberty/floatformat.c, however
2699 configuration issues with libiberty made this very difficult to do in the
2702 #include "floatformat.h"
2703 #include <math.h> /* ldexp */
2705 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
2706 going to bother with trying to muck around with whether it is defined in
2707 a system header, what we do if not, etc. */
2708 #define FLOATFORMAT_CHAR_BIT 8
2710 static unsigned long get_field
PARAMS ((unsigned char *,
2711 enum floatformat_byteorders
,
2716 /* Extract a field which starts at START and is LEN bytes long. DATA and
2717 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2718 static unsigned long
2719 get_field (data
, order
, total_len
, start
, len
)
2720 unsigned char *data
;
2721 enum floatformat_byteorders order
;
2722 unsigned int total_len
;
2726 unsigned long result
;
2727 unsigned int cur_byte
;
2730 /* Start at the least significant part of the field. */
2731 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2732 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2733 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2735 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2736 result
= *(data
+ cur_byte
) >> (-cur_bitshift
);
2737 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2738 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2743 /* Move towards the most significant part of the field. */
2744 while (cur_bitshift
< len
)
2746 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
2747 /* This is the last byte; zero out the bits which are not part of
2750 (*(data
+ cur_byte
) & ((1 << (len
- cur_bitshift
)) - 1))
2753 result
|= *(data
+ cur_byte
) << cur_bitshift
;
2754 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2755 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2763 /* Convert from FMT to a DOUBLEST.
2764 FROM is the address of the extended float.
2765 Store the DOUBLEST in *TO. */
2768 floatformat_to_doublest (fmt
, from
, to
)
2769 const struct floatformat
*fmt
;
2773 unsigned char *ufrom
= (unsigned char *) from
;
2777 unsigned int mant_bits
, mant_off
;
2779 int special_exponent
; /* It's a NaN, denorm or zero */
2781 /* If the mantissa bits are not contiguous from one end of the
2782 mantissa to the other, we need to make a private copy of the
2783 source bytes that is in the right order since the unpacking
2784 algorithm assumes that the bits are contiguous.
2786 Swap the bytes individually rather than accessing them through
2787 "long *" since we have no guarantee that they start on a long
2788 alignment, and also sizeof(long) for the host could be different
2789 than sizeof(long) for the target. FIXME: Assumes sizeof(long)
2790 for the target is 4. */
2792 if (fmt
->byteorder
== floatformat_littlebyte_bigword
)
2794 static unsigned char *newfrom
;
2795 unsigned char *swapin
, *swapout
;
2798 longswaps
= fmt
->totalsize
/ FLOATFORMAT_CHAR_BIT
;
2801 if (newfrom
== NULL
)
2803 newfrom
= (unsigned char *) xmalloc (fmt
->totalsize
);
2808 while (longswaps
-- > 0)
2810 /* This is ugly, but efficient */
2811 *swapout
++ = swapin
[4];
2812 *swapout
++ = swapin
[5];
2813 *swapout
++ = swapin
[6];
2814 *swapout
++ = swapin
[7];
2815 *swapout
++ = swapin
[0];
2816 *swapout
++ = swapin
[1];
2817 *swapout
++ = swapin
[2];
2818 *swapout
++ = swapin
[3];
2823 exponent
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2824 fmt
->exp_start
, fmt
->exp_len
);
2825 /* Note that if exponent indicates a NaN, we can't really do anything useful
2826 (not knowing if the host has NaN's, or how to build one). So it will
2827 end up as an infinity or something close; that is OK. */
2829 mant_bits_left
= fmt
->man_len
;
2830 mant_off
= fmt
->man_start
;
2833 special_exponent
= exponent
== 0 || exponent
== fmt
->exp_nan
;
2835 /* Don't bias zero's, denorms or NaNs. */
2836 if (!special_exponent
)
2837 exponent
-= fmt
->exp_bias
;
2839 /* Build the result algebraically. Might go infinite, underflow, etc;
2842 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
2843 increment the exponent by one to account for the integer bit. */
2845 if (!special_exponent
)
2847 if (fmt
->intbit
== floatformat_intbit_no
)
2848 dto
= ldexp (1.0, exponent
);
2853 while (mant_bits_left
> 0)
2855 mant_bits
= min (mant_bits_left
, 32);
2857 mant
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2858 mant_off
, mant_bits
);
2860 dto
+= ldexp ((double) mant
, exponent
- mant_bits
);
2861 exponent
-= mant_bits
;
2862 mant_off
+= mant_bits
;
2863 mant_bits_left
-= mant_bits
;
2866 /* Negate it if negative. */
2867 if (get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1))
2872 static void put_field
PARAMS ((unsigned char *, enum floatformat_byteorders
,
2878 /* Set a field which starts at START and is LEN bytes long. DATA and
2879 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2881 put_field (data
, order
, total_len
, start
, len
, stuff_to_put
)
2882 unsigned char *data
;
2883 enum floatformat_byteorders order
;
2884 unsigned int total_len
;
2887 unsigned long stuff_to_put
;
2889 unsigned int cur_byte
;
2892 /* Start at the least significant part of the field. */
2893 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2894 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2895 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2897 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2898 *(data
+ cur_byte
) &=
2899 ~(((1 << ((start
+ len
) % FLOATFORMAT_CHAR_BIT
)) - 1) << (-cur_bitshift
));
2900 *(data
+ cur_byte
) |=
2901 (stuff_to_put
& ((1 << FLOATFORMAT_CHAR_BIT
) - 1)) << (-cur_bitshift
);
2902 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2903 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2908 /* Move towards the most significant part of the field. */
2909 while (cur_bitshift
< len
)
2911 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
2913 /* This is the last byte. */
2914 *(data
+ cur_byte
) &=
2915 ~((1 << (len
- cur_bitshift
)) - 1);
2916 *(data
+ cur_byte
) |= (stuff_to_put
>> cur_bitshift
);
2919 *(data
+ cur_byte
) = ((stuff_to_put
>> cur_bitshift
)
2920 & ((1 << FLOATFORMAT_CHAR_BIT
) - 1));
2921 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2922 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2929 #ifdef HAVE_LONG_DOUBLE
2930 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
2931 The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
2932 frexp, but operates on the long double data type. */
2934 static long double ldfrexp
PARAMS ((long double value
, int *eptr
));
2937 ldfrexp (value
, eptr
)
2944 /* Unfortunately, there are no portable functions for extracting the exponent
2945 of a long double, so we have to do it iteratively by multiplying or dividing
2946 by two until the fraction is between 0.5 and 1.0. */
2954 if (value
>= tmp
) /* Value >= 1.0 */
2955 while (value
>= tmp
)
2960 else if (value
!= 0.0l) /* Value < 1.0 and > 0.0 */
2974 #endif /* HAVE_LONG_DOUBLE */
2977 /* The converse: convert the DOUBLEST *FROM to an extended float
2978 and store where TO points. Neither FROM nor TO have any alignment
2982 floatformat_from_doublest (fmt
, from
, to
)
2983 CONST
struct floatformat
*fmt
;
2990 unsigned int mant_bits
, mant_off
;
2992 unsigned char *uto
= (unsigned char *) to
;
2994 memcpy (&dfrom
, from
, sizeof (dfrom
));
2995 memset (uto
, 0, fmt
->totalsize
/ FLOATFORMAT_CHAR_BIT
);
2997 return; /* Result is zero */
2998 if (dfrom
!= dfrom
) /* Result is NaN */
3001 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3002 fmt
->exp_len
, fmt
->exp_nan
);
3003 /* Be sure it's not infinity, but NaN value is irrel */
3004 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3009 /* If negative, set the sign bit. */
3012 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1, 1);
3016 if (dfrom
+ dfrom
== dfrom
&& dfrom
!= 0.0) /* Result is Infinity */
3018 /* Infinity exponent is same as NaN's. */
3019 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3020 fmt
->exp_len
, fmt
->exp_nan
);
3021 /* Infinity mantissa is all zeroes. */
3022 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3027 #ifdef HAVE_LONG_DOUBLE
3028 mant
= ldfrexp (dfrom
, &exponent
);
3030 mant
= frexp (dfrom
, &exponent
);
3033 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
, fmt
->exp_len
,
3034 exponent
+ fmt
->exp_bias
- 1);
3036 mant_bits_left
= fmt
->man_len
;
3037 mant_off
= fmt
->man_start
;
3038 while (mant_bits_left
> 0)
3040 unsigned long mant_long
;
3041 mant_bits
= mant_bits_left
< 32 ? mant_bits_left
: 32;
3043 mant
*= 4294967296.0;
3044 mant_long
= (unsigned long) mant
;
3047 /* If the integer bit is implicit, then we need to discard it.
3048 If we are discarding a zero, we should be (but are not) creating
3049 a denormalized number which means adjusting the exponent
3051 if (mant_bits_left
== fmt
->man_len
3052 && fmt
->intbit
== floatformat_intbit_no
)
3060 /* The bits we want are in the most significant MANT_BITS bits of
3061 mant_long. Move them to the least significant. */
3062 mant_long
>>= 32 - mant_bits
;
3065 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
,
3066 mant_off
, mant_bits
, mant_long
);
3067 mant_off
+= mant_bits
;
3068 mant_bits_left
-= mant_bits
;
3070 if (fmt
->byteorder
== floatformat_littlebyte_bigword
)
3073 unsigned char *swaplow
= uto
;
3074 unsigned char *swaphigh
= uto
+ 4;
3077 for (count
= 0; count
< 4; count
++)
3080 *swaplow
++ = *swaphigh
;
3086 /* temporary storage using circular buffer */
3092 static char buf
[NUMCELLS
][CELLSIZE
];
3093 static int cell
= 0;
3094 if (++cell
>= NUMCELLS
)
3099 /* print routines to handle variable size regs, etc.
3101 FIXME: Note that t_addr is a bfd_vma, which is currently either an
3102 unsigned long or unsigned long long, determined at configure time.
3103 If t_addr is an unsigned long long and sizeof (unsigned long long)
3104 is greater than sizeof (unsigned long), then I believe this code will
3105 probably lose, at least for little endian machines. I believe that
3106 it would also be better to eliminate the switch on the absolute size
3107 of t_addr and replace it with a sequence of if statements that compare
3108 sizeof t_addr with sizeof the various types and do the right thing,
3109 which includes knowing whether or not the host supports long long.
3114 static int thirty_two
= 32; /* eliminate warning from compiler on 32-bit systems */
3120 char *paddr_str
= get_cell ();
3121 switch (sizeof (t_addr
))
3124 sprintf (paddr_str
, "%08lx%08lx",
3125 (unsigned long) (addr
>> thirty_two
), (unsigned long) (addr
& 0xffffffff));
3128 sprintf (paddr_str
, "%08lx", (unsigned long) addr
);
3131 sprintf (paddr_str
, "%04x", (unsigned short) (addr
& 0xffff));
3134 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3143 char *preg_str
= get_cell ();
3144 switch (sizeof (t_reg
))
3147 sprintf (preg_str
, "%08lx%08lx",
3148 (unsigned long) (reg
>> thirty_two
), (unsigned long) (reg
& 0xffffffff));
3151 sprintf (preg_str
, "%08lx", (unsigned long) reg
);
3154 sprintf (preg_str
, "%04x", (unsigned short) (reg
& 0xffff));
3157 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3166 char *paddr_str
= get_cell ();
3167 switch (sizeof (t_addr
))
3171 unsigned long high
= (unsigned long) (addr
>> thirty_two
);
3173 sprintf (paddr_str
, "%lx", (unsigned long) (addr
& 0xffffffff));
3175 sprintf (paddr_str
, "%lx%08lx",
3176 high
, (unsigned long) (addr
& 0xffffffff));
3180 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3183 sprintf (paddr_str
, "%x", (unsigned short) (addr
& 0xffff));
3186 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3195 char *preg_str
= get_cell ();
3196 switch (sizeof (t_reg
))
3200 unsigned long high
= (unsigned long) (reg
>> thirty_two
);
3202 sprintf (preg_str
, "%lx", (unsigned long) (reg
& 0xffffffff));
3204 sprintf (preg_str
, "%lx%08lx",
3205 high
, (unsigned long) (reg
& 0xffffffff));
3209 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3212 sprintf (preg_str
, "%x", (unsigned short) (reg
& 0xffff));
3215 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3220 /* Helper functions for INNER_THAN */
3222 core_addr_lessthan (lhs
, rhs
)
3230 core_addr_greaterthan (lhs
, rhs
)