895a62a490694acf2c8a1a93b6e46c14ce2809e7
1 /* General utility routines for GDB, the GNU debugger.
2 Copyright 1986, 1989, 1990, 1991, 1992 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #if !defined(__GO32__)
22 #include <sys/ioctl.h>
23 #include <sys/param.h>
36 #include "expression.h"
39 /* Prototypes for local functions */
41 #if !defined (NO_MALLOC_CHECK)
44 malloc_botch
PARAMS ((void));
46 #endif /* NO_MALLOC_CHECK */
49 fatal_dump_core (); /* Can't prototype with <varargs.h> usage... */
52 prompt_for_continue
PARAMS ((void));
55 set_width_command
PARAMS ((char *, int, struct cmd_list_element
*));
57 /* If this definition isn't overridden by the header files, assume
58 that isatty and fileno exist on this system. */
60 #define ISATTY(FP) (isatty (fileno (FP)))
63 /* Chain of cleanup actions established with make_cleanup,
64 to be executed if an error happens. */
66 static struct cleanup
*cleanup_chain
;
68 /* Nonzero means a quit has been requested. */
72 /* Nonzero means quit immediately if Control-C is typed now,
73 rather than waiting until QUIT is executed. */
77 /* Nonzero means that encoded C++ names should be printed out in their
78 C++ form rather than raw. */
82 /* Nonzero means that encoded C++ names should be printed out in their
83 C++ form even in assembler language displays. If this is set, but
84 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
88 /* Nonzero means that strings with character values >0x7F should be printed
89 as octal escapes. Zero means just print the value (e.g. it's an
90 international character, and the terminal or window can cope.) */
92 int sevenbit_strings
= 0;
94 /* String to be printed before error messages, if any. */
96 char *error_pre_print
;
97 char *warning_pre_print
= "\nwarning: ";
99 /* Add a new cleanup to the cleanup_chain,
100 and return the previous chain pointer
101 to be passed later to do_cleanups or discard_cleanups.
102 Args are FUNCTION to clean up with, and ARG to pass to it. */
105 make_cleanup (function
, arg
)
106 void (*function
) PARAMS ((PTR
));
109 register struct cleanup
*new
110 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
111 register struct cleanup
*old_chain
= cleanup_chain
;
113 new->next
= cleanup_chain
;
114 new->function
= function
;
121 /* Discard cleanups and do the actions they describe
122 until we get back to the point OLD_CHAIN in the cleanup_chain. */
125 do_cleanups (old_chain
)
126 register struct cleanup
*old_chain
;
128 register struct cleanup
*ptr
;
129 while ((ptr
= cleanup_chain
) != old_chain
)
131 cleanup_chain
= ptr
->next
; /* Do this first incase recursion */
132 (*ptr
->function
) (ptr
->arg
);
137 /* Discard cleanups, not doing the actions they describe,
138 until we get back to the point OLD_CHAIN in the cleanup_chain. */
141 discard_cleanups (old_chain
)
142 register struct cleanup
*old_chain
;
144 register struct cleanup
*ptr
;
145 while ((ptr
= cleanup_chain
) != old_chain
)
147 cleanup_chain
= ptr
->next
;
152 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
156 struct cleanup
*old_chain
= cleanup_chain
;
162 /* Restore the cleanup chain from a previously saved chain. */
164 restore_cleanups (chain
)
165 struct cleanup
*chain
;
167 cleanup_chain
= chain
;
170 /* This function is useful for cleanups.
174 old_chain = make_cleanup (free_current_contents, &foo);
176 to arrange to free the object thus allocated. */
179 free_current_contents (location
)
185 /* Provide a known function that does nothing, to use as a base for
186 for a possibly long chain of cleanups. This is useful where we
187 use the cleanup chain for handling normal cleanups as well as dealing
188 with cleanups that need to be done as a result of a call to error().
189 In such cases, we may not be certain where the first cleanup is, unless
190 we have a do-nothing one to always use as the base. */
200 /* Provide a hook for modules wishing to print their own warning messages
201 to set up the terminal state in a compatible way, without them having
202 to import all the target_<...> macros. */
207 target_terminal_ours ();
208 wrap_here(""); /* Force out any buffered output */
212 /* Print a warning message.
213 The first argument STRING is the warning message, used as a fprintf string,
214 and the remaining args are passed as arguments to it.
215 The primary difference between warnings and errors is that a warning
216 does not force the return to command level. */
227 target_terminal_ours ();
228 wrap_here(""); /* Force out any buffered output */
230 if (warning_pre_print
)
231 fprintf (stderr
, warning_pre_print
);
232 string
= va_arg (args
, char *);
233 vfprintf (stderr
, string
, args
);
234 fprintf (stderr
, "\n");
238 /* Print an error message and return to command level.
239 The first argument STRING is the error message, used as a fprintf string,
240 and the remaining args are passed as arguments to it. */
251 target_terminal_ours ();
252 wrap_here(""); /* Force out any buffered output */
255 fprintf_filtered (stderr
, error_pre_print
);
256 string
= va_arg (args
, char *);
257 vfprintf_filtered (stderr
, string
, args
);
258 fprintf_filtered (stderr
, "\n");
260 return_to_top_level ();
263 /* Print an error message and exit reporting failure.
264 This is for a error that we cannot continue from.
265 The arguments are printed a la printf.
267 This function cannot be declared volatile (NORETURN) in an
268 ANSI environment because exit() is not declared volatile. */
279 string
= va_arg (args
, char *);
280 fprintf (stderr
, "\ngdb: ");
281 vfprintf (stderr
, string
, args
);
282 fprintf (stderr
, "\n");
287 /* Print an error message and exit, dumping core.
288 The arguments are printed a la printf (). */
292 fatal_dump_core (va_alist
)
299 string
= va_arg (args
, char *);
300 /* "internal error" is always correct, since GDB should never dump
301 core, no matter what the input. */
302 fprintf (stderr
, "\ngdb internal error: ");
303 vfprintf (stderr
, string
, args
);
304 fprintf (stderr
, "\n");
307 signal (SIGQUIT
, SIG_DFL
);
308 kill (getpid (), SIGQUIT
);
309 /* We should never get here, but just in case... */
313 /* The strerror() function can return NULL for errno values that are
314 out of range. Provide a "safe" version that always returns a
318 safe_strerror (errnum
)
324 if ((msg
= strerror (errnum
)) == NULL
)
326 sprintf (buf
, "(undocumented errno %d)", errnum
);
332 /* The strsignal() function can return NULL for signal values that are
333 out of range. Provide a "safe" version that always returns a
337 safe_strsignal (signo
)
343 if ((msg
= strsignal (signo
)) == NULL
)
345 sprintf (buf
, "(undocumented signal %d)", signo
);
352 /* Print the system error message for errno, and also mention STRING
353 as the file name for which the error was encountered.
354 Then return to command level. */
357 perror_with_name (string
)
363 err
= safe_strerror (errno
);
364 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
365 strcpy (combined
, string
);
366 strcat (combined
, ": ");
367 strcat (combined
, err
);
369 /* I understand setting these is a matter of taste. Still, some people
370 may clear errno but not know about bfd_error. Doing this here is not
372 bfd_error
= no_error
;
375 error ("%s.", combined
);
378 /* Print the system error message for ERRCODE, and also mention STRING
379 as the file name for which the error was encountered. */
382 print_sys_errmsg (string
, errcode
)
389 err
= safe_strerror (errcode
);
390 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
391 strcpy (combined
, string
);
392 strcat (combined
, ": ");
393 strcat (combined
, err
);
395 fprintf (stderr
, "%s.\n", combined
);
398 /* Control C eventually causes this to be called, at a convenient time. */
403 target_terminal_ours ();
404 wrap_here ((char *)0); /* Force out any pending output */
405 #if !defined(__GO32__)
407 ioctl (fileno (stdout
), TCFLSH
, 1);
408 #else /* not HAVE_TERMIO */
409 ioctl (fileno (stdout
), TIOCFLUSH
, 0);
410 #endif /* not HAVE_TERMIO */
414 error ("Quit (expect signal %d when inferior is resumed)", SIGINT
);
415 #endif /* TIOCGPGRP */
424 /* In the absence of signals, poll keyboard for a quit.
425 Called from #define QUIT pollquit() in xm-go32.h. */
443 /* Control C comes here */
452 /* Restore the signal handler. */
453 signal (signo
, request_quit
);
461 /* Memory management stuff (malloc friends). */
463 #if defined (NO_MMALLOC)
470 return (malloc (size
));
474 mrealloc (md
, ptr
, size
)
479 if (ptr
== 0) /* Guard against old realloc's */
480 return malloc (size
);
482 return realloc (ptr
, size
);
493 #endif /* NO_MMALLOC */
495 #if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
503 #else /* have mmalloc and want corruption checking */
508 fatal_dump_core ("Memory corruption");
511 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
512 by MD, to detect memory corruption. Note that MD may be NULL to specify
513 the default heap that grows via sbrk.
515 Note that for freshly created regions, we must call mmcheck prior to any
516 mallocs in the region. Otherwise, any region which was allocated prior to
517 installing the checking hooks, which is later reallocated or freed, will
518 fail the checks! The mmcheck function only allows initial hooks to be
519 installed before the first mmalloc. However, anytime after we have called
520 mmcheck the first time to install the checking hooks, we can call it again
521 to update the function pointer to the memory corruption handler.
523 Returns zero on failure, non-zero on success. */
529 if (!mmcheck (md
, malloc_botch
))
531 warning ("internal error: failed to install memory consistency checks");
537 #endif /* Have mmalloc and want corruption checking */
539 /* Called when a memory allocation fails, with the number of bytes of
540 memory requested in SIZE. */
548 fatal ("virtual memory exhausted: can't allocate %ld bytes.", size
);
552 fatal ("virtual memory exhausted.");
556 /* Like mmalloc but get error if no storage available, and protect against
557 the caller wanting to allocate zero bytes. Whether to return NULL for
558 a zero byte request, or translate the request into a request for one
559 byte of zero'd storage, is a religious issue. */
572 else if ((val
= mmalloc (md
, size
)) == NULL
)
579 /* Like mrealloc but get error if no storage available. */
582 xmrealloc (md
, ptr
, size
)
591 val
= mrealloc (md
, ptr
, size
);
595 val
= mmalloc (md
, size
);
604 /* Like malloc but get error if no storage available, and protect against
605 the caller wanting to allocate zero bytes. */
611 return (xmmalloc ((void *) NULL
, size
));
614 /* Like mrealloc but get error if no storage available. */
621 return (xmrealloc ((void *) NULL
, ptr
, size
));
625 /* My replacement for the read system call.
626 Used like `read' but keeps going if `read' returns too soon. */
629 myread (desc
, addr
, len
)
639 val
= read (desc
, addr
, len
);
650 /* Make a copy of the string at PTR with SIZE characters
651 (and add a null character at the end in the copy).
652 Uses malloc to get the space. Returns the address of the copy. */
655 savestring (ptr
, size
)
659 register char *p
= (char *) xmalloc (size
+ 1);
660 memcpy (p
, ptr
, size
);
666 msavestring (md
, ptr
, size
)
671 register char *p
= (char *) xmmalloc (md
, size
+ 1);
672 memcpy (p
, ptr
, size
);
677 /* The "const" is so it compiles under DGUX (which prototypes strsave
678 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
679 Doesn't real strsave return NULL if out of memory? */
684 return savestring (ptr
, strlen (ptr
));
692 return (msavestring (md
, ptr
, strlen (ptr
)));
696 print_spaces (n
, file
)
704 /* Ask user a y-or-n question and return 1 iff answer is yes.
705 Takes three args which are given to printf to print the question.
706 The first, a control string, should end in "? ".
707 It should not say how to answer, because we do that. */
719 /* Automatically answer "yes" if input is not from a terminal. */
720 if (!input_from_terminal_p ())
725 wrap_here (""); /* Flush any buffered output */
728 ctlstr
= va_arg (args
, char *);
729 vfprintf_filtered (stdout
, ctlstr
, args
);
731 printf_filtered ("(y or n) ");
733 answer
= fgetc (stdin
);
734 clearerr (stdin
); /* in case of C-d */
735 if (answer
== EOF
) /* C-d */
737 if (answer
!= '\n') /* Eat rest of input line, to EOF or newline */
740 ans2
= fgetc (stdin
);
743 while (ans2
!= EOF
&& ans2
!= '\n');
750 printf_filtered ("Please answer y or n.\n");
755 /* Parse a C escape sequence. STRING_PTR points to a variable
756 containing a pointer to the string to parse. That pointer
757 should point to the character after the \. That pointer
758 is updated past the characters we use. The value of the
759 escape sequence is returned.
761 A negative value means the sequence \ newline was seen,
762 which is supposed to be equivalent to nothing at all.
764 If \ is followed by a null character, we return a negative
765 value and leave the string pointer pointing at the null character.
767 If \ is followed by 000, we return 0 and leave the string pointer
768 after the zeros. A value of 0 does not mean end of string. */
771 parse_escape (string_ptr
)
774 register int c
= *(*string_ptr
)++;
778 return 007; /* Bell (alert) char */
781 case 'e': /* Escape character */
799 c
= *(*string_ptr
)++;
801 c
= parse_escape (string_ptr
);
804 return (c
& 0200) | (c
& 037);
815 register int i
= c
- '0';
816 register int count
= 0;
819 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
837 /* Print the character C on STREAM as part of the contents of a literal
838 string whose delimiter is QUOTER. Note that this routine should only
839 be call for printing things which are independent of the language
840 of the program being debugged. */
843 gdb_printchar (c
, stream
, quoter
)
849 c
&= 0xFF; /* Avoid sign bit follies */
851 if ( c
< 0x20 || /* Low control chars */
852 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
853 (sevenbit_strings
&& c
>= 0x80)) { /* high order bit set */
857 fputs_filtered ("\\n", stream
);
860 fputs_filtered ("\\b", stream
);
863 fputs_filtered ("\\t", stream
);
866 fputs_filtered ("\\f", stream
);
869 fputs_filtered ("\\r", stream
);
872 fputs_filtered ("\\e", stream
);
875 fputs_filtered ("\\a", stream
);
878 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
882 if (c
== '\\' || c
== quoter
)
883 fputs_filtered ("\\", stream
);
884 fprintf_filtered (stream
, "%c", c
);
888 /* Number of lines per page or UINT_MAX if paging is disabled. */
889 static unsigned int lines_per_page
;
890 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
891 static unsigned int chars_per_line
;
892 /* Current count of lines printed on this page, chars on this line. */
893 static unsigned int lines_printed
, chars_printed
;
895 /* Buffer and start column of buffered text, for doing smarter word-
896 wrapping. When someone calls wrap_here(), we start buffering output
897 that comes through fputs_filtered(). If we see a newline, we just
898 spit it out and forget about the wrap_here(). If we see another
899 wrap_here(), we spit it out and remember the newer one. If we see
900 the end of the line, we spit out a newline, the indent, and then
903 wrap_column is the column number on the screen where wrap_buffer begins.
904 When wrap_column is zero, wrapping is not in effect.
905 wrap_buffer is malloc'd with chars_per_line+2 bytes.
906 When wrap_buffer[0] is null, the buffer is empty.
907 wrap_pointer points into it at the next character to fill.
908 wrap_indent is the string that should be used as indentation if the
911 static char *wrap_buffer
, *wrap_pointer
, *wrap_indent
;
912 static int wrap_column
;
916 set_width_command (args
, from_tty
, c
)
919 struct cmd_list_element
*c
;
923 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
924 wrap_buffer
[0] = '\0';
927 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
928 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
931 /* Wait, so the user can read what's on the screen. Prompt the user
932 to continue by pressing RETURN. */
935 prompt_for_continue ()
939 /* We must do this *before* we call gdb_readline, else it will eventually
940 call us -- thinking that we're trying to print beyond the end of the
942 reinitialize_more_filter ();
945 ignore
= gdb_readline ("---Type <return> to continue---");
950 /* Now we have to do this again, so that GDB will know that it doesn't
951 need to save the ---Type <return>--- line at the top of the screen. */
952 reinitialize_more_filter ();
954 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
957 /* Reinitialize filter; ie. tell it to reset to original values. */
960 reinitialize_more_filter ()
966 /* Indicate that if the next sequence of characters overflows the line,
967 a newline should be inserted here rather than when it hits the end.
968 If INDENT is nonzero, it is a string to be printed to indent the
969 wrapped part on the next line. INDENT must remain accessible until
970 the next call to wrap_here() or until a newline is printed through
973 If the line is already overfull, we immediately print a newline and
974 the indentation, and disable further wrapping.
976 If we don't know the width of lines, but we know the page height,
977 we must not wrap words, but should still keep track of newlines
978 that were explicitly printed.
980 INDENT should not contain tabs, as that
981 will mess up the char count on the next line. FIXME. */
989 *wrap_pointer
= '\0';
990 fputs (wrap_buffer
, stdout
);
992 wrap_pointer
= wrap_buffer
;
993 wrap_buffer
[0] = '\0';
994 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
998 else if (chars_printed
>= chars_per_line
)
1000 puts_filtered ("\n");
1001 puts_filtered (indent
);
1006 wrap_column
= chars_printed
;
1007 wrap_indent
= indent
;
1011 /* Ensure that whatever gets printed next, using the filtered output
1012 commands, starts at the beginning of the line. I.E. if there is
1013 any pending output for the current line, flush it and start a new
1014 line. Otherwise do nothing. */
1019 if (chars_printed
> 0)
1021 puts_filtered ("\n");
1025 /* Like fputs but pause after every screenful, and can wrap at points
1026 other than the final character of a line.
1027 Unlike fputs, fputs_filtered does not return a value.
1028 It is OK for LINEBUFFER to be NULL, in which case just don't print
1031 Note that a longjmp to top level may occur in this routine
1032 (since prompt_for_continue may do so) so this routine should not be
1033 called when cleanups are not in place. */
1036 fputs_filtered (linebuffer
, stream
)
1037 const char *linebuffer
;
1040 const char *lineptr
;
1042 if (linebuffer
== 0)
1045 /* Don't do any filtering if it is disabled. */
1046 if (stream
!= stdout
1047 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
1049 fputs (linebuffer
, stream
);
1053 /* Go through and output each character. Show line extension
1054 when this is necessary; prompt user for new page when this is
1057 lineptr
= linebuffer
;
1060 /* Possible new page. */
1061 if (lines_printed
>= lines_per_page
- 1)
1062 prompt_for_continue ();
1064 while (*lineptr
&& *lineptr
!= '\n')
1066 /* Print a single line. */
1067 if (*lineptr
== '\t')
1070 *wrap_pointer
++ = '\t';
1072 putc ('\t', stream
);
1073 /* Shifting right by 3 produces the number of tab stops
1074 we have already passed, and then adding one and
1075 shifting left 3 advances to the next tab stop. */
1076 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
1082 *wrap_pointer
++ = *lineptr
;
1084 putc (*lineptr
, stream
);
1089 if (chars_printed
>= chars_per_line
)
1091 unsigned int save_chars
= chars_printed
;
1095 /* If we aren't actually wrapping, don't output newline --
1096 if chars_per_line is right, we probably just overflowed
1097 anyway; if it's wrong, let us keep going. */
1099 putc ('\n', stream
);
1101 /* Possible new page. */
1102 if (lines_printed
>= lines_per_page
- 1)
1103 prompt_for_continue ();
1105 /* Now output indentation and wrapped string */
1109 fputs (wrap_indent
, stream
);
1110 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
1111 fputs (wrap_buffer
, stream
); /* and eject it */
1112 /* FIXME, this strlen is what prevents wrap_indent from
1113 containing tabs. However, if we recurse to print it
1114 and count its chars, we risk trouble if wrap_indent is
1115 longer than (the user settable) chars_per_line.
1116 Note also that this can set chars_printed > chars_per_line
1117 if we are printing a long string. */
1118 chars_printed
= strlen (wrap_indent
)
1119 + (save_chars
- wrap_column
);
1120 wrap_pointer
= wrap_buffer
; /* Reset buffer */
1121 wrap_buffer
[0] = '\0';
1122 wrap_column
= 0; /* And disable fancy wrap */
1127 if (*lineptr
== '\n')
1130 wrap_here ((char *)0); /* Spit out chars, cancel further wraps */
1132 putc ('\n', stream
);
1139 /* fputs_demangled attempts to demangle NAME, a symbol in language LANG, using
1140 demangling args ARG_MODE, and print it filtered to STREAM. If the name is
1141 not mangled, or the language for the name is unknown, or demangling is off,
1142 the name is printed in its "raw" form. */
1145 fputs_demangled (name
, stream
, arg_mode
, lang
)
1155 /* If user wants to see raw output, no problem. */
1158 fputs_filtered (name
, stream
);
1164 case language_cplus
:
1165 demangled
= cplus_demangle (name
, arg_mode
);
1167 /* start-sanitize-chill */
1168 case language_chill
:
1169 demangled
= chill_demangle (name
);
1171 /* end-sanitize-chill */
1176 fputs_filtered (demangled
? demangled
: name
, stream
);
1177 if (demangled
!= NULL
)
1185 /* Print a variable number of ARGS using format FORMAT. If this
1186 information is going to put the amount written (since the last call
1187 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
1188 print out a pause message and do a gdb_readline to get the users
1189 permision to continue.
1191 Unlike fprintf, this function does not return a value.
1193 We implement three variants, vfprintf (takes a vararg list and stream),
1194 fprintf (takes a stream to write on), and printf (the usual).
1196 Note that this routine has a restriction that the length of the
1197 final output line must be less than 255 characters *or* it must be
1198 less than twice the size of the format string. This is a very
1199 arbitrary restriction, but it is an internal restriction, so I'll
1200 put it in. This means that the %s format specifier is almost
1201 useless; unless the caller can GUARANTEE that the string is short
1202 enough, fputs_filtered should be used instead.
1204 Note also that a longjmp to top level may occur in this routine
1205 (since prompt_for_continue may do so) so this routine should not be
1206 called when cleanups are not in place. */
1208 #define MIN_LINEBUF 255
1211 vfprintf_filtered (stream
, format
, args
)
1216 char line_buf
[MIN_LINEBUF
+10];
1217 char *linebuffer
= line_buf
;
1220 format_length
= strlen (format
);
1222 /* Reallocate buffer to a larger size if this is necessary. */
1223 if (format_length
* 2 > MIN_LINEBUF
)
1225 linebuffer
= alloca (10 + format_length
* 2);
1228 /* This won't blow up if the restrictions described above are
1230 vsprintf (linebuffer
, format
, args
);
1232 fputs_filtered (linebuffer
, stream
);
1236 vprintf_filtered (format
, args
)
1240 vfprintf_filtered (stdout
, format
, args
);
1245 fprintf_filtered (va_alist
)
1253 stream
= va_arg (args
, FILE *);
1254 format
= va_arg (args
, char *);
1256 /* This won't blow up if the restrictions described above are
1258 vfprintf_filtered (stream
, format
, args
);
1262 /* Like fprintf_filtered, but prints it's result indent.
1263 Called as fprintfi_filtered (spaces, format, arg1, arg2, ...); */
1267 fprintfi_filtered (va_alist
)
1276 spaces
= va_arg (args
, int);
1277 stream
= va_arg (args
, FILE *);
1278 format
= va_arg (args
, char *);
1279 print_spaces_filtered (spaces
, stream
);
1281 /* This won't blow up if the restrictions described above are
1283 vfprintf_filtered (stream
, format
, args
);
1289 printf_filtered (va_alist
)
1296 format
= va_arg (args
, char *);
1298 vfprintf_filtered (stdout
, format
, args
);
1302 /* Like printf_filtered, but prints it's result indented.
1303 Called as printfi_filtered (spaces, format, arg1, arg2, ...); */
1307 printfi_filtered (va_alist
)
1315 spaces
= va_arg (args
, int);
1316 format
= va_arg (args
, char *);
1317 print_spaces_filtered (spaces
, stdout
);
1318 vfprintf_filtered (stdout
, format
, args
);
1322 /* Easy -- but watch out!
1324 This routine is *not* a replacement for puts()! puts() appends a newline.
1325 This one doesn't, and had better not! */
1328 puts_filtered (string
)
1331 fputs_filtered (string
, stdout
);
1334 /* Return a pointer to N spaces and a null. The pointer is good
1335 until the next call to here. */
1341 static char *spaces
;
1342 static int max_spaces
;
1348 spaces
= (char *) xmalloc (n
+1);
1349 for (t
= spaces
+n
; t
!= spaces
;)
1355 return spaces
+ max_spaces
- n
;
1358 /* Print N spaces. */
1360 print_spaces_filtered (n
, stream
)
1364 fputs_filtered (n_spaces (n
), stream
);
1367 /* C++ demangler stuff. */
1369 /* Print NAME on STREAM, demangling if necessary. */
1371 fprint_symbol (stream
, name
)
1375 char *demangled
= NULL
;
1379 /* Lacking a better method of knowing what demangler to use, pick
1380 one appropriate for whatever the current language is. (FIXME) */
1381 switch (current_language
-> la_language
)
1383 case language_cplus
:
1384 demangled
= cplus_demangle (name
, DMGL_PARAMS
| DMGL_ANSI
);
1386 /* start-sanitize-chill */
1387 case language_chill
:
1388 demangled
= chill_demangle (name
);
1390 /* end-sanitize-chill */
1393 if (demangled
== NULL
)
1395 fputs_filtered (name
, stream
);
1399 fputs_filtered (demangled
, stream
);
1404 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
1405 differences in whitespace. Returns 0 if they match, non-zero if they
1406 don't (slightly different than strcmp()'s range of return values).
1408 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
1409 This "feature" is useful when searching for matching C++ function names
1410 (such as if the user types 'break FOO', where FOO is a mangled C++
1414 strcmp_iw (string1
, string2
)
1415 const char *string1
;
1416 const char *string2
;
1418 while ((*string1
!= '\0') && (*string2
!= '\0'))
1420 while (isspace (*string1
))
1424 while (isspace (*string2
))
1428 if (*string1
!= *string2
)
1432 if (*string1
!= '\0')
1438 return (*string1
!= '\0' && *string1
!= '(') || (*string2
!= '\0');
1443 _initialize_utils ()
1445 struct cmd_list_element
*c
;
1447 c
= add_set_cmd ("width", class_support
, var_uinteger
,
1448 (char *)&chars_per_line
,
1449 "Set number of characters gdb thinks are in a line.",
1451 add_show_from_set (c
, &showlist
);
1452 c
->function
.sfunc
= set_width_command
;
1455 (add_set_cmd ("height", class_support
,
1456 var_uinteger
, (char *)&lines_per_page
,
1457 "Set number of lines gdb thinks are in a page.", &setlist
),
1460 /* These defaults will be used if we are unable to get the correct
1461 values from termcap. */
1462 #if defined(__GO32__)
1463 lines_per_page
= ScreenRows();
1464 chars_per_line
= ScreenCols();
1466 lines_per_page
= 24;
1467 chars_per_line
= 80;
1468 /* Initialize the screen height and width from termcap. */
1470 char *termtype
= getenv ("TERM");
1472 /* Positive means success, nonpositive means failure. */
1475 /* 2048 is large enough for all known terminals, according to the
1476 GNU termcap manual. */
1477 char term_buffer
[2048];
1481 status
= tgetent (term_buffer
, termtype
);
1486 val
= tgetnum ("li");
1488 lines_per_page
= val
;
1490 /* The number of lines per page is not mentioned
1491 in the terminal description. This probably means
1492 that paging is not useful (e.g. emacs shell window),
1493 so disable paging. */
1494 lines_per_page
= UINT_MAX
;
1496 val
= tgetnum ("co");
1498 chars_per_line
= val
;
1503 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1505 /* If there is a better way to determine the window size, use it. */
1506 SIGWINCH_HANDLER ();
1509 /* If the output is not a terminal, don't paginate it. */
1510 if (!ISATTY (stdout
))
1511 lines_per_page
= UINT_MAX
;
1513 set_width_command ((char *)NULL
, 0, c
);
1516 (add_set_cmd ("demangle", class_support
, var_boolean
,
1518 "Set demangling of encoded C++ names when displaying symbols.",
1523 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
1524 (char *)&sevenbit_strings
,
1525 "Set printing of 8-bit characters in strings as \\nnn.",
1530 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
1531 (char *)&asm_demangle
,
1532 "Set demangling of C++ names in disassembly listings.",
1537 /* Machine specific function to handle SIGWINCH signal. */
1539 #ifdef SIGWINCH_HANDLER_BODY
1540 SIGWINCH_HANDLER_BODY
This page took 0.084905 seconds and 3 git commands to generate.