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' */
95 static struct cleanup
*exec_cleanup_chain
; /* cleaned up on each execution command */
97 /* Pointer to what is left to do for an execution command after the
98 target stops. Used only in asynchronous mode, by targets that
99 support async execution. The finish and until commands use it. So
100 does the target extended-remote command. */
101 struct continuation
*cmd_continuation
;
103 /* Nonzero if we have job control. */
107 /* Nonzero means a quit has been requested. */
111 /* Nonzero means quit immediately if Control-C is typed now, rather
112 than waiting until QUIT is executed. Be careful in setting this;
113 code which executes with immediate_quit set has to be very careful
114 about being able to deal with being interrupted at any time. It is
115 almost always better to use QUIT; the only exception I can think of
116 is being able to quit out of a system call (using EINTR loses if
117 the SIGINT happens between the previous QUIT and the system call).
118 To immediately quit in the case in which a SIGINT happens between
119 the previous QUIT and setting immediate_quit (desirable anytime we
120 expect to block), call QUIT after setting immediate_quit. */
124 /* Nonzero means that encoded C++ names should be printed out in their
125 C++ form rather than raw. */
129 /* Nonzero means that encoded C++ names should be printed out in their
130 C++ form even in assembler language displays. If this is set, but
131 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
133 int asm_demangle
= 0;
135 /* Nonzero means that strings with character values >0x7F should be printed
136 as octal escapes. Zero means just print the value (e.g. it's an
137 international character, and the terminal or window can cope.) */
139 int sevenbit_strings
= 0;
141 /* String to be printed before error messages, if any. */
143 char *error_pre_print
;
145 /* String to be printed before quit messages, if any. */
147 char *quit_pre_print
;
149 /* String to be printed before warning messages, if any. */
151 char *warning_pre_print
= "\nwarning: ";
153 int pagination_enabled
= 1;
156 /* Add a new cleanup to the cleanup_chain,
157 and return the previous chain pointer
158 to be passed later to do_cleanups or discard_cleanups.
159 Args are FUNCTION to clean up with, and ARG to pass to it. */
162 make_cleanup (function
, arg
)
163 void (*function
) PARAMS ((PTR
));
166 return make_my_cleanup (&cleanup_chain
, function
, arg
);
170 make_final_cleanup (function
, arg
)
171 void (*function
) PARAMS ((PTR
));
174 return make_my_cleanup (&final_cleanup_chain
, function
, arg
);
178 make_run_cleanup (function
, arg
)
179 void (*function
) PARAMS ((PTR
));
182 return make_my_cleanup (&run_cleanup_chain
, function
, arg
);
186 make_exec_cleanup (function
, arg
)
187 void (*function
) PARAMS ((PTR
));
190 return make_my_cleanup (&exec_cleanup_chain
, function
, arg
);
197 freeargv ((char**) arg
);
201 make_cleanup_freeargv (arg
)
204 return make_my_cleanup (&cleanup_chain
, do_freeargv
, arg
);
208 make_my_cleanup (pmy_chain
, function
, arg
)
209 struct cleanup
**pmy_chain
;
210 void (*function
) PARAMS ((PTR
));
213 register struct cleanup
*new
214 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
215 register struct cleanup
*old_chain
= *pmy_chain
;
217 new->next
= *pmy_chain
;
218 new->function
= function
;
225 /* Discard cleanups and do the actions they describe
226 until we get back to the point OLD_CHAIN in the cleanup_chain. */
229 do_cleanups (old_chain
)
230 register struct cleanup
*old_chain
;
232 do_my_cleanups (&cleanup_chain
, old_chain
);
236 do_final_cleanups (old_chain
)
237 register struct cleanup
*old_chain
;
239 do_my_cleanups (&final_cleanup_chain
, old_chain
);
243 do_run_cleanups (old_chain
)
244 register struct cleanup
*old_chain
;
246 do_my_cleanups (&run_cleanup_chain
, old_chain
);
250 do_exec_cleanups (old_chain
)
251 register struct cleanup
*old_chain
;
253 do_my_cleanups (&exec_cleanup_chain
, old_chain
);
257 do_my_cleanups (pmy_chain
, old_chain
)
258 register struct cleanup
**pmy_chain
;
259 register struct cleanup
*old_chain
;
261 register struct cleanup
*ptr
;
262 while ((ptr
= *pmy_chain
) != old_chain
)
264 *pmy_chain
= ptr
->next
; /* Do this first incase recursion */
265 (*ptr
->function
) (ptr
->arg
);
270 /* Discard cleanups, not doing the actions they describe,
271 until we get back to the point OLD_CHAIN in the cleanup_chain. */
274 discard_cleanups (old_chain
)
275 register struct cleanup
*old_chain
;
277 discard_my_cleanups (&cleanup_chain
, old_chain
);
281 discard_final_cleanups (old_chain
)
282 register struct cleanup
*old_chain
;
284 discard_my_cleanups (&final_cleanup_chain
, old_chain
);
288 discard_my_cleanups (pmy_chain
, old_chain
)
289 register struct cleanup
**pmy_chain
;
290 register struct cleanup
*old_chain
;
292 register struct cleanup
*ptr
;
293 while ((ptr
= *pmy_chain
) != old_chain
)
295 *pmy_chain
= ptr
->next
;
300 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
304 return save_my_cleanups (&cleanup_chain
);
308 save_final_cleanups ()
310 return save_my_cleanups (&final_cleanup_chain
);
314 save_my_cleanups (pmy_chain
)
315 struct cleanup
**pmy_chain
;
317 struct cleanup
*old_chain
= *pmy_chain
;
323 /* Restore the cleanup chain from a previously saved chain. */
325 restore_cleanups (chain
)
326 struct cleanup
*chain
;
328 restore_my_cleanups (&cleanup_chain
, chain
);
332 restore_final_cleanups (chain
)
333 struct cleanup
*chain
;
335 restore_my_cleanups (&final_cleanup_chain
, chain
);
339 restore_my_cleanups (pmy_chain
, chain
)
340 struct cleanup
**pmy_chain
;
341 struct cleanup
*chain
;
346 /* This function is useful for cleanups.
350 old_chain = make_cleanup (free_current_contents, &foo);
352 to arrange to free the object thus allocated. */
355 free_current_contents (location
)
361 /* Provide a known function that does nothing, to use as a base for
362 for a possibly long chain of cleanups. This is useful where we
363 use the cleanup chain for handling normal cleanups as well as dealing
364 with cleanups that need to be done as a result of a call to error().
365 In such cases, we may not be certain where the first cleanup is, unless
366 we have a do-nothing one to always use as the base. */
375 /* Add a continuation to the continuation list, the gloabl list
378 add_continuation (continuation_hook
, arg_list
)
379 void (*continuation_hook
) PARAMS ((struct continuation_arg
*));
380 struct continuation_arg
*arg_list
;
382 struct continuation
*continuation_ptr
;
384 continuation_ptr
= (struct continuation
*) xmalloc (sizeof (struct continuation
));
385 continuation_ptr
->continuation_hook
= continuation_hook
;
386 continuation_ptr
->arg_list
= arg_list
;
387 continuation_ptr
->next
= cmd_continuation
;
388 cmd_continuation
= continuation_ptr
;
391 /* Walk down the cmd_continuation list, and execute all the
394 do_all_continuations ()
396 struct continuation
*continuation_ptr
;
398 while (cmd_continuation
)
400 (cmd_continuation
->continuation_hook
) (cmd_continuation
->arg_list
);
401 continuation_ptr
= cmd_continuation
;
402 cmd_continuation
= continuation_ptr
->next
;
403 free (continuation_ptr
);
408 /* Print a warning message. Way to use this is to call warning_begin,
409 output the warning message (use unfiltered output to gdb_stderr),
410 ending in a newline. There is not currently a warning_end that you
411 call afterwards, but such a thing might be added if it is useful
412 for a GUI to separate warning messages from other output.
414 FIXME: Why do warnings use unfiltered output and errors filtered?
415 Is this anything other than a historical accident? */
420 target_terminal_ours ();
421 wrap_here(""); /* Force out any buffered output */
422 gdb_flush (gdb_stdout
);
423 if (warning_pre_print
)
424 fprintf_unfiltered (gdb_stderr
, warning_pre_print
);
427 /* Print a warning message.
428 The first argument STRING is the warning message, used as a fprintf string,
429 and the remaining args are passed as arguments to it.
430 The primary difference between warnings and errors is that a warning
431 does not force the return to command level. */
435 #ifdef ANSI_PROTOTYPES
436 warning (const char *string
, ...)
443 #ifdef ANSI_PROTOTYPES
444 va_start (args
, string
);
449 string
= va_arg (args
, char *);
452 (*warning_hook
) (string
, args
);
456 vfprintf_unfiltered (gdb_stderr
, string
, args
);
457 fprintf_unfiltered (gdb_stderr
, "\n");
462 /* Start the printing of an error message. Way to use this is to call
463 this, output the error message (use filtered output to gdb_stderr
464 (FIXME: Some callers, like memory_error, use gdb_stdout)), ending
465 in a newline, and then call return_to_top_level (RETURN_ERROR).
466 error() provides a convenient way to do this for the special case
467 that the error message can be formatted with a single printf call,
468 but this is more general. */
472 if (error_begin_hook
)
475 target_terminal_ours ();
476 wrap_here (""); /* Force out any buffered output */
477 gdb_flush (gdb_stdout
);
479 annotate_error_begin ();
482 fprintf_filtered (gdb_stderr
, error_pre_print
);
485 /* Print an error message and return to command level.
486 The first argument STRING is the error message, used as a fprintf string,
487 and the remaining args are passed as arguments to it. */
491 #ifdef ANSI_PROTOTYPES
492 error (const char *string
, ...)
499 #ifdef ANSI_PROTOTYPES
500 va_start (args
, string
);
509 #ifdef ANSI_PROTOTYPES
510 vfprintf_filtered (gdb_stderr
, string
, args
);
515 string1
= va_arg (args
, char *);
516 vfprintf_filtered (gdb_stderr
, string1
, args
);
519 fprintf_filtered (gdb_stderr
, "\n");
521 return_to_top_level (RETURN_ERROR
);
526 /* Print an error message and exit reporting failure.
527 This is for a error that we cannot continue from.
528 The arguments are printed a la printf.
530 This function cannot be declared volatile (NORETURN) in an
531 ANSI environment because exit() is not declared volatile. */
535 #ifdef ANSI_PROTOTYPES
536 fatal (char *string
, ...)
543 #ifdef ANSI_PROTOTYPES
544 va_start (args
, string
);
548 string
= va_arg (args
, char *);
550 fprintf_unfiltered (gdb_stderr
, "\ngdb: ");
551 vfprintf_unfiltered (gdb_stderr
, string
, args
);
552 fprintf_unfiltered (gdb_stderr
, "\n");
557 /* Print an error message and exit, dumping core.
558 The arguments are printed a la printf (). */
562 #ifdef ANSI_PROTOTYPES
563 fatal_dump_core (char *string
, ...)
565 fatal_dump_core (va_alist
)
570 #ifdef ANSI_PROTOTYPES
571 va_start (args
, string
);
576 string
= va_arg (args
, char *);
578 /* "internal error" is always correct, since GDB should never dump
579 core, no matter what the input. */
580 fprintf_unfiltered (gdb_stderr
, "\ngdb internal error: ");
581 vfprintf_unfiltered (gdb_stderr
, string
, args
);
582 fprintf_unfiltered (gdb_stderr
, "\n");
585 signal (SIGQUIT
, SIG_DFL
);
586 kill (getpid (), SIGQUIT
);
587 /* We should never get here, but just in case... */
591 /* The strerror() function can return NULL for errno values that are
592 out of range. Provide a "safe" version that always returns a
596 safe_strerror (errnum
)
602 if ((msg
= strerror (errnum
)) == NULL
)
604 sprintf (buf
, "(undocumented errno %d)", errnum
);
610 /* The strsignal() function can return NULL for signal values that are
611 out of range. Provide a "safe" version that always returns a
615 safe_strsignal (signo
)
621 if ((msg
= strsignal (signo
)) == NULL
)
623 sprintf (buf
, "(undocumented signal %d)", signo
);
630 /* Print the system error message for errno, and also mention STRING
631 as the file name for which the error was encountered.
632 Then return to command level. */
635 perror_with_name (string
)
641 err
= safe_strerror (errno
);
642 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
643 strcpy (combined
, string
);
644 strcat (combined
, ": ");
645 strcat (combined
, err
);
647 /* I understand setting these is a matter of taste. Still, some people
648 may clear errno but not know about bfd_error. Doing this here is not
650 bfd_set_error (bfd_error_no_error
);
653 error ("%s.", combined
);
656 /* Print the system error message for ERRCODE, and also mention STRING
657 as the file name for which the error was encountered. */
660 print_sys_errmsg (string
, errcode
)
667 err
= safe_strerror (errcode
);
668 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
669 strcpy (combined
, string
);
670 strcat (combined
, ": ");
671 strcat (combined
, err
);
673 /* We want anything which was printed on stdout to come out first, before
675 gdb_flush (gdb_stdout
);
676 fprintf_unfiltered (gdb_stderr
, "%s.\n", combined
);
679 /* Control C eventually causes this to be called, at a convenient time. */
684 serial_t gdb_stdout_serial
= serial_fdopen (1);
686 target_terminal_ours ();
688 /* We want all output to appear now, before we print "Quit". We
689 have 3 levels of buffering we have to flush (it's possible that
690 some of these should be changed to flush the lower-level ones
693 /* 1. The _filtered buffer. */
694 wrap_here ((char *)0);
696 /* 2. The stdio buffer. */
697 gdb_flush (gdb_stdout
);
698 gdb_flush (gdb_stderr
);
700 /* 3. The system-level buffer. */
701 SERIAL_DRAIN_OUTPUT (gdb_stdout_serial
);
702 SERIAL_UN_FDOPEN (gdb_stdout_serial
);
704 annotate_error_begin ();
706 /* Don't use *_filtered; we don't want to prompt the user to continue. */
708 fprintf_unfiltered (gdb_stderr
, quit_pre_print
);
711 /* If there is no terminal switching for this target, then we can't
712 possibly get screwed by the lack of job control. */
713 || current_target
.to_terminal_ours
== NULL
)
714 fprintf_unfiltered (gdb_stderr
, "Quit\n");
716 fprintf_unfiltered (gdb_stderr
,
717 "Quit (expect signal SIGINT when the program is resumed)\n");
718 return_to_top_level (RETURN_QUIT
);
722 #if defined(__GO32__)
724 /* In the absence of signals, poll keyboard for a quit.
725 Called from #define QUIT pollquit() in xm-go32.h. */
740 /* We just ignore it */
741 /* FIXME!! Don't think this actually works! */
742 fprintf_unfiltered (gdb_stderr
, "CTRL-A to quit, CTRL-B to quit harder\n");
747 #elif defined(_MSC_VER) /* should test for wingdb instead? */
750 * Windows translates all keyboard and mouse events
751 * into a message which is appended to the message
752 * queue for the process.
757 int k
= win32pollquit();
764 #else /* !defined(__GO32__) && !defined(_MSC_VER) */
768 /* Done by signals */
771 #endif /* !defined(__GO32__) && !defined(_MSC_VER) */
773 /* Control C comes here */
779 /* Restore the signal handler. Harmless with BSD-style signals, needed
780 for System V-style signals. So just always do it, rather than worrying
781 about USG defines and stuff like that. */
782 signal (signo
, request_quit
);
792 /* Memory management stuff (malloc friends). */
794 /* Make a substitute size_t for non-ANSI compilers. */
796 #ifndef HAVE_STDDEF_H
798 #define size_t unsigned int
802 #if !defined (USE_MMALLOC)
809 return malloc (size
);
813 mrealloc (md
, ptr
, size
)
818 if (ptr
== 0) /* Guard against old realloc's */
819 return malloc (size
);
821 return realloc (ptr
, size
);
832 #endif /* USE_MMALLOC */
834 #if !defined (USE_MMALLOC) || defined (NO_MMCHECK)
842 #else /* Have mmalloc and want corruption checking */
847 fatal_dump_core ("Memory corruption");
850 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
851 by MD, to detect memory corruption. Note that MD may be NULL to specify
852 the default heap that grows via sbrk.
854 Note that for freshly created regions, we must call mmcheckf prior to any
855 mallocs in the region. Otherwise, any region which was allocated prior to
856 installing the checking hooks, which is later reallocated or freed, will
857 fail the checks! The mmcheck function only allows initial hooks to be
858 installed before the first mmalloc. However, anytime after we have called
859 mmcheck the first time to install the checking hooks, we can call it again
860 to update the function pointer to the memory corruption handler.
862 Returns zero on failure, non-zero on success. */
864 #ifndef MMCHECK_FORCE
865 #define MMCHECK_FORCE 0
872 if (!mmcheckf (md
, malloc_botch
, MMCHECK_FORCE
))
874 /* Don't use warning(), which relies on current_target being set
875 to something other than dummy_target, until after
876 initialize_all_files(). */
879 (gdb_stderr
, "warning: failed to install memory consistency checks; ");
881 (gdb_stderr
, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
887 #endif /* Have mmalloc and want corruption checking */
889 /* Called when a memory allocation fails, with the number of bytes of
890 memory requested in SIZE. */
898 fatal ("virtual memory exhausted: can't allocate %ld bytes.", size
);
902 fatal ("virtual memory exhausted.");
906 /* Like mmalloc but get error if no storage available, and protect against
907 the caller wanting to allocate zero bytes. Whether to return NULL for
908 a zero byte request, or translate the request into a request for one
909 byte of zero'd storage, is a religious issue. */
922 else if ((val
= mmalloc (md
, size
)) == NULL
)
929 /* Like mrealloc but get error if no storage available. */
932 xmrealloc (md
, ptr
, size
)
941 val
= mrealloc (md
, ptr
, size
);
945 val
= mmalloc (md
, size
);
954 /* Like malloc but get error if no storage available, and protect against
955 the caller wanting to allocate zero bytes. */
961 return (xmmalloc ((PTR
) NULL
, size
));
964 /* Like mrealloc but get error if no storage available. */
971 return (xmrealloc ((PTR
) NULL
, ptr
, size
));
975 /* My replacement for the read system call.
976 Used like `read' but keeps going if `read' returns too soon. */
979 myread (desc
, addr
, len
)
989 val
= read (desc
, addr
, len
);
1000 /* Make a copy of the string at PTR with SIZE characters
1001 (and add a null character at the end in the copy).
1002 Uses malloc to get the space. Returns the address of the copy. */
1005 savestring (ptr
, size
)
1009 register char *p
= (char *) xmalloc (size
+ 1);
1010 memcpy (p
, ptr
, size
);
1016 msavestring (md
, ptr
, size
)
1021 register char *p
= (char *) xmmalloc (md
, size
+ 1);
1022 memcpy (p
, ptr
, size
);
1027 /* The "const" is so it compiles under DGUX (which prototypes strsave
1028 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
1029 Doesn't real strsave return NULL if out of memory? */
1034 return savestring (ptr
, strlen (ptr
));
1042 return (msavestring (md
, ptr
, strlen (ptr
)));
1046 print_spaces (n
, file
)
1048 register GDB_FILE
*file
;
1050 fputs_unfiltered (n_spaces (n
), file
);
1053 /* Print a host address. */
1056 gdb_print_address (addr
, stream
)
1061 /* We could use the %p conversion specifier to fprintf if we had any
1062 way of knowing whether this host supports it. But the following
1063 should work on the Alpha and on 32 bit machines. */
1065 fprintf_filtered (stream
, "0x%lx", (unsigned long)addr
);
1068 /* Ask user a y-or-n question and return 1 iff answer is yes.
1069 Takes three args which are given to printf to print the question.
1070 The first, a control string, should end in "? ".
1071 It should not say how to answer, because we do that. */
1075 #ifdef ANSI_PROTOTYPES
1076 query (char *ctlstr
, ...)
1083 register int answer
;
1087 #ifdef ANSI_PROTOTYPES
1088 va_start (args
, ctlstr
);
1092 ctlstr
= va_arg (args
, char *);
1097 return query_hook (ctlstr
, args
);
1100 /* Automatically answer "yes" if input is not from a terminal. */
1101 if (!input_from_terminal_p ())
1104 /* FIXME Automatically answer "yes" if called from MacGDB. */
1111 wrap_here (""); /* Flush any buffered output */
1112 gdb_flush (gdb_stdout
);
1114 if (annotation_level
> 1)
1115 printf_filtered ("\n\032\032pre-query\n");
1117 vfprintf_filtered (gdb_stdout
, ctlstr
, args
);
1118 printf_filtered ("(y or n) ");
1120 if (annotation_level
> 1)
1121 printf_filtered ("\n\032\032query\n");
1124 /* If not in MacGDB, move to a new line so the entered line doesn't
1125 have a prompt on the front of it. */
1127 fputs_unfiltered ("\n", gdb_stdout
);
1131 gdb_flush (gdb_stdout
);
1134 if (!tui_version
|| cmdWin
== tuiWinWithFocus())
1136 answer
= fgetc (stdin
);
1140 answer
= (unsigned char)tuiBufferGetc();
1143 clearerr (stdin
); /* in case of C-d */
1144 if (answer
== EOF
) /* C-d */
1149 /* Eat rest of input line, to EOF or newline */
1150 if ((answer
!= '\n') || (tui_version
&& answer
!= '\r'))
1154 if (!tui_version
|| cmdWin
== tuiWinWithFocus())
1156 ans2
= fgetc (stdin
);
1160 ans2
= (unsigned char)tuiBufferGetc();
1164 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
1165 TUIDO(((TuiOpaqueFuncPtr
)tui_vStartNewLines
, 1));
1179 printf_filtered ("Please answer y or n.\n");
1182 if (annotation_level
> 1)
1183 printf_filtered ("\n\032\032post-query\n");
1188 /* Parse a C escape sequence. STRING_PTR points to a variable
1189 containing a pointer to the string to parse. That pointer
1190 should point to the character after the \. That pointer
1191 is updated past the characters we use. The value of the
1192 escape sequence is returned.
1194 A negative value means the sequence \ newline was seen,
1195 which is supposed to be equivalent to nothing at all.
1197 If \ is followed by a null character, we return a negative
1198 value and leave the string pointer pointing at the null character.
1200 If \ is followed by 000, we return 0 and leave the string pointer
1201 after the zeros. A value of 0 does not mean end of string. */
1204 parse_escape (string_ptr
)
1207 register int c
= *(*string_ptr
)++;
1211 return 007; /* Bell (alert) char */
1214 case 'e': /* Escape character */
1232 c
= *(*string_ptr
)++;
1234 c
= parse_escape (string_ptr
);
1237 return (c
& 0200) | (c
& 037);
1248 register int i
= c
- '0';
1249 register int count
= 0;
1252 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
1270 /* Print the character C on STREAM as part of the contents of a literal
1271 string whose delimiter is QUOTER. Note that this routine should only
1272 be call for printing things which are independent of the language
1273 of the program being debugged. */
1276 gdb_printchar (c
, stream
, quoter
)
1282 c
&= 0xFF; /* Avoid sign bit follies */
1284 if ( c
< 0x20 || /* Low control chars */
1285 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
1286 (sevenbit_strings
&& c
>= 0x80)) { /* high order bit set */
1290 fputs_filtered ("\\n", stream
);
1293 fputs_filtered ("\\b", stream
);
1296 fputs_filtered ("\\t", stream
);
1299 fputs_filtered ("\\f", stream
);
1302 fputs_filtered ("\\r", stream
);
1305 fputs_filtered ("\\e", stream
);
1308 fputs_filtered ("\\a", stream
);
1311 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
1315 if (c
== '\\' || c
== quoter
)
1316 fputs_filtered ("\\", stream
);
1317 fprintf_filtered (stream
, "%c", c
);
1322 /* Number of lines per page or UINT_MAX if paging is disabled. */
1323 static unsigned int lines_per_page
;
1324 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
1325 static unsigned int chars_per_line
;
1326 /* Current count of lines printed on this page, chars on this line. */
1327 static unsigned int lines_printed
, chars_printed
;
1329 /* Buffer and start column of buffered text, for doing smarter word-
1330 wrapping. When someone calls wrap_here(), we start buffering output
1331 that comes through fputs_filtered(). If we see a newline, we just
1332 spit it out and forget about the wrap_here(). If we see another
1333 wrap_here(), we spit it out and remember the newer one. If we see
1334 the end of the line, we spit out a newline, the indent, and then
1335 the buffered output. */
1337 /* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
1338 are waiting to be output (they have already been counted in chars_printed).
1339 When wrap_buffer[0] is null, the buffer is empty. */
1340 static char *wrap_buffer
;
1342 /* Pointer in wrap_buffer to the next character to fill. */
1343 static char *wrap_pointer
;
1345 /* String to indent by if the wrap occurs. Must not be NULL if wrap_column
1347 static char *wrap_indent
;
1349 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
1350 is not in effect. */
1351 static int wrap_column
;
1354 /* Inialize the lines and chars per page */
1359 if (tui_version
&& m_winPtrNotNull(cmdWin
))
1361 lines_per_page
= cmdWin
->generic
.height
;
1362 chars_per_line
= cmdWin
->generic
.width
;
1367 /* These defaults will be used if we are unable to get the correct
1368 values from termcap. */
1369 #if defined(__GO32__)
1370 lines_per_page
= ScreenRows();
1371 chars_per_line
= ScreenCols();
1373 lines_per_page
= 24;
1374 chars_per_line
= 80;
1376 #if !defined (MPW) && !defined (_WIN32)
1377 /* No termcap under MPW, although might be cool to do something
1378 by looking at worksheet or console window sizes. */
1379 /* Initialize the screen height and width from termcap. */
1381 char *termtype
= getenv ("TERM");
1383 /* Positive means success, nonpositive means failure. */
1386 /* 2048 is large enough for all known terminals, according to the
1387 GNU termcap manual. */
1388 char term_buffer
[2048];
1392 status
= tgetent (term_buffer
, termtype
);
1396 int running_in_emacs
= getenv ("EMACS") != NULL
;
1398 val
= tgetnum ("li");
1399 if (val
>= 0 && !running_in_emacs
)
1400 lines_per_page
= val
;
1402 /* The number of lines per page is not mentioned
1403 in the terminal description. This probably means
1404 that paging is not useful (e.g. emacs shell window),
1405 so disable paging. */
1406 lines_per_page
= UINT_MAX
;
1408 val
= tgetnum ("co");
1410 chars_per_line
= val
;
1416 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1418 /* If there is a better way to determine the window size, use it. */
1419 SIGWINCH_HANDLER (SIGWINCH
);
1422 /* If the output is not a terminal, don't paginate it. */
1423 if (!GDB_FILE_ISATTY (gdb_stdout
))
1424 lines_per_page
= UINT_MAX
;
1425 } /* the command_line_version */
1432 if (chars_per_line
== 0)
1437 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
1438 wrap_buffer
[0] = '\0';
1441 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
1442 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
1447 set_width_command (args
, from_tty
, c
)
1450 struct cmd_list_element
*c
;
1455 /* Wait, so the user can read what's on the screen. Prompt the user
1456 to continue by pressing RETURN. */
1459 prompt_for_continue ()
1462 char cont_prompt
[120];
1464 if (annotation_level
> 1)
1465 printf_unfiltered ("\n\032\032pre-prompt-for-continue\n");
1467 strcpy (cont_prompt
,
1468 "---Type <return> to continue, or q <return> to quit---");
1469 if (annotation_level
> 1)
1470 strcat (cont_prompt
, "\n\032\032prompt-for-continue\n");
1472 /* We must do this *before* we call gdb_readline, else it will eventually
1473 call us -- thinking that we're trying to print beyond the end of the
1475 reinitialize_more_filter ();
1478 /* On a real operating system, the user can quit with SIGINT.
1481 'q' is provided on all systems so users don't have to change habits
1482 from system to system, and because telling them what to do in
1483 the prompt is more user-friendly than expecting them to think of
1485 /* Call readline, not gdb_readline, because GO32 readline handles control-C
1486 whereas control-C to gdb_readline will cause the user to get dumped
1488 ignore
= readline (cont_prompt
);
1490 if (annotation_level
> 1)
1491 printf_unfiltered ("\n\032\032post-prompt-for-continue\n");
1496 while (*p
== ' ' || *p
== '\t')
1501 request_quit (SIGINT
);
1503 async_request_quit (0);
1509 /* Now we have to do this again, so that GDB will know that it doesn't
1510 need to save the ---Type <return>--- line at the top of the screen. */
1511 reinitialize_more_filter ();
1513 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
1516 /* Reinitialize filter; ie. tell it to reset to original values. */
1519 reinitialize_more_filter ()
1525 /* Indicate that if the next sequence of characters overflows the line,
1526 a newline should be inserted here rather than when it hits the end.
1527 If INDENT is non-null, it is a string to be printed to indent the
1528 wrapped part on the next line. INDENT must remain accessible until
1529 the next call to wrap_here() or until a newline is printed through
1532 If the line is already overfull, we immediately print a newline and
1533 the indentation, and disable further wrapping.
1535 If we don't know the width of lines, but we know the page height,
1536 we must not wrap words, but should still keep track of newlines
1537 that were explicitly printed.
1539 INDENT should not contain tabs, as that will mess up the char count
1540 on the next line. FIXME.
1542 This routine is guaranteed to force out any output which has been
1543 squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
1544 used to force out output from the wrap_buffer. */
1550 /* This should have been allocated, but be paranoid anyway. */
1556 *wrap_pointer
= '\0';
1557 fputs_unfiltered (wrap_buffer
, gdb_stdout
);
1559 wrap_pointer
= wrap_buffer
;
1560 wrap_buffer
[0] = '\0';
1561 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
1565 else if (chars_printed
>= chars_per_line
)
1567 puts_filtered ("\n");
1569 puts_filtered (indent
);
1574 wrap_column
= chars_printed
;
1578 wrap_indent
= indent
;
1582 /* Ensure that whatever gets printed next, using the filtered output
1583 commands, starts at the beginning of the line. I.E. if there is
1584 any pending output for the current line, flush it and start a new
1585 line. Otherwise do nothing. */
1590 if (chars_printed
> 0)
1592 puts_filtered ("\n");
1597 /* ``struct gdb_file'' implementation that maps directly onto
1598 <stdio.h>'s FILE. */
1600 static gdb_file_fputs_ftype stdio_file_fputs
;
1601 static gdb_file_isatty_ftype stdio_file_isatty
;
1602 static gdb_file_delete_ftype stdio_file_delete
;
1603 static struct gdb_file
*stdio_file_new
PARAMS ((FILE *file
, int close_p
));
1604 static gdb_file_flush_ftype stdio_file_flush
;
1606 static int stdio_file_magic
;
1615 static struct gdb_file
*
1616 stdio_file_new (file
, close_p
)
1620 struct gdb_file
*gdb_file
= gdb_file_new ();
1621 struct stdio_file
*stdio
= xmalloc (sizeof (struct stdio_file
));
1622 stdio
->magic
= &stdio_file_magic
;
1624 stdio
->close_p
= close_p
;
1625 set_gdb_file_data (gdb_file
, stdio
, stdio_file_delete
);
1626 set_gdb_file_flush (gdb_file
, stdio_file_flush
);
1627 set_gdb_file_fputs (gdb_file
, stdio_file_fputs
);
1628 set_gdb_file_isatty (gdb_file
, stdio_file_isatty
);
1633 stdio_file_delete (file
)
1634 struct gdb_file
*file
;
1636 struct stdio_file
*stdio
= gdb_file_data (file
);
1637 if (stdio
->magic
!= &stdio_file_magic
)
1638 error ("Internal error: bad magic number");
1641 fclose (stdio
->file
);
1647 stdio_file_flush (file
)
1648 struct gdb_file
*file
;
1650 struct stdio_file
*stdio
= gdb_file_data (file
);
1651 if (stdio
->magic
!= &stdio_file_magic
)
1652 error ("Internal error: bad magic number");
1653 fflush (stdio
->file
);
1657 stdio_file_fputs (linebuffer
, file
)
1658 const char *linebuffer
;
1659 struct gdb_file
*file
;
1661 struct stdio_file
*stdio
= gdb_file_data (file
);
1662 if (stdio
->magic
!= &stdio_file_magic
)
1663 error ("Internal error: bad magic number");
1664 fputs (linebuffer
, stdio
->file
);
1668 stdio_file_isatty (file
)
1669 struct gdb_file
*file
;
1671 struct stdio_file
*stdio
= gdb_file_data (file
);
1672 if (stdio
->magic
!= &stdio_file_magic
)
1673 error ("Internal error: bad magic number");
1674 return (isatty (fileno (stdio
->file
)));
1677 /* Like fdopen(). Create a gdb_file from a previously opened FILE. */
1680 stdio_fileopen (file
)
1683 return stdio_file_new (file
, 0);
1687 /* A ``struct gdb_file'' that is compatible with all the legacy
1690 static gdb_file_flush_ftype tui_file_flush
;
1691 extern gdb_file_fputs_ftype tui_file_fputs
;
1692 static gdb_file_isatty_ftype tui_file_isatty
;
1693 static gdb_file_rewind_ftype tui_file_rewind
;
1694 static gdb_file_put_ftype tui_file_put
;
1695 static gdb_file_delete_ftype tui_file_delete
;
1696 static struct gdb_file
*tui_file_new
PARAMS ((void));
1697 static int tui_file_magic
;
1699 static struct gdb_file
*
1702 struct tui_stream
*tui
= xmalloc (sizeof (struct tui_stream
));
1703 struct gdb_file
*file
= gdb_file_new ();
1704 set_gdb_file_data (file
, tui
, tui_file_delete
);
1705 set_gdb_file_flush (file
, tui_file_flush
);
1706 set_gdb_file_fputs (file
, tui_file_fputs
);
1707 set_gdb_file_isatty (file
, tui_file_isatty
);
1708 set_gdb_file_rewind (file
, tui_file_rewind
);
1709 set_gdb_file_put (file
, tui_file_put
);
1710 tui
->ts_magic
= &tui_file_magic
;
1715 tui_file_delete (file
)
1716 struct gdb_file
*file
;
1718 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1719 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1720 error ("Internal error: bad magic number");
1721 if ((tmpstream
->ts_streamtype
== astring
) &&
1722 (tmpstream
->ts_strbuf
!= NULL
))
1724 free (tmpstream
->ts_strbuf
);
1730 tui_fileopen (stream
)
1733 struct gdb_file
*file
= tui_file_new ();
1734 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1735 tmpstream
->ts_streamtype
= afile
;
1736 tmpstream
->ts_filestream
= stream
;
1737 tmpstream
->ts_strbuf
= NULL
;
1738 tmpstream
->ts_buflen
= 0;
1743 tui_file_isatty (file
)
1744 struct gdb_file
*file
;
1746 struct tui_stream
*stream
= gdb_file_data (file
);
1747 if (stream
->ts_magic
!= &tui_file_magic
)
1748 error ("Internal error: bad magic number");
1749 if (stream
->ts_streamtype
== afile
)
1750 return (isatty(fileno(stream
->ts_filestream
)));
1755 tui_file_rewind (file
)
1756 struct gdb_file
*file
;
1758 struct tui_stream
*stream
= gdb_file_data (file
);
1759 if (stream
->ts_magic
!= &tui_file_magic
)
1760 error ("Internal error: bad magic number");
1761 stream
->ts_strbuf
[0] = '\0';
1765 tui_file_put (file
, dest
)
1766 struct gdb_file
*file
;
1767 struct gdb_file
*dest
;
1769 struct tui_stream
*stream
= gdb_file_data (file
);
1770 if (stream
->ts_magic
!= &tui_file_magic
)
1771 error ("Internal error: bad magic number");
1772 if (stream
->ts_streamtype
== astring
)
1774 fputs_unfiltered (stream
->ts_strbuf
, dest
);
1779 gdb_file_init_astring (n
)
1782 struct gdb_file
*file
= tui_file_new ();
1783 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1784 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1785 error ("Internal error: bad magic number");
1787 tmpstream
->ts_streamtype
= astring
;
1788 tmpstream
->ts_filestream
= NULL
;
1791 tmpstream
->ts_strbuf
= xmalloc ((n
+ 1)*sizeof(char));
1792 tmpstream
->ts_strbuf
[0] = '\0';
1795 tmpstream
->ts_strbuf
= NULL
;
1796 tmpstream
->ts_buflen
= n
;
1802 gdb_file_deallocate (streamptr
)
1803 GDB_FILE
**streamptr
;
1805 gdb_file_delete (*streamptr
);
1810 gdb_file_get_strbuf (file
)
1813 struct tui_stream
*stream
= gdb_file_data (file
);
1814 if (stream
->ts_magic
!= &tui_file_magic
)
1815 error ("Internal error: bad magic number");
1816 return (stream
->ts_strbuf
);
1819 /* adjust the length of the buffer by the amount necessary
1820 to accomodate appending a string of length N to the buffer contents */
1822 gdb_file_adjust_strbuf (n
, file
)
1826 struct tui_stream
*stream
= gdb_file_data (file
);
1828 if (stream
->ts_magic
!= &tui_file_magic
)
1829 error ("Internal error: bad magic number");
1831 if (stream
->ts_streamtype
!= astring
)
1834 if (stream
->ts_strbuf
)
1836 /* There is already a buffer allocated */
1837 non_null_chars
= strlen(stream
->ts_strbuf
);
1839 if (n
> (stream
->ts_buflen
- non_null_chars
- 1))
1841 stream
->ts_buflen
= n
+ non_null_chars
+ 1;
1842 stream
->ts_strbuf
= xrealloc (stream
->ts_strbuf
, stream
->ts_buflen
);
1846 /* No buffer yet, so allocate one of the desired size */
1847 stream
->ts_strbuf
= xmalloc ((n
+ 1) * sizeof (char));
1851 gdb_fopen (name
, mode
)
1855 FILE *f
= fopen (name
, mode
);
1858 return stdio_file_new (f
, 1);
1862 tui_file_flush (file
)
1865 struct tui_stream
*stream
= gdb_file_data (file
);
1866 if (stream
->ts_magic
!= &tui_file_magic
)
1867 error ("Internal error: bad magic number");
1869 && (file
== gdb_stdout
1870 || file
== gdb_stderr
))
1876 fflush (stream
->ts_filestream
);
1880 gdb_fclose(streamptr
)
1881 GDB_FILE
**streamptr
;
1883 gdb_file_delete (*streamptr
);
1888 /* Implement the ``struct gdb_file'' object. */
1890 static gdb_file_isatty_ftype null_file_isatty
;
1891 static gdb_file_fputs_ftype null_file_fputs
;
1892 static gdb_file_flush_ftype null_file_flush
;
1893 static gdb_file_delete_ftype null_file_delete
;
1894 static gdb_file_rewind_ftype null_file_rewind
;
1895 static gdb_file_put_ftype null_file_put
;
1899 gdb_file_flush_ftype
*to_flush
;
1900 gdb_file_fputs_ftype
*to_fputs
;
1901 gdb_file_delete_ftype
*to_delete
;
1902 gdb_file_isatty_ftype
*to_isatty
;
1903 gdb_file_rewind_ftype
*to_rewind
;
1904 gdb_file_put_ftype
*to_put
;
1911 struct gdb_file
*file
= xmalloc (sizeof (struct gdb_file
));
1912 set_gdb_file_data (file
, NULL
, null_file_delete
);
1913 set_gdb_file_flush (file
, null_file_flush
);
1914 set_gdb_file_fputs (file
, null_file_fputs
);
1915 set_gdb_file_isatty (file
, null_file_isatty
);
1916 set_gdb_file_rewind (file
, null_file_rewind
);
1917 set_gdb_file_put (file
, null_file_put
);
1922 gdb_file_delete (file
)
1923 struct gdb_file
*file
;
1925 file
->to_delete (file
);
1930 null_file_isatty (file
)
1931 struct gdb_file
*file
;
1937 null_file_rewind (file
)
1938 struct gdb_file
*file
;
1944 null_file_put (file
, src
)
1945 struct gdb_file
*file
;
1946 struct gdb_file
*src
;
1952 null_file_flush (file
)
1953 struct gdb_file
*file
;
1959 null_file_fputs (buf
, file
)
1961 struct gdb_file
*file
;
1967 null_file_delete (file
)
1968 struct gdb_file
*file
;
1974 gdb_file_data (file
)
1975 struct gdb_file
*file
;
1977 return file
->to_data
;
1982 struct gdb_file
*file
;
1984 file
->to_flush (file
);
1988 gdb_file_isatty (file
)
1989 struct gdb_file
*file
;
1991 return file
->to_isatty (file
);
1995 gdb_file_rewind (file
)
1996 struct gdb_file
*file
;
1998 file
->to_rewind (file
);
2002 gdb_file_put (file
, dest
)
2003 struct gdb_file
*file
;
2004 struct gdb_file
*dest
;
2006 file
->to_put (file
, dest
);
2010 fputs_unfiltered (buf
, file
)
2012 struct gdb_file
*file
;
2014 file
->to_fputs (buf
, file
);
2018 set_gdb_file_flush (file
, flush
)
2019 struct gdb_file
*file
;
2020 gdb_file_flush_ftype
*flush
;
2022 file
->to_flush
= flush
;
2026 set_gdb_file_isatty (file
, isatty
)
2027 struct gdb_file
*file
;
2028 gdb_file_isatty_ftype
*isatty
;
2030 file
->to_isatty
= isatty
;
2034 set_gdb_file_rewind (file
, rewind
)
2035 struct gdb_file
*file
;
2036 gdb_file_rewind_ftype
*rewind
;
2038 file
->to_rewind
= rewind
;
2042 set_gdb_file_put (file
, put
)
2043 struct gdb_file
*file
;
2044 gdb_file_put_ftype
*put
;
2050 set_gdb_file_fputs (file
, fputs
)
2051 struct gdb_file
*file
;
2052 gdb_file_fputs_ftype
*fputs
;
2054 file
->to_fputs
= fputs
;
2058 set_gdb_file_data (file
, data
, delete)
2059 struct gdb_file
*file
;
2061 gdb_file_delete_ftype
*delete;
2063 file
->to_data
= data
;
2064 file
->to_delete
= delete;
2067 /* Like fputs but if FILTER is true, pause after every screenful.
2069 Regardless of FILTER can wrap at points other than the final
2070 character of a line.
2072 Unlike fputs, fputs_maybe_filtered does not return a value.
2073 It is OK for LINEBUFFER to be NULL, in which case just don't print
2076 Note that a longjmp to top level may occur in this routine (only if
2077 FILTER is true) (since prompt_for_continue may do so) so this
2078 routine should not be called when cleanups are not in place. */
2081 fputs_maybe_filtered (linebuffer
, stream
, filter
)
2082 const char *linebuffer
;
2086 const char *lineptr
;
2088 if (linebuffer
== 0)
2091 /* Don't do any filtering if it is disabled. */
2092 if ((stream
!= gdb_stdout
) || !pagination_enabled
2093 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
2095 fputs_unfiltered (linebuffer
, stream
);
2099 /* Go through and output each character. Show line extension
2100 when this is necessary; prompt user for new page when this is
2103 lineptr
= linebuffer
;
2106 /* Possible new page. */
2108 (lines_printed
>= lines_per_page
- 1))
2109 prompt_for_continue ();
2111 while (*lineptr
&& *lineptr
!= '\n')
2113 /* Print a single line. */
2114 if (*lineptr
== '\t')
2117 *wrap_pointer
++ = '\t';
2119 fputc_unfiltered ('\t', stream
);
2120 /* Shifting right by 3 produces the number of tab stops
2121 we have already passed, and then adding one and
2122 shifting left 3 advances to the next tab stop. */
2123 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
2129 *wrap_pointer
++ = *lineptr
;
2131 fputc_unfiltered (*lineptr
, stream
);
2136 if (chars_printed
>= chars_per_line
)
2138 unsigned int save_chars
= chars_printed
;
2142 /* If we aren't actually wrapping, don't output newline --
2143 if chars_per_line is right, we probably just overflowed
2144 anyway; if it's wrong, let us keep going. */
2146 fputc_unfiltered ('\n', stream
);
2148 /* Possible new page. */
2149 if (lines_printed
>= lines_per_page
- 1)
2150 prompt_for_continue ();
2152 /* Now output indentation and wrapped string */
2155 fputs_unfiltered (wrap_indent
, stream
);
2156 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
2157 fputs_unfiltered (wrap_buffer
, stream
); /* and eject it */
2158 /* FIXME, this strlen is what prevents wrap_indent from
2159 containing tabs. However, if we recurse to print it
2160 and count its chars, we risk trouble if wrap_indent is
2161 longer than (the user settable) chars_per_line.
2162 Note also that this can set chars_printed > chars_per_line
2163 if we are printing a long string. */
2164 chars_printed
= strlen (wrap_indent
)
2165 + (save_chars
- wrap_column
);
2166 wrap_pointer
= wrap_buffer
; /* Reset buffer */
2167 wrap_buffer
[0] = '\0';
2168 wrap_column
= 0; /* And disable fancy wrap */
2173 if (*lineptr
== '\n')
2176 wrap_here ((char *)0); /* Spit out chars, cancel further wraps */
2178 fputc_unfiltered ('\n', stream
);
2185 fputs_filtered (linebuffer
, stream
)
2186 const char *linebuffer
;
2189 fputs_maybe_filtered (linebuffer
, stream
, 1);
2193 putchar_unfiltered (c
)
2200 fputs_unfiltered (buf
, gdb_stdout
);
2205 fputc_unfiltered (c
, stream
)
2213 fputs_unfiltered (buf
, stream
);
2218 fputc_filtered (c
, stream
)
2226 fputs_filtered (buf
, stream
);
2230 /* puts_debug is like fputs_unfiltered, except it prints special
2231 characters in printable fashion. */
2234 puts_debug (prefix
, string
, suffix
)
2241 /* Print prefix and suffix after each line. */
2242 static int new_line
= 1;
2243 static int return_p
= 0;
2244 static char *prev_prefix
= "";
2245 static char *prev_suffix
= "";
2247 if (*string
== '\n')
2250 /* If the prefix is changing, print the previous suffix, a new line,
2251 and the new prefix. */
2252 if ((return_p
|| (strcmp(prev_prefix
, prefix
) != 0)) && !new_line
)
2254 fputs_unfiltered (prev_suffix
, gdb_stdlog
);
2255 fputs_unfiltered ("\n", gdb_stdlog
);
2256 fputs_unfiltered (prefix
, gdb_stdlog
);
2259 /* Print prefix if we printed a newline during the previous call. */
2263 fputs_unfiltered (prefix
, gdb_stdlog
);
2266 prev_prefix
= prefix
;
2267 prev_suffix
= suffix
;
2269 /* Output characters in a printable format. */
2270 while ((ch
= *string
++) != '\0')
2276 fputc_unfiltered (ch
, gdb_stdlog
);
2279 fprintf_unfiltered (gdb_stdlog
, "\\x%02x", ch
& 0xff);
2282 case '\\': fputs_unfiltered ("\\\\", gdb_stdlog
); break;
2283 case '\b': fputs_unfiltered ("\\b", gdb_stdlog
); break;
2284 case '\f': fputs_unfiltered ("\\f", gdb_stdlog
); break;
2285 case '\n': new_line
= 1;
2286 fputs_unfiltered ("\\n", gdb_stdlog
); break;
2287 case '\r': fputs_unfiltered ("\\r", gdb_stdlog
); break;
2288 case '\t': fputs_unfiltered ("\\t", gdb_stdlog
); break;
2289 case '\v': fputs_unfiltered ("\\v", gdb_stdlog
); break;
2292 return_p
= ch
== '\r';
2295 /* Print suffix if we printed a newline. */
2298 fputs_unfiltered (suffix
, gdb_stdlog
);
2299 fputs_unfiltered ("\n", gdb_stdlog
);
2304 /* Print a variable number of ARGS using format FORMAT. If this
2305 information is going to put the amount written (since the last call
2306 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
2307 call prompt_for_continue to get the users permision to continue.
2309 Unlike fprintf, this function does not return a value.
2311 We implement three variants, vfprintf (takes a vararg list and stream),
2312 fprintf (takes a stream to write on), and printf (the usual).
2314 Note also that a longjmp to top level may occur in this routine
2315 (since prompt_for_continue may do so) so this routine should not be
2316 called when cleanups are not in place. */
2319 vfprintf_maybe_filtered (stream
, format
, args
, filter
)
2326 struct cleanup
*old_cleanups
;
2328 vasprintf (&linebuffer
, format
, args
);
2329 if (linebuffer
== NULL
)
2331 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2334 old_cleanups
= make_cleanup (free
, linebuffer
);
2335 fputs_maybe_filtered (linebuffer
, stream
, filter
);
2336 do_cleanups (old_cleanups
);
2341 vfprintf_filtered (stream
, format
, args
)
2346 vfprintf_maybe_filtered (stream
, format
, args
, 1);
2350 vfprintf_unfiltered (stream
, format
, args
)
2356 struct cleanup
*old_cleanups
;
2358 vasprintf (&linebuffer
, format
, args
);
2359 if (linebuffer
== NULL
)
2361 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2364 old_cleanups
= make_cleanup (free
, linebuffer
);
2365 fputs_unfiltered (linebuffer
, stream
);
2366 do_cleanups (old_cleanups
);
2370 vprintf_filtered (format
, args
)
2374 vfprintf_maybe_filtered (gdb_stdout
, format
, args
, 1);
2378 vprintf_unfiltered (format
, args
)
2382 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2387 #ifdef ANSI_PROTOTYPES
2388 fprintf_filtered (GDB_FILE
*stream
, const char *format
, ...)
2390 fprintf_filtered (va_alist
)
2395 #ifdef ANSI_PROTOTYPES
2396 va_start (args
, format
);
2402 stream
= va_arg (args
, GDB_FILE
*);
2403 format
= va_arg (args
, char *);
2405 vfprintf_filtered (stream
, format
, args
);
2411 #ifdef ANSI_PROTOTYPES
2412 fprintf_unfiltered (GDB_FILE
*stream
, const char *format
, ...)
2414 fprintf_unfiltered (va_alist
)
2419 #ifdef ANSI_PROTOTYPES
2420 va_start (args
, format
);
2426 stream
= va_arg (args
, GDB_FILE
*);
2427 format
= va_arg (args
, char *);
2429 vfprintf_unfiltered (stream
, format
, args
);
2433 /* Like fprintf_filtered, but prints its result indented.
2434 Called as fprintfi_filtered (spaces, stream, format, ...); */
2438 #ifdef ANSI_PROTOTYPES
2439 fprintfi_filtered (int spaces
, GDB_FILE
*stream
, const char *format
, ...)
2441 fprintfi_filtered (va_alist
)
2446 #ifdef ANSI_PROTOTYPES
2447 va_start (args
, format
);
2454 spaces
= va_arg (args
, int);
2455 stream
= va_arg (args
, GDB_FILE
*);
2456 format
= va_arg (args
, char *);
2458 print_spaces_filtered (spaces
, stream
);
2460 vfprintf_filtered (stream
, format
, args
);
2467 #ifdef ANSI_PROTOTYPES
2468 printf_filtered (const char *format
, ...)
2470 printf_filtered (va_alist
)
2475 #ifdef ANSI_PROTOTYPES
2476 va_start (args
, format
);
2481 format
= va_arg (args
, char *);
2483 vfprintf_filtered (gdb_stdout
, format
, args
);
2490 #ifdef ANSI_PROTOTYPES
2491 printf_unfiltered (const char *format
, ...)
2493 printf_unfiltered (va_alist
)
2498 #ifdef ANSI_PROTOTYPES
2499 va_start (args
, format
);
2504 format
= va_arg (args
, char *);
2506 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2510 /* Like printf_filtered, but prints it's result indented.
2511 Called as printfi_filtered (spaces, format, ...); */
2515 #ifdef ANSI_PROTOTYPES
2516 printfi_filtered (int spaces
, const char *format
, ...)
2518 printfi_filtered (va_alist
)
2523 #ifdef ANSI_PROTOTYPES
2524 va_start (args
, format
);
2530 spaces
= va_arg (args
, int);
2531 format
= va_arg (args
, char *);
2533 print_spaces_filtered (spaces
, gdb_stdout
);
2534 vfprintf_filtered (gdb_stdout
, format
, args
);
2538 /* Easy -- but watch out!
2540 This routine is *not* a replacement for puts()! puts() appends a newline.
2541 This one doesn't, and had better not! */
2544 puts_filtered (string
)
2547 fputs_filtered (string
, gdb_stdout
);
2551 puts_unfiltered (string
)
2554 fputs_unfiltered (string
, gdb_stdout
);
2557 /* Return a pointer to N spaces and a null. The pointer is good
2558 until the next call to here. */
2564 static char *spaces
= 0;
2565 static int max_spaces
= -1;
2571 spaces
= (char *) xmalloc (n
+1);
2572 for (t
= spaces
+n
; t
!= spaces
;)
2578 return spaces
+ max_spaces
- n
;
2581 /* Print N spaces. */
2583 print_spaces_filtered (n
, stream
)
2587 fputs_filtered (n_spaces (n
), stream
);
2590 /* C++ demangler stuff. */
2592 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
2593 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
2594 If the name is not mangled, or the language for the name is unknown, or
2595 demangling is off, the name is printed in its "raw" form. */
2598 fprintf_symbol_filtered (stream
, name
, lang
, arg_mode
)
2608 /* If user wants to see raw output, no problem. */
2611 fputs_filtered (name
, stream
);
2617 case language_cplus
:
2618 demangled
= cplus_demangle (name
, arg_mode
);
2621 demangled
= cplus_demangle (name
, arg_mode
| DMGL_JAVA
);
2623 case language_chill
:
2624 demangled
= chill_demangle (name
);
2630 fputs_filtered (demangled
? demangled
: name
, stream
);
2631 if (demangled
!= NULL
)
2639 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
2640 differences in whitespace. Returns 0 if they match, non-zero if they
2641 don't (slightly different than strcmp()'s range of return values).
2643 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
2644 This "feature" is useful when searching for matching C++ function names
2645 (such as if the user types 'break FOO', where FOO is a mangled C++
2649 strcmp_iw (string1
, string2
)
2650 const char *string1
;
2651 const char *string2
;
2653 while ((*string1
!= '\0') && (*string2
!= '\0'))
2655 while (isspace (*string1
))
2659 while (isspace (*string2
))
2663 if (*string1
!= *string2
)
2667 if (*string1
!= '\0')
2673 return (*string1
!= '\0' && *string1
!= '(') || (*string2
!= '\0');
2679 ** Answer whether string_to_compare is a full or partial match to
2680 ** template_string. The partial match must be in sequence starting
2684 subset_compare (string_to_compare
, template_string
)
2685 char *string_to_compare
;
2686 char *template_string
;
2689 if (template_string
!= (char *)NULL
&& string_to_compare
!= (char *)NULL
&&
2690 strlen(string_to_compare
) <= strlen(template_string
))
2691 match
= (strncmp(template_string
,
2693 strlen(string_to_compare
)) == 0);
2700 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2702 pagination_on_command (arg
, from_tty
)
2706 pagination_enabled
= 1;
2709 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2711 pagination_off_command (arg
, from_tty
)
2715 pagination_enabled
= 0;
2722 struct cmd_list_element
*c
;
2724 c
= add_set_cmd ("width", class_support
, var_uinteger
,
2725 (char *)&chars_per_line
,
2726 "Set number of characters gdb thinks are in a line.",
2728 add_show_from_set (c
, &showlist
);
2729 c
->function
.sfunc
= set_width_command
;
2732 (add_set_cmd ("height", class_support
,
2733 var_uinteger
, (char *)&lines_per_page
,
2734 "Set number of lines gdb thinks are in a page.", &setlist
),
2739 /* If the output is not a terminal, don't paginate it. */
2740 if (!GDB_FILE_ISATTY (gdb_stdout
))
2741 lines_per_page
= UINT_MAX
;
2743 set_width_command ((char *)NULL
, 0, c
);
2746 (add_set_cmd ("demangle", class_support
, var_boolean
,
2748 "Set demangling of encoded C++ names when displaying symbols.",
2753 (add_set_cmd ("pagination", class_support
,
2754 var_boolean
, (char *)&pagination_enabled
,
2755 "Set state of pagination.", &setlist
),
2759 add_com("am", class_support
, pagination_on_command
,
2760 "Enable pagination");
2761 add_com("sm", class_support
, pagination_off_command
,
2762 "Disable pagination");
2766 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
2767 (char *)&sevenbit_strings
,
2768 "Set printing of 8-bit characters in strings as \\nnn.",
2773 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
2774 (char *)&asm_demangle
,
2775 "Set demangling of C++ names in disassembly listings.",
2780 /* Machine specific function to handle SIGWINCH signal. */
2782 #ifdef SIGWINCH_HANDLER_BODY
2783 SIGWINCH_HANDLER_BODY
2786 /* Support for converting target fp numbers into host DOUBLEST format. */
2788 /* XXX - This code should really be in libiberty/floatformat.c, however
2789 configuration issues with libiberty made this very difficult to do in the
2792 #include "floatformat.h"
2793 #include <math.h> /* ldexp */
2795 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
2796 going to bother with trying to muck around with whether it is defined in
2797 a system header, what we do if not, etc. */
2798 #define FLOATFORMAT_CHAR_BIT 8
2800 static unsigned long get_field
PARAMS ((unsigned char *,
2801 enum floatformat_byteorders
,
2806 /* Extract a field which starts at START and is LEN bytes long. DATA and
2807 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2808 static unsigned long
2809 get_field (data
, order
, total_len
, start
, len
)
2810 unsigned char *data
;
2811 enum floatformat_byteorders order
;
2812 unsigned int total_len
;
2816 unsigned long result
;
2817 unsigned int cur_byte
;
2820 /* Start at the least significant part of the field. */
2821 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2822 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2823 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2825 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2826 result
= *(data
+ cur_byte
) >> (-cur_bitshift
);
2827 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2828 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2833 /* Move towards the most significant part of the field. */
2834 while (cur_bitshift
< len
)
2836 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
2837 /* This is the last byte; zero out the bits which are not part of
2840 (*(data
+ cur_byte
) & ((1 << (len
- cur_bitshift
)) - 1))
2843 result
|= *(data
+ cur_byte
) << cur_bitshift
;
2844 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2845 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2853 /* Convert from FMT to a DOUBLEST.
2854 FROM is the address of the extended float.
2855 Store the DOUBLEST in *TO. */
2858 floatformat_to_doublest (fmt
, from
, to
)
2859 const struct floatformat
*fmt
;
2863 unsigned char *ufrom
= (unsigned char *)from
;
2867 unsigned int mant_bits
, mant_off
;
2869 int special_exponent
; /* It's a NaN, denorm or zero */
2871 /* If the mantissa bits are not contiguous from one end of the
2872 mantissa to the other, we need to make a private copy of the
2873 source bytes that is in the right order since the unpacking
2874 algorithm assumes that the bits are contiguous.
2876 Swap the bytes individually rather than accessing them through
2877 "long *" since we have no guarantee that they start on a long
2878 alignment, and also sizeof(long) for the host could be different
2879 than sizeof(long) for the target. FIXME: Assumes sizeof(long)
2880 for the target is 4. */
2882 if (fmt
-> byteorder
== floatformat_littlebyte_bigword
)
2884 static unsigned char *newfrom
;
2885 unsigned char *swapin
, *swapout
;
2888 longswaps
= fmt
-> totalsize
/ FLOATFORMAT_CHAR_BIT
;
2891 if (newfrom
== NULL
)
2893 newfrom
= (unsigned char *) xmalloc (fmt
-> totalsize
);
2898 while (longswaps
-- > 0)
2900 /* This is ugly, but efficient */
2901 *swapout
++ = swapin
[4];
2902 *swapout
++ = swapin
[5];
2903 *swapout
++ = swapin
[6];
2904 *swapout
++ = swapin
[7];
2905 *swapout
++ = swapin
[0];
2906 *swapout
++ = swapin
[1];
2907 *swapout
++ = swapin
[2];
2908 *swapout
++ = swapin
[3];
2913 exponent
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2914 fmt
->exp_start
, fmt
->exp_len
);
2915 /* Note that if exponent indicates a NaN, we can't really do anything useful
2916 (not knowing if the host has NaN's, or how to build one). So it will
2917 end up as an infinity or something close; that is OK. */
2919 mant_bits_left
= fmt
->man_len
;
2920 mant_off
= fmt
->man_start
;
2923 special_exponent
= exponent
== 0 || exponent
== fmt
->exp_nan
;
2925 /* Don't bias zero's, denorms or NaNs. */
2926 if (!special_exponent
)
2927 exponent
-= fmt
->exp_bias
;
2929 /* Build the result algebraically. Might go infinite, underflow, etc;
2932 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
2933 increment the exponent by one to account for the integer bit. */
2935 if (!special_exponent
)
2937 if (fmt
->intbit
== floatformat_intbit_no
)
2938 dto
= ldexp (1.0, exponent
);
2943 while (mant_bits_left
> 0)
2945 mant_bits
= min (mant_bits_left
, 32);
2947 mant
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2948 mant_off
, mant_bits
);
2950 dto
+= ldexp ((double)mant
, exponent
- mant_bits
);
2951 exponent
-= mant_bits
;
2952 mant_off
+= mant_bits
;
2953 mant_bits_left
-= mant_bits
;
2956 /* Negate it if negative. */
2957 if (get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1))
2962 static void put_field
PARAMS ((unsigned char *, enum floatformat_byteorders
,
2968 /* Set a field which starts at START and is LEN bytes long. DATA and
2969 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2971 put_field (data
, order
, total_len
, start
, len
, stuff_to_put
)
2972 unsigned char *data
;
2973 enum floatformat_byteorders order
;
2974 unsigned int total_len
;
2977 unsigned long stuff_to_put
;
2979 unsigned int cur_byte
;
2982 /* Start at the least significant part of the field. */
2983 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2984 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2985 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2987 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2988 *(data
+ cur_byte
) &=
2989 ~(((1 << ((start
+ len
) % FLOATFORMAT_CHAR_BIT
)) - 1) << (-cur_bitshift
));
2990 *(data
+ cur_byte
) |=
2991 (stuff_to_put
& ((1 << FLOATFORMAT_CHAR_BIT
) - 1)) << (-cur_bitshift
);
2992 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2993 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2998 /* Move towards the most significant part of the field. */
2999 while (cur_bitshift
< len
)
3001 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
3003 /* This is the last byte. */
3004 *(data
+ cur_byte
) &=
3005 ~((1 << (len
- cur_bitshift
)) - 1);
3006 *(data
+ cur_byte
) |= (stuff_to_put
>> cur_bitshift
);
3009 *(data
+ cur_byte
) = ((stuff_to_put
>> cur_bitshift
)
3010 & ((1 << FLOATFORMAT_CHAR_BIT
) - 1));
3011 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
3012 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
3019 #ifdef HAVE_LONG_DOUBLE
3020 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
3021 The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
3022 frexp, but operates on the long double data type. */
3024 static long double ldfrexp
PARAMS ((long double value
, int *eptr
));
3027 ldfrexp (value
, eptr
)
3034 /* Unfortunately, there are no portable functions for extracting the exponent
3035 of a long double, so we have to do it iteratively by multiplying or dividing
3036 by two until the fraction is between 0.5 and 1.0. */
3044 if (value
>= tmp
) /* Value >= 1.0 */
3045 while (value
>= tmp
)
3050 else if (value
!= 0.0l) /* Value < 1.0 and > 0.0 */
3064 #endif /* HAVE_LONG_DOUBLE */
3067 /* The converse: convert the DOUBLEST *FROM to an extended float
3068 and store where TO points. Neither FROM nor TO have any alignment
3072 floatformat_from_doublest (fmt
, from
, to
)
3073 CONST
struct floatformat
*fmt
;
3080 unsigned int mant_bits
, mant_off
;
3082 unsigned char *uto
= (unsigned char *)to
;
3084 memcpy (&dfrom
, from
, sizeof (dfrom
));
3085 memset (uto
, 0, fmt
->totalsize
/ FLOATFORMAT_CHAR_BIT
);
3087 return; /* Result is zero */
3088 if (dfrom
!= dfrom
) /* Result is NaN */
3091 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3092 fmt
->exp_len
, fmt
->exp_nan
);
3093 /* Be sure it's not infinity, but NaN value is irrel */
3094 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3099 /* If negative, set the sign bit. */
3102 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1, 1);
3106 if (dfrom
+ dfrom
== dfrom
&& dfrom
!= 0.0) /* Result is Infinity */
3108 /* Infinity exponent is same as NaN's. */
3109 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3110 fmt
->exp_len
, fmt
->exp_nan
);
3111 /* Infinity mantissa is all zeroes. */
3112 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3117 #ifdef HAVE_LONG_DOUBLE
3118 mant
= ldfrexp (dfrom
, &exponent
);
3120 mant
= frexp (dfrom
, &exponent
);
3123 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
, fmt
->exp_len
,
3124 exponent
+ fmt
->exp_bias
- 1);
3126 mant_bits_left
= fmt
->man_len
;
3127 mant_off
= fmt
->man_start
;
3128 while (mant_bits_left
> 0)
3130 unsigned long mant_long
;
3131 mant_bits
= mant_bits_left
< 32 ? mant_bits_left
: 32;
3133 mant
*= 4294967296.0;
3134 mant_long
= (unsigned long)mant
;
3137 /* If the integer bit is implicit, then we need to discard it.
3138 If we are discarding a zero, we should be (but are not) creating
3139 a denormalized number which means adjusting the exponent
3141 if (mant_bits_left
== fmt
->man_len
3142 && fmt
->intbit
== floatformat_intbit_no
)
3150 /* The bits we want are in the most significant MANT_BITS bits of
3151 mant_long. Move them to the least significant. */
3152 mant_long
>>= 32 - mant_bits
;
3155 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
,
3156 mant_off
, mant_bits
, mant_long
);
3157 mant_off
+= mant_bits
;
3158 mant_bits_left
-= mant_bits
;
3160 if (fmt
-> byteorder
== floatformat_littlebyte_bigword
)
3163 unsigned char *swaplow
= uto
;
3164 unsigned char *swaphigh
= uto
+ 4;
3167 for (count
= 0; count
< 4; count
++)
3170 *swaplow
++ = *swaphigh
;
3176 /* temporary storage using circular buffer */
3182 static char buf
[NUMCELLS
][CELLSIZE
];
3184 if (++cell
>=NUMCELLS
) cell
=0;
3188 /* print routines to handle variable size regs, etc.
3190 FIXME: Note that t_addr is a bfd_vma, which is currently either an
3191 unsigned long or unsigned long long, determined at configure time.
3192 If t_addr is an unsigned long long and sizeof (unsigned long long)
3193 is greater than sizeof (unsigned long), then I believe this code will
3194 probably lose, at least for little endian machines. I believe that
3195 it would also be better to eliminate the switch on the absolute size
3196 of t_addr and replace it with a sequence of if statements that compare
3197 sizeof t_addr with sizeof the various types and do the right thing,
3198 which includes knowing whether or not the host supports long long.
3203 static int thirty_two
= 32; /* eliminate warning from compiler on 32-bit systems */
3209 char *paddr_str
=get_cell();
3210 switch (sizeof(t_addr
))
3213 sprintf (paddr_str
, "%08lx%08lx",
3214 (unsigned long) (addr
>> thirty_two
), (unsigned long) (addr
& 0xffffffff));
3217 sprintf (paddr_str
, "%08lx", (unsigned long) addr
);
3220 sprintf (paddr_str
, "%04x", (unsigned short) (addr
& 0xffff));
3223 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3232 char *preg_str
=get_cell();
3233 switch (sizeof(t_reg
))
3236 sprintf (preg_str
, "%08lx%08lx",
3237 (unsigned long) (reg
>> thirty_two
), (unsigned long) (reg
& 0xffffffff));
3240 sprintf (preg_str
, "%08lx", (unsigned long) reg
);
3243 sprintf (preg_str
, "%04x", (unsigned short) (reg
& 0xffff));
3246 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3255 char *paddr_str
=get_cell();
3256 switch (sizeof(t_addr
))
3260 unsigned long high
= (unsigned long) (addr
>> thirty_two
);
3262 sprintf (paddr_str
, "%lx", (unsigned long) (addr
& 0xffffffff));
3264 sprintf (paddr_str
, "%lx%08lx",
3265 high
, (unsigned long) (addr
& 0xffffffff));
3269 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3272 sprintf (paddr_str
, "%x", (unsigned short) (addr
& 0xffff));
3275 sprintf (paddr_str
,"%lx", (unsigned long) addr
);
3284 char *preg_str
=get_cell();
3285 switch (sizeof(t_reg
))
3289 unsigned long high
= (unsigned long) (reg
>> thirty_two
);
3291 sprintf (preg_str
, "%lx", (unsigned long) (reg
& 0xffffffff));
3293 sprintf (preg_str
, "%lx%08lx",
3294 high
, (unsigned long) (reg
& 0xffffffff));
3298 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3301 sprintf (preg_str
, "%x", (unsigned short) (reg
& 0xffff));
3304 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3309 /* Helper functions for INNER_THAN */
3311 core_addr_lessthan (lhs
, rhs
)
3319 core_addr_greaterthan (lhs
, rhs
)