1 /* General utility routines for GDB, the GNU debugger.
2 Copyright 1986, 89, 90, 91, 92, 95, 96, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
24 #include "event-loop.h"
25 #include "event-top.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 prompt_for_continue
PARAMS ((void));
71 set_width_command
PARAMS ((char *, int, struct cmd_list_element
*));
74 set_width
PARAMS ((void));
76 #ifndef GDB_FILE_ISATTY
77 #define GDB_FILE_ISATTY(GDB_FILE_PTR) (gdb_file_isatty(GDB_FILE_PTR))
80 /* Chain of cleanup actions established with make_cleanup,
81 to be executed if an error happens. */
83 static struct cleanup
*cleanup_chain
; /* cleaned up after a failed command */
84 static struct cleanup
*final_cleanup_chain
; /* cleaned up when gdb exits */
85 static struct cleanup
*run_cleanup_chain
; /* cleaned up on each 'run' */
86 static struct cleanup
*exec_cleanup_chain
; /* cleaned up on each execution command */
87 /* cleaned up on each error from within an execution command */
88 static struct cleanup
*exec_error_cleanup_chain
;
90 /* Pointer to what is left to do for an execution command after the
91 target stops. Used only in asynchronous mode, by targets that
92 support async execution. The finish and until commands use it. So
93 does the target extended-remote command. */
94 struct continuation
*cmd_continuation
;
96 /* Nonzero if we have job control. */
100 /* Nonzero means a quit has been requested. */
104 /* Nonzero means quit immediately if Control-C is typed now, rather
105 than waiting until QUIT is executed. Be careful in setting this;
106 code which executes with immediate_quit set has to be very careful
107 about being able to deal with being interrupted at any time. It is
108 almost always better to use QUIT; the only exception I can think of
109 is being able to quit out of a system call (using EINTR loses if
110 the SIGINT happens between the previous QUIT and the system call).
111 To immediately quit in the case in which a SIGINT happens between
112 the previous QUIT and setting immediate_quit (desirable anytime we
113 expect to block), call QUIT after setting immediate_quit. */
117 /* Nonzero means that encoded C++ names should be printed out in their
118 C++ form rather than raw. */
122 /* Nonzero means that encoded C++ names should be printed out in their
123 C++ form even in assembler language displays. If this is set, but
124 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
126 int asm_demangle
= 0;
128 /* Nonzero means that strings with character values >0x7F should be printed
129 as octal escapes. Zero means just print the value (e.g. it's an
130 international character, and the terminal or window can cope.) */
132 int sevenbit_strings
= 0;
134 /* String to be printed before error messages, if any. */
136 char *error_pre_print
;
138 /* String to be printed before quit messages, if any. */
140 char *quit_pre_print
;
142 /* String to be printed before warning messages, if any. */
144 char *warning_pre_print
= "\nwarning: ";
146 int pagination_enabled
= 1;
149 /* Add a new cleanup to the cleanup_chain,
150 and return the previous chain pointer
151 to be passed later to do_cleanups or discard_cleanups.
152 Args are FUNCTION to clean up with, and ARG to pass to it. */
155 make_cleanup (function
, arg
)
156 void (*function
) PARAMS ((PTR
));
159 return make_my_cleanup (&cleanup_chain
, function
, arg
);
163 make_final_cleanup (function
, arg
)
164 void (*function
) PARAMS ((PTR
));
167 return make_my_cleanup (&final_cleanup_chain
, function
, arg
);
171 make_run_cleanup (function
, arg
)
172 void (*function
) PARAMS ((PTR
));
175 return make_my_cleanup (&run_cleanup_chain
, function
, arg
);
179 make_exec_cleanup (function
, arg
)
180 void (*function
) PARAMS ((PTR
));
183 return make_my_cleanup (&exec_cleanup_chain
, function
, arg
);
187 make_exec_error_cleanup (function
, arg
)
188 void (*function
) PARAMS ((PTR
));
191 return make_my_cleanup (&exec_error_cleanup_chain
, function
, arg
);
198 freeargv ((char **) arg
);
202 make_cleanup_freeargv (arg
)
205 return make_my_cleanup (&cleanup_chain
, do_freeargv
, arg
);
209 make_my_cleanup (pmy_chain
, function
, arg
)
210 struct cleanup
**pmy_chain
;
211 void (*function
) PARAMS ((PTR
));
214 register struct cleanup
*new
215 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
216 register struct cleanup
*old_chain
= *pmy_chain
;
218 new->next
= *pmy_chain
;
219 new->function
= function
;
226 /* Discard cleanups and do the actions they describe
227 until we get back to the point OLD_CHAIN in the cleanup_chain. */
230 do_cleanups (old_chain
)
231 register struct cleanup
*old_chain
;
233 do_my_cleanups (&cleanup_chain
, old_chain
);
237 do_final_cleanups (old_chain
)
238 register struct cleanup
*old_chain
;
240 do_my_cleanups (&final_cleanup_chain
, old_chain
);
244 do_run_cleanups (old_chain
)
245 register struct cleanup
*old_chain
;
247 do_my_cleanups (&run_cleanup_chain
, old_chain
);
251 do_exec_cleanups (old_chain
)
252 register struct cleanup
*old_chain
;
254 do_my_cleanups (&exec_cleanup_chain
, old_chain
);
258 do_exec_error_cleanups (old_chain
)
259 register struct cleanup
*old_chain
;
261 do_my_cleanups (&exec_error_cleanup_chain
, old_chain
);
265 do_my_cleanups (pmy_chain
, old_chain
)
266 register struct cleanup
**pmy_chain
;
267 register struct cleanup
*old_chain
;
269 register struct cleanup
*ptr
;
270 while ((ptr
= *pmy_chain
) != old_chain
)
272 *pmy_chain
= ptr
->next
; /* Do this first incase recursion */
273 (*ptr
->function
) (ptr
->arg
);
278 /* Discard cleanups, not doing the actions they describe,
279 until we get back to the point OLD_CHAIN in the cleanup_chain. */
282 discard_cleanups (old_chain
)
283 register struct cleanup
*old_chain
;
285 discard_my_cleanups (&cleanup_chain
, old_chain
);
289 discard_final_cleanups (old_chain
)
290 register struct cleanup
*old_chain
;
292 discard_my_cleanups (&final_cleanup_chain
, old_chain
);
296 discard_exec_error_cleanups (old_chain
)
297 register struct cleanup
*old_chain
;
299 discard_my_cleanups (&exec_error_cleanup_chain
, old_chain
);
303 discard_my_cleanups (pmy_chain
, old_chain
)
304 register struct cleanup
**pmy_chain
;
305 register struct cleanup
*old_chain
;
307 register struct cleanup
*ptr
;
308 while ((ptr
= *pmy_chain
) != old_chain
)
310 *pmy_chain
= ptr
->next
;
315 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
319 return save_my_cleanups (&cleanup_chain
);
323 save_final_cleanups ()
325 return save_my_cleanups (&final_cleanup_chain
);
329 save_my_cleanups (pmy_chain
)
330 struct cleanup
**pmy_chain
;
332 struct cleanup
*old_chain
= *pmy_chain
;
338 /* Restore the cleanup chain from a previously saved chain. */
340 restore_cleanups (chain
)
341 struct cleanup
*chain
;
343 restore_my_cleanups (&cleanup_chain
, chain
);
347 restore_final_cleanups (chain
)
348 struct cleanup
*chain
;
350 restore_my_cleanups (&final_cleanup_chain
, chain
);
354 restore_my_cleanups (pmy_chain
, chain
)
355 struct cleanup
**pmy_chain
;
356 struct cleanup
*chain
;
361 /* This function is useful for cleanups.
365 old_chain = make_cleanup (free_current_contents, &foo);
367 to arrange to free the object thus allocated. */
370 free_current_contents (location
)
376 /* Provide a known function that does nothing, to use as a base for
377 for a possibly long chain of cleanups. This is useful where we
378 use the cleanup chain for handling normal cleanups as well as dealing
379 with cleanups that need to be done as a result of a call to error().
380 In such cases, we may not be certain where the first cleanup is, unless
381 we have a do-nothing one to always use as the base. */
390 /* Add a continuation to the continuation list, the gloabl list
393 add_continuation (continuation_hook
, arg_list
)
394 void (*continuation_hook
) PARAMS ((struct continuation_arg
*));
395 struct continuation_arg
*arg_list
;
397 struct continuation
*continuation_ptr
;
399 continuation_ptr
= (struct continuation
*) xmalloc (sizeof (struct continuation
));
400 continuation_ptr
->continuation_hook
= continuation_hook
;
401 continuation_ptr
->arg_list
= arg_list
;
402 continuation_ptr
->next
= cmd_continuation
;
403 cmd_continuation
= continuation_ptr
;
406 /* Walk down the cmd_continuation list, and execute all the
409 do_all_continuations ()
411 struct continuation
*continuation_ptr
;
413 while (cmd_continuation
)
415 (cmd_continuation
->continuation_hook
) (cmd_continuation
->arg_list
);
416 continuation_ptr
= cmd_continuation
;
417 cmd_continuation
= continuation_ptr
->next
;
418 free (continuation_ptr
);
422 /* Walk down the cmd_continuation list, and get rid of all the
425 discard_all_continuations ()
427 struct continuation
*continuation_ptr
;
429 while (cmd_continuation
)
431 continuation_ptr
= cmd_continuation
;
432 cmd_continuation
= continuation_ptr
->next
;
433 free (continuation_ptr
);
439 /* Print a warning message. Way to use this is to call warning_begin,
440 output the warning message (use unfiltered output to gdb_stderr),
441 ending in a newline. There is not currently a warning_end that you
442 call afterwards, but such a thing might be added if it is useful
443 for a GUI to separate warning messages from other output.
445 FIXME: Why do warnings use unfiltered output and errors filtered?
446 Is this anything other than a historical accident? */
451 target_terminal_ours ();
452 wrap_here (""); /* Force out any buffered output */
453 gdb_flush (gdb_stdout
);
454 if (warning_pre_print
)
455 fprintf_unfiltered (gdb_stderr
, warning_pre_print
);
458 /* Print a warning message.
459 The first argument STRING is the warning message, used as a fprintf string,
460 and the remaining args are passed as arguments to it.
461 The primary difference between warnings and errors is that a warning
462 does not force the return to command level. */
465 warning (const char *string
,...)
468 va_start (args
, string
);
470 (*warning_hook
) (string
, args
);
474 vfprintf_unfiltered (gdb_stderr
, string
, args
);
475 fprintf_unfiltered (gdb_stderr
, "\n");
480 /* Start the printing of an error message. Way to use this is to call
481 this, output the error message (use filtered output to gdb_stderr
482 (FIXME: Some callers, like memory_error, use gdb_stdout)), ending
483 in a newline, and then call return_to_top_level (RETURN_ERROR).
484 error() provides a convenient way to do this for the special case
485 that the error message can be formatted with a single printf call,
486 but this is more general. */
490 if (error_begin_hook
)
493 target_terminal_ours ();
494 wrap_here (""); /* Force out any buffered output */
495 gdb_flush (gdb_stdout
);
497 annotate_error_begin ();
500 fprintf_filtered (gdb_stderr
, error_pre_print
);
503 /* Print an error message and return to command level.
504 The first argument STRING is the error message, used as a fprintf string,
505 and the remaining args are passed as arguments to it. */
508 error (const char *string
,...)
511 va_start (args
, string
);
517 vfprintf_filtered (gdb_stderr
, string
, args
);
518 fprintf_filtered (gdb_stderr
, "\n");
520 return_to_top_level (RETURN_ERROR
);
525 /* Print a message reporting an internal error. Ask the user if they
526 want to continue, dump core, or just exit. */
529 internal_error (char *string
, ...)
531 static char msg
[] = "Internal GDB error: recursive internal error.\n";
532 static int dejavu
= 0;
537 /* don't allow infinite error recursion. */
545 fputs_unfiltered (msg
, gdb_stderr
);
549 write (STDERR_FILENO
, msg
, sizeof (msg
));
553 /* Try to get the message out */
554 fputs_unfiltered ("gdb-internal-error: ", gdb_stderr
);
555 va_start (args
, string
);
556 vfprintf_unfiltered (gdb_stderr
, string
, args
);
558 fputs_unfiltered ("\n", gdb_stderr
);
560 /* Default (no case) is to quit GDB. When in batch mode this
561 lessens the likelhood of GDB going into an infinate loop. */
562 continue_p
= query ("\
563 An internal GDB error was detected. This may make make further\n\
564 debugging unreliable. Continue this debugging session? ");
566 /* Default (no case) is to not dump core. Lessen the chance of GDB
567 leaving random core files around. */
568 dump_core_p
= query ("\
569 Create a core file containing the current state of GDB? ");
588 return_to_top_level (RETURN_ERROR
);
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 /* No steenking SIGINT will ever be coming our way when the
712 program is resumed. Don't lie. */
713 fprintf_unfiltered (gdb_stderr
, "Quit\n");
716 /* If there is no terminal switching for this target, then we can't
717 possibly get screwed by the lack of job control. */
718 || current_target
.to_terminal_ours
== NULL
)
719 fprintf_unfiltered (gdb_stderr
, "Quit\n");
721 fprintf_unfiltered (gdb_stderr
,
722 "Quit (expect signal SIGINT when the program is resumed)\n");
724 return_to_top_level (RETURN_QUIT
);
728 #if defined(_MSC_VER) /* should test for wingdb instead? */
731 * Windows translates all keyboard and mouse events
732 * into a message which is appended to the message
733 * queue for the process.
739 int k
= win32pollquit ();
746 #else /* !defined(__GO32__) && !defined(_MSC_VER) */
751 /* Done by signals */
754 #endif /* !defined(__GO32__) && !defined(_MSC_VER) */
756 /* Control C comes here */
762 /* Restore the signal handler. Harmless with BSD-style signals, needed
763 for System V-style signals. So just always do it, rather than worrying
764 about USG defines and stuff like that. */
765 signal (signo
, request_quit
);
775 /* Memory management stuff (malloc friends). */
777 /* Make a substitute size_t for non-ANSI compilers. */
779 #ifndef HAVE_STDDEF_H
781 #define size_t unsigned int
785 #if !defined (USE_MMALLOC)
792 return malloc (size
);
796 mrealloc (md
, ptr
, size
)
801 if (ptr
== 0) /* Guard against old realloc's */
802 return malloc (size
);
804 return realloc (ptr
, size
);
815 #endif /* USE_MMALLOC */
817 #if !defined (USE_MMALLOC) || defined (NO_MMCHECK)
825 #else /* Have mmalloc and want corruption checking */
830 fprintf_unfiltered (gdb_stderr
, "Memory corruption\n");
834 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
835 by MD, to detect memory corruption. Note that MD may be NULL to specify
836 the default heap that grows via sbrk.
838 Note that for freshly created regions, we must call mmcheckf prior to any
839 mallocs in the region. Otherwise, any region which was allocated prior to
840 installing the checking hooks, which is later reallocated or freed, will
841 fail the checks! The mmcheck function only allows initial hooks to be
842 installed before the first mmalloc. However, anytime after we have called
843 mmcheck the first time to install the checking hooks, we can call it again
844 to update the function pointer to the memory corruption handler.
846 Returns zero on failure, non-zero on success. */
848 #ifndef MMCHECK_FORCE
849 #define MMCHECK_FORCE 0
856 if (!mmcheckf (md
, malloc_botch
, MMCHECK_FORCE
))
858 /* Don't use warning(), which relies on current_target being set
859 to something other than dummy_target, until after
860 initialize_all_files(). */
863 (gdb_stderr
, "warning: failed to install memory consistency checks; ");
865 (gdb_stderr
, "configuration should define NO_MMCHECK or MMCHECK_FORCE\n");
871 #endif /* Have mmalloc and want corruption checking */
873 /* Called when a memory allocation fails, with the number of bytes of
874 memory requested in SIZE. */
882 internal_error ("virtual memory exhausted: can't allocate %ld bytes.", size
);
886 internal_error ("virtual memory exhausted.");
890 /* Like mmalloc but get error if no storage available, and protect against
891 the caller wanting to allocate zero bytes. Whether to return NULL for
892 a zero byte request, or translate the request into a request for one
893 byte of zero'd storage, is a religious issue. */
906 else if ((val
= mmalloc (md
, size
)) == NULL
)
913 /* Like mrealloc but get error if no storage available. */
916 xmrealloc (md
, ptr
, size
)
925 val
= mrealloc (md
, ptr
, size
);
929 val
= mmalloc (md
, size
);
938 /* Like malloc but get error if no storage available, and protect against
939 the caller wanting to allocate zero bytes. */
945 return (xmmalloc ((PTR
) NULL
, size
));
948 /* Like mrealloc but get error if no storage available. */
955 return (xmrealloc ((PTR
) NULL
, ptr
, size
));
959 /* My replacement for the read system call.
960 Used like `read' but keeps going if `read' returns too soon. */
963 myread (desc
, addr
, len
)
973 val
= read (desc
, addr
, len
);
984 /* Make a copy of the string at PTR with SIZE characters
985 (and add a null character at the end in the copy).
986 Uses malloc to get the space. Returns the address of the copy. */
989 savestring (ptr
, size
)
993 register char *p
= (char *) xmalloc (size
+ 1);
994 memcpy (p
, ptr
, size
);
1000 msavestring (md
, ptr
, size
)
1005 register char *p
= (char *) xmmalloc (md
, size
+ 1);
1006 memcpy (p
, ptr
, size
);
1011 /* The "const" is so it compiles under DGUX (which prototypes strsave
1012 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
1013 Doesn't real strsave return NULL if out of memory? */
1018 return savestring (ptr
, strlen (ptr
));
1026 return (msavestring (md
, ptr
, strlen (ptr
)));
1030 print_spaces (n
, file
)
1032 register GDB_FILE
*file
;
1034 fputs_unfiltered (n_spaces (n
), file
);
1037 /* Print a host address. */
1040 gdb_print_host_address (void *addr
, struct gdb_file
*stream
)
1043 /* We could use the %p conversion specifier to fprintf if we had any
1044 way of knowing whether this host supports it. But the following
1045 should work on the Alpha and on 32 bit machines. */
1047 fprintf_filtered (stream
, "0x%lx", (unsigned long) addr
);
1050 /* Ask user a y-or-n question and return 1 iff answer is yes.
1051 Takes three args which are given to printf to print the question.
1052 The first, a control string, should end in "? ".
1053 It should not say how to answer, because we do that. */
1057 query (char *ctlstr
,...)
1060 register int answer
;
1064 va_start (args
, ctlstr
);
1068 return query_hook (ctlstr
, args
);
1071 /* Automatically answer "yes" if input is not from a terminal. */
1072 if (!input_from_terminal_p ())
1075 /* FIXME Automatically answer "yes" if called from MacGDB. */
1082 wrap_here (""); /* Flush any buffered output */
1083 gdb_flush (gdb_stdout
);
1085 if (annotation_level
> 1)
1086 printf_filtered ("\n\032\032pre-query\n");
1088 vfprintf_filtered (gdb_stdout
, ctlstr
, args
);
1089 printf_filtered ("(y or n) ");
1091 if (annotation_level
> 1)
1092 printf_filtered ("\n\032\032query\n");
1095 /* If not in MacGDB, move to a new line so the entered line doesn't
1096 have a prompt on the front of it. */
1098 fputs_unfiltered ("\n", gdb_stdout
);
1102 gdb_flush (gdb_stdout
);
1105 if (!tui_version
|| cmdWin
== tuiWinWithFocus ())
1107 answer
= fgetc (stdin
);
1110 answer
= (unsigned char) tuiBufferGetc ();
1113 clearerr (stdin
); /* in case of C-d */
1114 if (answer
== EOF
) /* C-d */
1119 /* Eat rest of input line, to EOF or newline */
1120 if ((answer
!= '\n') || (tui_version
&& answer
!= '\r'))
1124 if (!tui_version
|| cmdWin
== tuiWinWithFocus ())
1126 ans2
= fgetc (stdin
);
1129 ans2
= (unsigned char) tuiBufferGetc ();
1133 while (ans2
!= EOF
&& ans2
!= '\n' && ans2
!= '\r');
1134 TUIDO (((TuiOpaqueFuncPtr
) tui_vStartNewLines
, 1));
1148 printf_filtered ("Please answer y or n.\n");
1151 if (annotation_level
> 1)
1152 printf_filtered ("\n\032\032post-query\n");
1157 /* Parse a C escape sequence. STRING_PTR points to a variable
1158 containing a pointer to the string to parse. That pointer
1159 should point to the character after the \. That pointer
1160 is updated past the characters we use. The value of the
1161 escape sequence is returned.
1163 A negative value means the sequence \ newline was seen,
1164 which is supposed to be equivalent to nothing at all.
1166 If \ is followed by a null character, we return a negative
1167 value and leave the string pointer pointing at the null character.
1169 If \ is followed by 000, we return 0 and leave the string pointer
1170 after the zeros. A value of 0 does not mean end of string. */
1173 parse_escape (string_ptr
)
1176 register int c
= *(*string_ptr
)++;
1180 return 007; /* Bell (alert) char */
1183 case 'e': /* Escape character */
1201 c
= *(*string_ptr
)++;
1203 c
= parse_escape (string_ptr
);
1206 return (c
& 0200) | (c
& 037);
1217 register int i
= c
- '0';
1218 register int count
= 0;
1221 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
1239 /* Print the character C on STREAM as part of the contents of a literal
1240 string whose delimiter is QUOTER. Note that this routine should only
1241 be call for printing things which are independent of the language
1242 of the program being debugged. */
1244 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
));
1247 printchar (c
, do_fputs
, do_fprintf
, stream
, quoter
)
1249 void (*do_fputs
) PARAMS ((const char *, GDB_FILE
*));
1250 void (*do_fprintf
) PARAMS ((GDB_FILE
*, const char *, ...));
1255 c
&= 0xFF; /* Avoid sign bit follies */
1257 if (c
< 0x20 || /* Low control chars */
1258 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
1259 (sevenbit_strings
&& c
>= 0x80))
1260 { /* high order bit set */
1264 do_fputs ("\\n", stream
);
1267 do_fputs ("\\b", stream
);
1270 do_fputs ("\\t", stream
);
1273 do_fputs ("\\f", stream
);
1276 do_fputs ("\\r", stream
);
1279 do_fputs ("\\e", stream
);
1282 do_fputs ("\\a", stream
);
1285 do_fprintf (stream
, "\\%.3o", (unsigned int) c
);
1291 if (c
== '\\' || c
== quoter
)
1292 do_fputs ("\\", stream
);
1293 do_fprintf (stream
, "%c", c
);
1297 /* Print the character C on STREAM as part of the contents of a
1298 literal string whose delimiter is QUOTER. Note that these routines
1299 should only be call for printing things which are independent of
1300 the language of the program being debugged. */
1303 fputstr_filtered (str
, quoter
, stream
)
1309 printchar (*str
++, fputs_filtered
, fprintf_filtered
, stream
, quoter
);
1313 fputstr_unfiltered (str
, quoter
, stream
)
1319 printchar (*str
++, fputs_unfiltered
, fprintf_unfiltered
, stream
, quoter
);
1323 fputstrn_unfiltered (str
, n
, quoter
, stream
)
1330 for (i
= 0; i
< n
; i
++)
1331 printchar (str
[i
], fputs_unfiltered
, fprintf_unfiltered
, stream
, quoter
);
1336 /* Number of lines per page or UINT_MAX if paging is disabled. */
1337 static unsigned int lines_per_page
;
1338 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
1339 static unsigned int chars_per_line
;
1340 /* Current count of lines printed on this page, chars on this line. */
1341 static unsigned int lines_printed
, chars_printed
;
1343 /* Buffer and start column of buffered text, for doing smarter word-
1344 wrapping. When someone calls wrap_here(), we start buffering output
1345 that comes through fputs_filtered(). If we see a newline, we just
1346 spit it out and forget about the wrap_here(). If we see another
1347 wrap_here(), we spit it out and remember the newer one. If we see
1348 the end of the line, we spit out a newline, the indent, and then
1349 the buffered output. */
1351 /* Malloc'd buffer with chars_per_line+2 bytes. Contains characters which
1352 are waiting to be output (they have already been counted in chars_printed).
1353 When wrap_buffer[0] is null, the buffer is empty. */
1354 static char *wrap_buffer
;
1356 /* Pointer in wrap_buffer to the next character to fill. */
1357 static char *wrap_pointer
;
1359 /* String to indent by if the wrap occurs. Must not be NULL if wrap_column
1361 static char *wrap_indent
;
1363 /* Column number on the screen where wrap_buffer begins, or 0 if wrapping
1364 is not in effect. */
1365 static int wrap_column
;
1368 /* Inialize the lines and chars per page */
1373 if (tui_version
&& m_winPtrNotNull (cmdWin
))
1375 lines_per_page
= cmdWin
->generic
.height
;
1376 chars_per_line
= cmdWin
->generic
.width
;
1381 /* These defaults will be used if we are unable to get the correct
1382 values from termcap. */
1383 #if defined(__GO32__)
1384 lines_per_page
= ScreenRows ();
1385 chars_per_line
= ScreenCols ();
1387 lines_per_page
= 24;
1388 chars_per_line
= 80;
1390 #if !defined (MPW) && !defined (_WIN32)
1391 /* No termcap under MPW, although might be cool to do something
1392 by looking at worksheet or console window sizes. */
1393 /* Initialize the screen height and width from termcap. */
1395 char *termtype
= getenv ("TERM");
1397 /* Positive means success, nonpositive means failure. */
1400 /* 2048 is large enough for all known terminals, according to the
1401 GNU termcap manual. */
1402 char term_buffer
[2048];
1406 status
= tgetent (term_buffer
, termtype
);
1410 int running_in_emacs
= getenv ("EMACS") != NULL
;
1412 val
= tgetnum ("li");
1413 if (val
>= 0 && !running_in_emacs
)
1414 lines_per_page
= val
;
1416 /* The number of lines per page is not mentioned
1417 in the terminal description. This probably means
1418 that paging is not useful (e.g. emacs shell window),
1419 so disable paging. */
1420 lines_per_page
= UINT_MAX
;
1422 val
= tgetnum ("co");
1424 chars_per_line
= val
;
1430 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1432 /* If there is a better way to determine the window size, use it. */
1433 SIGWINCH_HANDLER (SIGWINCH
);
1436 /* If the output is not a terminal, don't paginate it. */
1437 if (!GDB_FILE_ISATTY (gdb_stdout
))
1438 lines_per_page
= UINT_MAX
;
1439 } /* the command_line_version */
1446 if (chars_per_line
== 0)
1451 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
1452 wrap_buffer
[0] = '\0';
1455 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
1456 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
1461 set_width_command (args
, from_tty
, c
)
1464 struct cmd_list_element
*c
;
1469 /* Wait, so the user can read what's on the screen. Prompt the user
1470 to continue by pressing RETURN. */
1473 prompt_for_continue ()
1476 char cont_prompt
[120];
1478 if (annotation_level
> 1)
1479 printf_unfiltered ("\n\032\032pre-prompt-for-continue\n");
1481 strcpy (cont_prompt
,
1482 "---Type <return> to continue, or q <return> to quit---");
1483 if (annotation_level
> 1)
1484 strcat (cont_prompt
, "\n\032\032prompt-for-continue\n");
1486 /* We must do this *before* we call gdb_readline, else it will eventually
1487 call us -- thinking that we're trying to print beyond the end of the
1489 reinitialize_more_filter ();
1492 /* On a real operating system, the user can quit with SIGINT.
1495 'q' is provided on all systems so users don't have to change habits
1496 from system to system, and because telling them what to do in
1497 the prompt is more user-friendly than expecting them to think of
1499 /* Call readline, not gdb_readline, because GO32 readline handles control-C
1500 whereas control-C to gdb_readline will cause the user to get dumped
1502 ignore
= readline (cont_prompt
);
1504 if (annotation_level
> 1)
1505 printf_unfiltered ("\n\032\032post-prompt-for-continue\n");
1510 while (*p
== ' ' || *p
== '\t')
1515 request_quit (SIGINT
);
1517 async_request_quit (0);
1523 /* Now we have to do this again, so that GDB will know that it doesn't
1524 need to save the ---Type <return>--- line at the top of the screen. */
1525 reinitialize_more_filter ();
1527 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
1530 /* Reinitialize filter; ie. tell it to reset to original values. */
1533 reinitialize_more_filter ()
1539 /* Indicate that if the next sequence of characters overflows the line,
1540 a newline should be inserted here rather than when it hits the end.
1541 If INDENT is non-null, it is a string to be printed to indent the
1542 wrapped part on the next line. INDENT must remain accessible until
1543 the next call to wrap_here() or until a newline is printed through
1546 If the line is already overfull, we immediately print a newline and
1547 the indentation, and disable further wrapping.
1549 If we don't know the width of lines, but we know the page height,
1550 we must not wrap words, but should still keep track of newlines
1551 that were explicitly printed.
1553 INDENT should not contain tabs, as that will mess up the char count
1554 on the next line. FIXME.
1556 This routine is guaranteed to force out any output which has been
1557 squirreled away in the wrap_buffer, so wrap_here ((char *)0) can be
1558 used to force out output from the wrap_buffer. */
1564 /* This should have been allocated, but be paranoid anyway. */
1570 *wrap_pointer
= '\0';
1571 fputs_unfiltered (wrap_buffer
, gdb_stdout
);
1573 wrap_pointer
= wrap_buffer
;
1574 wrap_buffer
[0] = '\0';
1575 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
1579 else if (chars_printed
>= chars_per_line
)
1581 puts_filtered ("\n");
1583 puts_filtered (indent
);
1588 wrap_column
= chars_printed
;
1592 wrap_indent
= indent
;
1596 /* Ensure that whatever gets printed next, using the filtered output
1597 commands, starts at the beginning of the line. I.E. if there is
1598 any pending output for the current line, flush it and start a new
1599 line. Otherwise do nothing. */
1604 if (chars_printed
> 0)
1606 puts_filtered ("\n");
1611 /* ``struct gdb_file'' implementation that maps directly onto
1612 <stdio.h>'s FILE. */
1614 static gdb_file_fputs_ftype stdio_file_fputs
;
1615 static gdb_file_isatty_ftype stdio_file_isatty
;
1616 static gdb_file_delete_ftype stdio_file_delete
;
1617 static struct gdb_file
*stdio_file_new
PARAMS ((FILE * file
, int close_p
));
1618 static gdb_file_flush_ftype stdio_file_flush
;
1620 static int stdio_file_magic
;
1629 static struct gdb_file
*
1630 stdio_file_new (file
, close_p
)
1634 struct gdb_file
*gdb_file
= gdb_file_new ();
1635 struct stdio_file
*stdio
= xmalloc (sizeof (struct stdio_file
));
1636 stdio
->magic
= &stdio_file_magic
;
1638 stdio
->close_p
= close_p
;
1639 set_gdb_file_data (gdb_file
, stdio
, stdio_file_delete
);
1640 set_gdb_file_flush (gdb_file
, stdio_file_flush
);
1641 set_gdb_file_fputs (gdb_file
, stdio_file_fputs
);
1642 set_gdb_file_isatty (gdb_file
, stdio_file_isatty
);
1647 stdio_file_delete (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");
1655 fclose (stdio
->file
);
1661 stdio_file_flush (file
)
1662 struct gdb_file
*file
;
1664 struct stdio_file
*stdio
= gdb_file_data (file
);
1665 if (stdio
->magic
!= &stdio_file_magic
)
1666 error ("Internal error: bad magic number");
1667 fflush (stdio
->file
);
1671 stdio_file_fputs (linebuffer
, file
)
1672 const char *linebuffer
;
1673 struct gdb_file
*file
;
1675 struct stdio_file
*stdio
= gdb_file_data (file
);
1676 if (stdio
->magic
!= &stdio_file_magic
)
1677 error ("Internal error: bad magic number");
1678 fputs (linebuffer
, stdio
->file
);
1682 stdio_file_isatty (file
)
1683 struct gdb_file
*file
;
1685 struct stdio_file
*stdio
= gdb_file_data (file
);
1686 if (stdio
->magic
!= &stdio_file_magic
)
1687 error ("Internal error: bad magic number");
1688 return (isatty (fileno (stdio
->file
)));
1691 /* Like fdopen(). Create a gdb_file from a previously opened FILE. */
1694 stdio_fileopen (file
)
1697 return stdio_file_new (file
, 0);
1701 /* A ``struct gdb_file'' that is compatible with all the legacy
1715 enum streamtype ts_streamtype
;
1716 FILE *ts_filestream
;
1721 static gdb_file_flush_ftype tui_file_flush
;
1722 extern gdb_file_fputs_ftype tui_file_fputs
;
1723 static gdb_file_isatty_ftype tui_file_isatty
;
1724 static gdb_file_rewind_ftype tui_file_rewind
;
1725 static gdb_file_put_ftype tui_file_put
;
1726 static gdb_file_delete_ftype tui_file_delete
;
1727 static struct gdb_file
*tui_file_new
PARAMS ((void));
1728 static int tui_file_magic
;
1730 static struct gdb_file
*
1733 struct tui_stream
*tui
= xmalloc (sizeof (struct tui_stream
));
1734 struct gdb_file
*file
= gdb_file_new ();
1735 set_gdb_file_data (file
, tui
, tui_file_delete
);
1736 set_gdb_file_flush (file
, tui_file_flush
);
1737 set_gdb_file_fputs (file
, tui_file_fputs
);
1738 set_gdb_file_isatty (file
, tui_file_isatty
);
1739 set_gdb_file_rewind (file
, tui_file_rewind
);
1740 set_gdb_file_put (file
, tui_file_put
);
1741 tui
->ts_magic
= &tui_file_magic
;
1746 tui_file_delete (file
)
1747 struct gdb_file
*file
;
1749 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1750 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1751 error ("Internal error: bad magic number");
1752 if ((tmpstream
->ts_streamtype
== astring
) &&
1753 (tmpstream
->ts_strbuf
!= NULL
))
1755 free (tmpstream
->ts_strbuf
);
1761 tui_fileopen (stream
)
1764 struct gdb_file
*file
= tui_file_new ();
1765 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1766 tmpstream
->ts_streamtype
= afile
;
1767 tmpstream
->ts_filestream
= stream
;
1768 tmpstream
->ts_strbuf
= NULL
;
1769 tmpstream
->ts_buflen
= 0;
1774 tui_file_isatty (file
)
1775 struct gdb_file
*file
;
1777 struct tui_stream
*stream
= gdb_file_data (file
);
1778 if (stream
->ts_magic
!= &tui_file_magic
)
1779 error ("Internal error: bad magic number");
1780 if (stream
->ts_streamtype
== afile
)
1781 return (isatty (fileno (stream
->ts_filestream
)));
1787 tui_file_rewind (file
)
1788 struct gdb_file
*file
;
1790 struct tui_stream
*stream
= gdb_file_data (file
);
1791 if (stream
->ts_magic
!= &tui_file_magic
)
1792 error ("Internal error: bad magic number");
1793 stream
->ts_strbuf
[0] = '\0';
1797 tui_file_put (file
, dest
)
1798 struct gdb_file
*file
;
1799 struct gdb_file
*dest
;
1801 struct tui_stream
*stream
= gdb_file_data (file
);
1802 if (stream
->ts_magic
!= &tui_file_magic
)
1803 error ("Internal error: bad magic number");
1804 if (stream
->ts_streamtype
== astring
)
1806 fputs_unfiltered (stream
->ts_strbuf
, dest
);
1810 /* All TUI I/O sent to the *_filtered and *_unfiltered functions
1811 eventually ends up here. The fputs_unfiltered_hook is primarily
1812 used by GUIs to collect all output and send it to the GUI, instead
1813 of the controlling terminal. Only output to gdb_stdout and
1814 gdb_stderr are sent to the hook. Everything else is sent on to
1815 fputs to allow file I/O to be handled appropriately. */
1817 /* FIXME: Should be broken up and moved to a TUI specific file. */
1820 tui_file_fputs (linebuffer
, file
)
1821 const char *linebuffer
;
1824 struct tui_stream
*stream
= gdb_file_data (file
);
1826 extern int tui_owns_terminal
;
1828 /* If anything (GUI, TUI) wants to capture GDB output, this is
1829 * the place... the way to do it is to set up
1830 * fputs_unfiltered_hook.
1831 * Our TUI ("gdb -tui") used to hook output, but in the
1832 * new (XDB style) scheme, we do not do that anymore... - RT
1834 if (fputs_unfiltered_hook
1835 && (file
== gdb_stdout
1836 || file
== gdb_stderr
))
1837 fputs_unfiltered_hook (linebuffer
, file
);
1841 if (tui_version
&& tui_owns_terminal
)
1843 /* If we get here somehow while updating the TUI (from
1844 * within a tuiDo(), then we need to temporarily
1845 * set up the terminal for GDB output. This probably just
1846 * happens on error output.
1849 if (stream
->ts_streamtype
== astring
)
1851 gdb_file_adjust_strbuf (strlen (linebuffer
), stream
);
1852 strcat (stream
->ts_strbuf
, linebuffer
);
1856 tuiTermUnsetup (0, (tui_version
) ? cmdWin
->detail
.commandInfo
.curch
: 0);
1857 fputs (linebuffer
, stream
->ts_filestream
);
1859 if (linebuffer
[strlen (linebuffer
) - 1] == '\n')
1860 tuiClearCommandCharCount ();
1862 tuiIncrCommandCharCountBy (strlen (linebuffer
));
1867 /* The normal case - just do a fputs() */
1868 if (stream
->ts_streamtype
== astring
)
1870 gdb_file_adjust_strbuf (strlen (linebuffer
), stream
);
1871 strcat (stream
->ts_strbuf
, linebuffer
);
1874 fputs (linebuffer
, stream
->ts_filestream
);
1879 if (stream
->ts_streamtype
== astring
)
1881 gdb_file_adjust_strbuf (strlen (linebuffer
), file
);
1882 strcat (stream
->ts_strbuf
, linebuffer
);
1885 fputs (linebuffer
, stream
->ts_filestream
);
1891 gdb_file_init_astring (n
)
1894 struct gdb_file
*file
= tui_file_new ();
1895 struct tui_stream
*tmpstream
= gdb_file_data (file
);
1896 if (tmpstream
->ts_magic
!= &tui_file_magic
)
1897 error ("Internal error: bad magic number");
1899 tmpstream
->ts_streamtype
= astring
;
1900 tmpstream
->ts_filestream
= NULL
;
1903 tmpstream
->ts_strbuf
= xmalloc ((n
+ 1) * sizeof (char));
1904 tmpstream
->ts_strbuf
[0] = '\0';
1907 tmpstream
->ts_strbuf
= NULL
;
1908 tmpstream
->ts_buflen
= n
;
1914 gdb_file_deallocate (streamptr
)
1915 GDB_FILE
**streamptr
;
1917 gdb_file_delete (*streamptr
);
1922 gdb_file_get_strbuf (file
)
1925 struct tui_stream
*stream
= gdb_file_data (file
);
1926 if (stream
->ts_magic
!= &tui_file_magic
)
1927 error ("Internal error: bad magic number");
1928 return (stream
->ts_strbuf
);
1931 /* adjust the length of the buffer by the amount necessary
1932 to accomodate appending a string of length N to the buffer contents */
1934 gdb_file_adjust_strbuf (n
, file
)
1938 struct tui_stream
*stream
= gdb_file_data (file
);
1940 if (stream
->ts_magic
!= &tui_file_magic
)
1941 error ("Internal error: bad magic number");
1943 if (stream
->ts_streamtype
!= astring
)
1946 if (stream
->ts_strbuf
)
1948 /* There is already a buffer allocated */
1949 non_null_chars
= strlen (stream
->ts_strbuf
);
1951 if (n
> (stream
->ts_buflen
- non_null_chars
- 1))
1953 stream
->ts_buflen
= n
+ non_null_chars
+ 1;
1954 stream
->ts_strbuf
= xrealloc (stream
->ts_strbuf
, stream
->ts_buflen
);
1958 /* No buffer yet, so allocate one of the desired size */
1959 stream
->ts_strbuf
= xmalloc ((n
+ 1) * sizeof (char));
1963 gdb_fopen (name
, mode
)
1967 FILE *f
= fopen (name
, mode
);
1970 return stdio_file_new (f
, 1);
1974 tui_file_flush (file
)
1977 struct tui_stream
*stream
= gdb_file_data (file
);
1978 if (stream
->ts_magic
!= &tui_file_magic
)
1979 error ("Internal error: bad magic number");
1981 && (file
== gdb_stdout
1982 || file
== gdb_stderr
))
1988 fflush (stream
->ts_filestream
);
1992 gdb_fclose (streamptr
)
1993 GDB_FILE
**streamptr
;
1995 gdb_file_delete (*streamptr
);
2000 /* Implement the ``struct gdb_file'' object. */
2002 static gdb_file_isatty_ftype null_file_isatty
;
2003 static gdb_file_fputs_ftype null_file_fputs
;
2004 static gdb_file_flush_ftype null_file_flush
;
2005 static gdb_file_delete_ftype null_file_delete
;
2006 static gdb_file_rewind_ftype null_file_rewind
;
2007 static gdb_file_put_ftype null_file_put
;
2011 gdb_file_flush_ftype
*to_flush
;
2012 gdb_file_fputs_ftype
*to_fputs
;
2013 gdb_file_delete_ftype
*to_delete
;
2014 gdb_file_isatty_ftype
*to_isatty
;
2015 gdb_file_rewind_ftype
*to_rewind
;
2016 gdb_file_put_ftype
*to_put
;
2023 struct gdb_file
*file
= xmalloc (sizeof (struct gdb_file
));
2024 set_gdb_file_data (file
, NULL
, null_file_delete
);
2025 set_gdb_file_flush (file
, null_file_flush
);
2026 set_gdb_file_fputs (file
, null_file_fputs
);
2027 set_gdb_file_isatty (file
, null_file_isatty
);
2028 set_gdb_file_rewind (file
, null_file_rewind
);
2029 set_gdb_file_put (file
, null_file_put
);
2034 gdb_file_delete (file
)
2035 struct gdb_file
*file
;
2037 file
->to_delete (file
);
2042 null_file_isatty (file
)
2043 struct gdb_file
*file
;
2049 null_file_rewind (file
)
2050 struct gdb_file
*file
;
2056 null_file_put (file
, src
)
2057 struct gdb_file
*file
;
2058 struct gdb_file
*src
;
2064 null_file_flush (file
)
2065 struct gdb_file
*file
;
2071 null_file_fputs (buf
, file
)
2073 struct gdb_file
*file
;
2079 null_file_delete (file
)
2080 struct gdb_file
*file
;
2086 gdb_file_data (file
)
2087 struct gdb_file
*file
;
2089 return file
->to_data
;
2094 struct gdb_file
*file
;
2096 file
->to_flush (file
);
2100 gdb_file_isatty (file
)
2101 struct gdb_file
*file
;
2103 return file
->to_isatty (file
);
2107 gdb_file_rewind (file
)
2108 struct gdb_file
*file
;
2110 file
->to_rewind (file
);
2114 gdb_file_put (file
, dest
)
2115 struct gdb_file
*file
;
2116 struct gdb_file
*dest
;
2118 file
->to_put (file
, dest
);
2122 fputs_unfiltered (buf
, file
)
2124 struct gdb_file
*file
;
2126 file
->to_fputs (buf
, file
);
2130 set_gdb_file_flush (file
, flush
)
2131 struct gdb_file
*file
;
2132 gdb_file_flush_ftype
*flush
;
2134 file
->to_flush
= flush
;
2138 set_gdb_file_isatty (file
, isatty
)
2139 struct gdb_file
*file
;
2140 gdb_file_isatty_ftype
*isatty
;
2142 file
->to_isatty
= isatty
;
2146 set_gdb_file_rewind (file
, rewind
)
2147 struct gdb_file
*file
;
2148 gdb_file_rewind_ftype
*rewind
;
2150 file
->to_rewind
= rewind
;
2154 set_gdb_file_put (file
, put
)
2155 struct gdb_file
*file
;
2156 gdb_file_put_ftype
*put
;
2162 set_gdb_file_fputs (file
, fputs
)
2163 struct gdb_file
*file
;
2164 gdb_file_fputs_ftype
*fputs
;
2166 file
->to_fputs
= fputs
;
2170 set_gdb_file_data (file
, data
, delete)
2171 struct gdb_file
*file
;
2173 gdb_file_delete_ftype
*delete;
2175 file
->to_data
= data
;
2176 file
->to_delete
= delete;
2179 /* Like fputs but if FILTER is true, pause after every screenful.
2181 Regardless of FILTER can wrap at points other than the final
2182 character of a line.
2184 Unlike fputs, fputs_maybe_filtered does not return a value.
2185 It is OK for LINEBUFFER to be NULL, in which case just don't print
2188 Note that a longjmp to top level may occur in this routine (only if
2189 FILTER is true) (since prompt_for_continue may do so) so this
2190 routine should not be called when cleanups are not in place. */
2193 fputs_maybe_filtered (linebuffer
, stream
, filter
)
2194 const char *linebuffer
;
2198 const char *lineptr
;
2200 if (linebuffer
== 0)
2203 /* Don't do any filtering if it is disabled. */
2204 if ((stream
!= gdb_stdout
) || !pagination_enabled
2205 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
2207 fputs_unfiltered (linebuffer
, stream
);
2211 /* Go through and output each character. Show line extension
2212 when this is necessary; prompt user for new page when this is
2215 lineptr
= linebuffer
;
2218 /* Possible new page. */
2220 (lines_printed
>= lines_per_page
- 1))
2221 prompt_for_continue ();
2223 while (*lineptr
&& *lineptr
!= '\n')
2225 /* Print a single line. */
2226 if (*lineptr
== '\t')
2229 *wrap_pointer
++ = '\t';
2231 fputc_unfiltered ('\t', stream
);
2232 /* Shifting right by 3 produces the number of tab stops
2233 we have already passed, and then adding one and
2234 shifting left 3 advances to the next tab stop. */
2235 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
2241 *wrap_pointer
++ = *lineptr
;
2243 fputc_unfiltered (*lineptr
, stream
);
2248 if (chars_printed
>= chars_per_line
)
2250 unsigned int save_chars
= chars_printed
;
2254 /* If we aren't actually wrapping, don't output newline --
2255 if chars_per_line is right, we probably just overflowed
2256 anyway; if it's wrong, let us keep going. */
2258 fputc_unfiltered ('\n', stream
);
2260 /* Possible new page. */
2261 if (lines_printed
>= lines_per_page
- 1)
2262 prompt_for_continue ();
2264 /* Now output indentation and wrapped string */
2267 fputs_unfiltered (wrap_indent
, stream
);
2268 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
2269 fputs_unfiltered (wrap_buffer
, stream
); /* and eject it */
2270 /* FIXME, this strlen is what prevents wrap_indent from
2271 containing tabs. However, if we recurse to print it
2272 and count its chars, we risk trouble if wrap_indent is
2273 longer than (the user settable) chars_per_line.
2274 Note also that this can set chars_printed > chars_per_line
2275 if we are printing a long string. */
2276 chars_printed
= strlen (wrap_indent
)
2277 + (save_chars
- wrap_column
);
2278 wrap_pointer
= wrap_buffer
; /* Reset buffer */
2279 wrap_buffer
[0] = '\0';
2280 wrap_column
= 0; /* And disable fancy wrap */
2285 if (*lineptr
== '\n')
2288 wrap_here ((char *) 0); /* Spit out chars, cancel further wraps */
2290 fputc_unfiltered ('\n', stream
);
2297 fputs_filtered (linebuffer
, stream
)
2298 const char *linebuffer
;
2301 fputs_maybe_filtered (linebuffer
, stream
, 1);
2305 putchar_unfiltered (c
)
2312 fputs_unfiltered (buf
, gdb_stdout
);
2317 fputc_unfiltered (c
, stream
)
2325 fputs_unfiltered (buf
, stream
);
2330 fputc_filtered (c
, stream
)
2338 fputs_filtered (buf
, stream
);
2342 /* puts_debug is like fputs_unfiltered, except it prints special
2343 characters in printable fashion. */
2346 puts_debug (prefix
, string
, suffix
)
2353 /* Print prefix and suffix after each line. */
2354 static int new_line
= 1;
2355 static int return_p
= 0;
2356 static char *prev_prefix
= "";
2357 static char *prev_suffix
= "";
2359 if (*string
== '\n')
2362 /* If the prefix is changing, print the previous suffix, a new line,
2363 and the new prefix. */
2364 if ((return_p
|| (strcmp (prev_prefix
, prefix
) != 0)) && !new_line
)
2366 fputs_unfiltered (prev_suffix
, gdb_stdlog
);
2367 fputs_unfiltered ("\n", gdb_stdlog
);
2368 fputs_unfiltered (prefix
, gdb_stdlog
);
2371 /* Print prefix if we printed a newline during the previous call. */
2375 fputs_unfiltered (prefix
, gdb_stdlog
);
2378 prev_prefix
= prefix
;
2379 prev_suffix
= suffix
;
2381 /* Output characters in a printable format. */
2382 while ((ch
= *string
++) != '\0')
2388 fputc_unfiltered (ch
, gdb_stdlog
);
2391 fprintf_unfiltered (gdb_stdlog
, "\\x%02x", ch
& 0xff);
2395 fputs_unfiltered ("\\\\", gdb_stdlog
);
2398 fputs_unfiltered ("\\b", gdb_stdlog
);
2401 fputs_unfiltered ("\\f", gdb_stdlog
);
2405 fputs_unfiltered ("\\n", gdb_stdlog
);
2408 fputs_unfiltered ("\\r", gdb_stdlog
);
2411 fputs_unfiltered ("\\t", gdb_stdlog
);
2414 fputs_unfiltered ("\\v", gdb_stdlog
);
2418 return_p
= ch
== '\r';
2421 /* Print suffix if we printed a newline. */
2424 fputs_unfiltered (suffix
, gdb_stdlog
);
2425 fputs_unfiltered ("\n", gdb_stdlog
);
2430 /* Print a variable number of ARGS using format FORMAT. If this
2431 information is going to put the amount written (since the last call
2432 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
2433 call prompt_for_continue to get the users permision to continue.
2435 Unlike fprintf, this function does not return a value.
2437 We implement three variants, vfprintf (takes a vararg list and stream),
2438 fprintf (takes a stream to write on), and printf (the usual).
2440 Note also that a longjmp to top level may occur in this routine
2441 (since prompt_for_continue may do so) so this routine should not be
2442 called when cleanups are not in place. */
2445 vfprintf_maybe_filtered (stream
, format
, args
, filter
)
2452 struct cleanup
*old_cleanups
;
2454 vasprintf (&linebuffer
, format
, args
);
2455 if (linebuffer
== NULL
)
2457 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2460 old_cleanups
= make_cleanup (free
, linebuffer
);
2461 fputs_maybe_filtered (linebuffer
, stream
, filter
);
2462 do_cleanups (old_cleanups
);
2467 vfprintf_filtered (stream
, format
, args
)
2472 vfprintf_maybe_filtered (stream
, format
, args
, 1);
2476 vfprintf_unfiltered (stream
, format
, args
)
2482 struct cleanup
*old_cleanups
;
2484 vasprintf (&linebuffer
, format
, args
);
2485 if (linebuffer
== NULL
)
2487 fputs_unfiltered ("\ngdb: virtual memory exhausted.\n", gdb_stderr
);
2490 old_cleanups
= make_cleanup (free
, linebuffer
);
2491 fputs_unfiltered (linebuffer
, stream
);
2492 do_cleanups (old_cleanups
);
2496 vprintf_filtered (format
, args
)
2500 vfprintf_maybe_filtered (gdb_stdout
, format
, args
, 1);
2504 vprintf_unfiltered (format
, args
)
2508 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2512 fprintf_filtered (GDB_FILE
* stream
, const char *format
,...)
2515 va_start (args
, format
);
2516 vfprintf_filtered (stream
, format
, args
);
2521 fprintf_unfiltered (GDB_FILE
* stream
, const char *format
,...)
2524 va_start (args
, format
);
2525 vfprintf_unfiltered (stream
, format
, args
);
2529 /* Like fprintf_filtered, but prints its result indented.
2530 Called as fprintfi_filtered (spaces, stream, format, ...); */
2533 fprintfi_filtered (int spaces
, GDB_FILE
* stream
, const char *format
,...)
2536 va_start (args
, format
);
2537 print_spaces_filtered (spaces
, stream
);
2539 vfprintf_filtered (stream
, format
, args
);
2545 printf_filtered (const char *format
,...)
2548 va_start (args
, format
);
2549 vfprintf_filtered (gdb_stdout
, format
, args
);
2555 printf_unfiltered (const char *format
,...)
2558 va_start (args
, format
);
2559 vfprintf_unfiltered (gdb_stdout
, format
, args
);
2563 /* Like printf_filtered, but prints it's result indented.
2564 Called as printfi_filtered (spaces, format, ...); */
2567 printfi_filtered (int spaces
, const char *format
,...)
2570 va_start (args
, format
);
2571 print_spaces_filtered (spaces
, gdb_stdout
);
2572 vfprintf_filtered (gdb_stdout
, format
, args
);
2576 /* Easy -- but watch out!
2578 This routine is *not* a replacement for puts()! puts() appends a newline.
2579 This one doesn't, and had better not! */
2582 puts_filtered (string
)
2585 fputs_filtered (string
, gdb_stdout
);
2589 puts_unfiltered (string
)
2592 fputs_unfiltered (string
, gdb_stdout
);
2595 /* Return a pointer to N spaces and a null. The pointer is good
2596 until the next call to here. */
2602 static char *spaces
= 0;
2603 static int max_spaces
= -1;
2609 spaces
= (char *) xmalloc (n
+ 1);
2610 for (t
= spaces
+ n
; t
!= spaces
;)
2616 return spaces
+ max_spaces
- n
;
2619 /* Print N spaces. */
2621 print_spaces_filtered (n
, stream
)
2625 fputs_filtered (n_spaces (n
), stream
);
2628 /* C++ demangler stuff. */
2630 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
2631 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
2632 If the name is not mangled, or the language for the name is unknown, or
2633 demangling is off, the name is printed in its "raw" form. */
2636 fprintf_symbol_filtered (stream
, name
, lang
, arg_mode
)
2646 /* If user wants to see raw output, no problem. */
2649 fputs_filtered (name
, stream
);
2655 case language_cplus
:
2656 demangled
= cplus_demangle (name
, arg_mode
);
2659 demangled
= cplus_demangle (name
, arg_mode
| DMGL_JAVA
);
2661 case language_chill
:
2662 demangled
= chill_demangle (name
);
2668 fputs_filtered (demangled
? demangled
: name
, stream
);
2669 if (demangled
!= NULL
)
2677 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
2678 differences in whitespace. Returns 0 if they match, non-zero if they
2679 don't (slightly different than strcmp()'s range of return values).
2681 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
2682 This "feature" is useful when searching for matching C++ function names
2683 (such as if the user types 'break FOO', where FOO is a mangled C++
2687 strcmp_iw (string1
, string2
)
2688 const char *string1
;
2689 const char *string2
;
2691 while ((*string1
!= '\0') && (*string2
!= '\0'))
2693 while (isspace (*string1
))
2697 while (isspace (*string2
))
2701 if (*string1
!= *string2
)
2705 if (*string1
!= '\0')
2711 return (*string1
!= '\0' && *string1
!= '(') || (*string2
!= '\0');
2717 ** Answer whether string_to_compare is a full or partial match to
2718 ** template_string. The partial match must be in sequence starting
2722 subset_compare (string_to_compare
, template_string
)
2723 char *string_to_compare
;
2724 char *template_string
;
2727 if (template_string
!= (char *) NULL
&& string_to_compare
!= (char *) NULL
&&
2728 strlen (string_to_compare
) <= strlen (template_string
))
2729 match
= (strncmp (template_string
,
2731 strlen (string_to_compare
)) == 0);
2738 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2740 pagination_on_command (arg
, from_tty
)
2744 pagination_enabled
= 1;
2747 static void pagination_on_command
PARAMS ((char *arg
, int from_tty
));
2749 pagination_off_command (arg
, from_tty
)
2753 pagination_enabled
= 0;
2760 struct cmd_list_element
*c
;
2762 c
= add_set_cmd ("width", class_support
, var_uinteger
,
2763 (char *) &chars_per_line
,
2764 "Set number of characters gdb thinks are in a line.",
2766 add_show_from_set (c
, &showlist
);
2767 c
->function
.sfunc
= set_width_command
;
2770 (add_set_cmd ("height", class_support
,
2771 var_uinteger
, (char *) &lines_per_page
,
2772 "Set number of lines gdb thinks are in a page.", &setlist
),
2777 /* If the output is not a terminal, don't paginate it. */
2778 if (!GDB_FILE_ISATTY (gdb_stdout
))
2779 lines_per_page
= UINT_MAX
;
2781 set_width_command ((char *) NULL
, 0, c
);
2784 (add_set_cmd ("demangle", class_support
, var_boolean
,
2786 "Set demangling of encoded C++ names when displaying symbols.",
2791 (add_set_cmd ("pagination", class_support
,
2792 var_boolean
, (char *) &pagination_enabled
,
2793 "Set state of pagination.", &setlist
),
2797 add_com ("am", class_support
, pagination_on_command
,
2798 "Enable pagination");
2799 add_com ("sm", class_support
, pagination_off_command
,
2800 "Disable pagination");
2804 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
2805 (char *) &sevenbit_strings
,
2806 "Set printing of 8-bit characters in strings as \\nnn.",
2811 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
2812 (char *) &asm_demangle
,
2813 "Set demangling of C++ names in disassembly listings.",
2818 /* Machine specific function to handle SIGWINCH signal. */
2820 #ifdef SIGWINCH_HANDLER_BODY
2821 SIGWINCH_HANDLER_BODY
2824 /* Support for converting target fp numbers into host DOUBLEST format. */
2826 /* XXX - This code should really be in libiberty/floatformat.c, however
2827 configuration issues with libiberty made this very difficult to do in the
2830 #include "floatformat.h"
2831 #include <math.h> /* ldexp */
2833 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
2834 going to bother with trying to muck around with whether it is defined in
2835 a system header, what we do if not, etc. */
2836 #define FLOATFORMAT_CHAR_BIT 8
2838 static unsigned long get_field
PARAMS ((unsigned char *,
2839 enum floatformat_byteorders
,
2844 /* Extract a field which starts at START and is LEN bytes long. DATA and
2845 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
2846 static unsigned long
2847 get_field (data
, order
, total_len
, start
, len
)
2848 unsigned char *data
;
2849 enum floatformat_byteorders order
;
2850 unsigned int total_len
;
2854 unsigned long result
;
2855 unsigned int cur_byte
;
2858 /* Start at the least significant part of the field. */
2859 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
2860 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2861 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
2863 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
2864 result
= *(data
+ cur_byte
) >> (-cur_bitshift
);
2865 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2866 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2871 /* Move towards the most significant part of the field. */
2872 while (cur_bitshift
< len
)
2874 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
2875 /* This is the last byte; zero out the bits which are not part of
2878 (*(data
+ cur_byte
) & ((1 << (len
- cur_bitshift
)) - 1))
2881 result
|= *(data
+ cur_byte
) << cur_bitshift
;
2882 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
2883 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
2891 /* Convert from FMT to a DOUBLEST.
2892 FROM is the address of the extended float.
2893 Store the DOUBLEST in *TO. */
2896 floatformat_to_doublest (fmt
, from
, to
)
2897 const struct floatformat
*fmt
;
2901 unsigned char *ufrom
= (unsigned char *) from
;
2905 unsigned int mant_bits
, mant_off
;
2907 int special_exponent
; /* It's a NaN, denorm or zero */
2909 /* If the mantissa bits are not contiguous from one end of the
2910 mantissa to the other, we need to make a private copy of the
2911 source bytes that is in the right order since the unpacking
2912 algorithm assumes that the bits are contiguous.
2914 Swap the bytes individually rather than accessing them through
2915 "long *" since we have no guarantee that they start on a long
2916 alignment, and also sizeof(long) for the host could be different
2917 than sizeof(long) for the target. FIXME: Assumes sizeof(long)
2918 for the target is 4. */
2920 if (fmt
->byteorder
== floatformat_littlebyte_bigword
)
2922 static unsigned char *newfrom
;
2923 unsigned char *swapin
, *swapout
;
2926 longswaps
= fmt
->totalsize
/ FLOATFORMAT_CHAR_BIT
;
2929 if (newfrom
== NULL
)
2931 newfrom
= (unsigned char *) xmalloc (fmt
->totalsize
);
2936 while (longswaps
-- > 0)
2938 /* This is ugly, but efficient */
2939 *swapout
++ = swapin
[4];
2940 *swapout
++ = swapin
[5];
2941 *swapout
++ = swapin
[6];
2942 *swapout
++ = swapin
[7];
2943 *swapout
++ = swapin
[0];
2944 *swapout
++ = swapin
[1];
2945 *swapout
++ = swapin
[2];
2946 *swapout
++ = swapin
[3];
2951 exponent
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2952 fmt
->exp_start
, fmt
->exp_len
);
2953 /* Note that if exponent indicates a NaN, we can't really do anything useful
2954 (not knowing if the host has NaN's, or how to build one). So it will
2955 end up as an infinity or something close; that is OK. */
2957 mant_bits_left
= fmt
->man_len
;
2958 mant_off
= fmt
->man_start
;
2961 special_exponent
= exponent
== 0 || exponent
== fmt
->exp_nan
;
2963 /* Don't bias zero's, denorms or NaNs. */
2964 if (!special_exponent
)
2965 exponent
-= fmt
->exp_bias
;
2967 /* Build the result algebraically. Might go infinite, underflow, etc;
2970 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
2971 increment the exponent by one to account for the integer bit. */
2973 if (!special_exponent
)
2975 if (fmt
->intbit
== floatformat_intbit_no
)
2976 dto
= ldexp (1.0, exponent
);
2981 while (mant_bits_left
> 0)
2983 mant_bits
= min (mant_bits_left
, 32);
2985 mant
= get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
,
2986 mant_off
, mant_bits
);
2988 dto
+= ldexp ((double) mant
, exponent
- mant_bits
);
2989 exponent
-= mant_bits
;
2990 mant_off
+= mant_bits
;
2991 mant_bits_left
-= mant_bits
;
2994 /* Negate it if negative. */
2995 if (get_field (ufrom
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1))
3000 static void put_field
PARAMS ((unsigned char *, enum floatformat_byteorders
,
3006 /* Set a field which starts at START and is LEN bytes long. DATA and
3007 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
3009 put_field (data
, order
, total_len
, start
, len
, stuff_to_put
)
3010 unsigned char *data
;
3011 enum floatformat_byteorders order
;
3012 unsigned int total_len
;
3015 unsigned long stuff_to_put
;
3017 unsigned int cur_byte
;
3020 /* Start at the least significant part of the field. */
3021 cur_byte
= (start
+ len
) / FLOATFORMAT_CHAR_BIT
;
3022 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
3023 cur_byte
= (total_len
/ FLOATFORMAT_CHAR_BIT
) - cur_byte
- 1;
3025 ((start
+ len
) % FLOATFORMAT_CHAR_BIT
) - FLOATFORMAT_CHAR_BIT
;
3026 *(data
+ cur_byte
) &=
3027 ~(((1 << ((start
+ len
) % FLOATFORMAT_CHAR_BIT
)) - 1) << (-cur_bitshift
));
3028 *(data
+ cur_byte
) |=
3029 (stuff_to_put
& ((1 << FLOATFORMAT_CHAR_BIT
) - 1)) << (-cur_bitshift
);
3030 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
3031 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
3036 /* Move towards the most significant part of the field. */
3037 while (cur_bitshift
< len
)
3039 if (len
- cur_bitshift
< FLOATFORMAT_CHAR_BIT
)
3041 /* This is the last byte. */
3042 *(data
+ cur_byte
) &=
3043 ~((1 << (len
- cur_bitshift
)) - 1);
3044 *(data
+ cur_byte
) |= (stuff_to_put
>> cur_bitshift
);
3047 *(data
+ cur_byte
) = ((stuff_to_put
>> cur_bitshift
)
3048 & ((1 << FLOATFORMAT_CHAR_BIT
) - 1));
3049 cur_bitshift
+= FLOATFORMAT_CHAR_BIT
;
3050 if (order
== floatformat_little
|| order
== floatformat_littlebyte_bigword
)
3057 #ifdef HAVE_LONG_DOUBLE
3058 /* Return the fractional part of VALUE, and put the exponent of VALUE in *EPTR.
3059 The range of the returned value is >= 0.5 and < 1.0. This is equivalent to
3060 frexp, but operates on the long double data type. */
3062 static long double ldfrexp
PARAMS ((long double value
, int *eptr
));
3065 ldfrexp (value
, eptr
)
3072 /* Unfortunately, there are no portable functions for extracting the exponent
3073 of a long double, so we have to do it iteratively by multiplying or dividing
3074 by two until the fraction is between 0.5 and 1.0. */
3082 if (value
>= tmp
) /* Value >= 1.0 */
3083 while (value
>= tmp
)
3088 else if (value
!= 0.0l) /* Value < 1.0 and > 0.0 */
3102 #endif /* HAVE_LONG_DOUBLE */
3105 /* The converse: convert the DOUBLEST *FROM to an extended float
3106 and store where TO points. Neither FROM nor TO have any alignment
3110 floatformat_from_doublest (fmt
, from
, to
)
3111 CONST
struct floatformat
*fmt
;
3118 unsigned int mant_bits
, mant_off
;
3120 unsigned char *uto
= (unsigned char *) to
;
3122 memcpy (&dfrom
, from
, sizeof (dfrom
));
3123 memset (uto
, 0, fmt
->totalsize
/ FLOATFORMAT_CHAR_BIT
);
3125 return; /* Result is zero */
3126 if (dfrom
!= dfrom
) /* Result is NaN */
3129 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3130 fmt
->exp_len
, fmt
->exp_nan
);
3131 /* Be sure it's not infinity, but NaN value is irrel */
3132 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3137 /* If negative, set the sign bit. */
3140 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->sign_start
, 1, 1);
3144 if (dfrom
+ dfrom
== dfrom
&& dfrom
!= 0.0) /* Result is Infinity */
3146 /* Infinity exponent is same as NaN's. */
3147 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
,
3148 fmt
->exp_len
, fmt
->exp_nan
);
3149 /* Infinity mantissa is all zeroes. */
3150 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->man_start
,
3155 #ifdef HAVE_LONG_DOUBLE
3156 mant
= ldfrexp (dfrom
, &exponent
);
3158 mant
= frexp (dfrom
, &exponent
);
3161 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
, fmt
->exp_start
, fmt
->exp_len
,
3162 exponent
+ fmt
->exp_bias
- 1);
3164 mant_bits_left
= fmt
->man_len
;
3165 mant_off
= fmt
->man_start
;
3166 while (mant_bits_left
> 0)
3168 unsigned long mant_long
;
3169 mant_bits
= mant_bits_left
< 32 ? mant_bits_left
: 32;
3171 mant
*= 4294967296.0;
3172 mant_long
= (unsigned long) mant
;
3175 /* If the integer bit is implicit, then we need to discard it.
3176 If we are discarding a zero, we should be (but are not) creating
3177 a denormalized number which means adjusting the exponent
3179 if (mant_bits_left
== fmt
->man_len
3180 && fmt
->intbit
== floatformat_intbit_no
)
3188 /* The bits we want are in the most significant MANT_BITS bits of
3189 mant_long. Move them to the least significant. */
3190 mant_long
>>= 32 - mant_bits
;
3193 put_field (uto
, fmt
->byteorder
, fmt
->totalsize
,
3194 mant_off
, mant_bits
, mant_long
);
3195 mant_off
+= mant_bits
;
3196 mant_bits_left
-= mant_bits
;
3198 if (fmt
->byteorder
== floatformat_littlebyte_bigword
)
3201 unsigned char *swaplow
= uto
;
3202 unsigned char *swaphigh
= uto
+ 4;
3205 for (count
= 0; count
< 4; count
++)
3208 *swaplow
++ = *swaphigh
;
3214 /* temporary storage using circular buffer */
3220 static char buf
[NUMCELLS
][CELLSIZE
];
3221 static int cell
= 0;
3222 if (++cell
>= NUMCELLS
)
3227 /* print routines to handle variable size regs, etc.
3229 FIXME: Note that t_addr is a bfd_vma, which is currently either an
3230 unsigned long or unsigned long long, determined at configure time.
3231 If t_addr is an unsigned long long and sizeof (unsigned long long)
3232 is greater than sizeof (unsigned long), then I believe this code will
3233 probably lose, at least for little endian machines. I believe that
3234 it would also be better to eliminate the switch on the absolute size
3235 of t_addr and replace it with a sequence of if statements that compare
3236 sizeof t_addr with sizeof the various types and do the right thing,
3237 which includes knowing whether or not the host supports long long.
3245 return (TARGET_PTR_BIT
/ 8 * 2);
3249 /* eliminate warning from compiler on 32-bit systems */
3250 static int thirty_two
= 32;
3253 paddr (CORE_ADDR addr
)
3255 char *paddr_str
= get_cell ();
3256 switch (TARGET_PTR_BIT
/ 8)
3259 sprintf (paddr_str
, "%08lx%08lx",
3260 (unsigned long) (addr
>> thirty_two
), (unsigned long) (addr
& 0xffffffff));
3263 sprintf (paddr_str
, "%08lx", (unsigned long) addr
);
3266 sprintf (paddr_str
, "%04x", (unsigned short) (addr
& 0xffff));
3269 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3275 paddr_nz (CORE_ADDR addr
)
3277 char *paddr_str
= get_cell ();
3278 switch (TARGET_PTR_BIT
/ 8)
3282 unsigned long high
= (unsigned long) (addr
>> thirty_two
);
3284 sprintf (paddr_str
, "%lx", (unsigned long) (addr
& 0xffffffff));
3286 sprintf (paddr_str
, "%lx%08lx",
3287 high
, (unsigned long) (addr
& 0xffffffff));
3291 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3294 sprintf (paddr_str
, "%x", (unsigned short) (addr
& 0xffff));
3297 sprintf (paddr_str
, "%lx", (unsigned long) addr
);
3303 decimal2str (char *paddr_str
, char *sign
, ULONGEST addr
)
3305 /* steal code from valprint.c:print_decimal(). Should this worry
3306 about the real size of addr as the above does? */
3307 unsigned long temp
[3];
3311 temp
[i
] = addr
% (1000 * 1000 * 1000);
3312 addr
/= (1000 * 1000 * 1000);
3315 while (addr
!= 0 && i
< (sizeof (temp
) / sizeof (temp
[0])));
3319 sprintf (paddr_str
, "%s%lu",
3323 sprintf (paddr_str
, "%s%lu%09lu",
3324 sign
, temp
[1], temp
[0]);
3327 sprintf (paddr_str
, "%s%lu%09lu%09lu",
3328 sign
, temp
[2], temp
[1], temp
[0]);
3336 paddr_u (CORE_ADDR addr
)
3338 char *paddr_str
= get_cell ();
3339 decimal2str (paddr_str
, "", addr
);
3344 paddr_d (LONGEST addr
)
3346 char *paddr_str
= get_cell ();
3348 decimal2str (paddr_str
, "-", -addr
);
3350 decimal2str (paddr_str
, "", addr
);
3358 char *preg_str
= get_cell ();
3359 switch (sizeof (t_reg
))
3362 sprintf (preg_str
, "%08lx%08lx",
3363 (unsigned long) (reg
>> thirty_two
), (unsigned long) (reg
& 0xffffffff));
3366 sprintf (preg_str
, "%08lx", (unsigned long) reg
);
3369 sprintf (preg_str
, "%04x", (unsigned short) (reg
& 0xffff));
3372 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3381 char *preg_str
= get_cell ();
3382 switch (sizeof (t_reg
))
3386 unsigned long high
= (unsigned long) (reg
>> thirty_two
);
3388 sprintf (preg_str
, "%lx", (unsigned long) (reg
& 0xffffffff));
3390 sprintf (preg_str
, "%lx%08lx",
3391 high
, (unsigned long) (reg
& 0xffffffff));
3395 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3398 sprintf (preg_str
, "%x", (unsigned short) (reg
& 0xffff));
3401 sprintf (preg_str
, "%lx", (unsigned long) reg
);
3406 /* Helper functions for INNER_THAN */
3408 core_addr_lessthan (lhs
, rhs
)
3416 core_addr_greaterthan (lhs
, rhs
)