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_MMALLOC) || defined (NO_MMALLOC_CHECK)
45 malloc_botch
PARAMS ((void));
47 #endif /* NO_MMALLOC, etc */
50 fatal_dump_core (); /* Can't prototype with <varargs.h> usage... */
53 prompt_for_continue
PARAMS ((void));
56 set_width_command
PARAMS ((char *, int, struct cmd_list_element
*));
58 /* If this definition isn't overridden by the header files, assume
59 that isatty and fileno exist on this system. */
61 #define ISATTY(FP) (isatty (fileno (FP)))
64 /* Chain of cleanup actions established with make_cleanup,
65 to be executed if an error happens. */
67 static struct cleanup
*cleanup_chain
;
69 /* Nonzero means a quit has been requested. */
73 /* Nonzero means quit immediately if Control-C is typed now,
74 rather than waiting until QUIT is executed. */
78 /* Nonzero means that encoded C++ names should be printed out in their
79 C++ form rather than raw. */
83 /* Nonzero means that encoded C++ names should be printed out in their
84 C++ form even in assembler language displays. If this is set, but
85 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
89 /* Nonzero means that strings with character values >0x7F should be printed
90 as octal escapes. Zero means just print the value (e.g. it's an
91 international character, and the terminal or window can cope.) */
93 int sevenbit_strings
= 0;
95 /* String to be printed before error messages, if any. */
97 char *error_pre_print
;
98 char *warning_pre_print
= "\nwarning: ";
100 /* Add a new cleanup to the cleanup_chain,
101 and return the previous chain pointer
102 to be passed later to do_cleanups or discard_cleanups.
103 Args are FUNCTION to clean up with, and ARG to pass to it. */
106 make_cleanup (function
, arg
)
107 void (*function
) PARAMS ((PTR
));
110 register struct cleanup
*new
111 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
112 register struct cleanup
*old_chain
= cleanup_chain
;
114 new->next
= cleanup_chain
;
115 new->function
= function
;
122 /* Discard cleanups and do the actions they describe
123 until we get back to the point OLD_CHAIN in the cleanup_chain. */
126 do_cleanups (old_chain
)
127 register struct cleanup
*old_chain
;
129 register struct cleanup
*ptr
;
130 while ((ptr
= cleanup_chain
) != old_chain
)
132 cleanup_chain
= ptr
->next
; /* Do this first incase recursion */
133 (*ptr
->function
) (ptr
->arg
);
138 /* Discard cleanups, not doing the actions they describe,
139 until we get back to the point OLD_CHAIN in the cleanup_chain. */
142 discard_cleanups (old_chain
)
143 register struct cleanup
*old_chain
;
145 register struct cleanup
*ptr
;
146 while ((ptr
= cleanup_chain
) != old_chain
)
148 cleanup_chain
= ptr
->next
;
153 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
157 struct cleanup
*old_chain
= cleanup_chain
;
163 /* Restore the cleanup chain from a previously saved chain. */
165 restore_cleanups (chain
)
166 struct cleanup
*chain
;
168 cleanup_chain
= chain
;
171 /* This function is useful for cleanups.
175 old_chain = make_cleanup (free_current_contents, &foo);
177 to arrange to free the object thus allocated. */
180 free_current_contents (location
)
186 /* Provide a known function that does nothing, to use as a base for
187 for a possibly long chain of cleanups. This is useful where we
188 use the cleanup chain for handling normal cleanups as well as dealing
189 with cleanups that need to be done as a result of a call to error().
190 In such cases, we may not be certain where the first cleanup is, unless
191 we have a do-nothing one to always use as the base. */
201 /* Provide a hook for modules wishing to print their own warning messages
202 to set up the terminal state in a compatible way, without them having
203 to import all the target_<...> macros. */
208 target_terminal_ours ();
209 wrap_here(""); /* Force out any buffered output */
213 /* Print a warning message.
214 The first argument STRING is the warning message, used as a fprintf string,
215 and the remaining args are passed as arguments to it.
216 The primary difference between warnings and errors is that a warning
217 does not force the return to command level. */
228 target_terminal_ours ();
229 wrap_here(""); /* Force out any buffered output */
231 if (warning_pre_print
)
232 fprintf (stderr
, warning_pre_print
);
233 string
= va_arg (args
, char *);
234 vfprintf (stderr
, string
, args
);
235 fprintf (stderr
, "\n");
239 /* Print an error message and return to command level.
240 The first argument STRING is the error message, used as a fprintf string,
241 and the remaining args are passed as arguments to it. */
252 target_terminal_ours ();
253 wrap_here(""); /* Force out any buffered output */
256 fprintf_filtered (stderr
, error_pre_print
);
257 string
= va_arg (args
, char *);
258 vfprintf_filtered (stderr
, string
, args
);
259 fprintf_filtered (stderr
, "\n");
261 return_to_top_level ();
264 /* Print an error message and exit reporting failure.
265 This is for a error that we cannot continue from.
266 The arguments are printed a la printf.
268 This function cannot be declared volatile (NORETURN) in an
269 ANSI environment because exit() is not declared volatile. */
280 string
= va_arg (args
, char *);
281 fprintf (stderr
, "\ngdb: ");
282 vfprintf (stderr
, string
, args
);
283 fprintf (stderr
, "\n");
288 /* Print an error message and exit, dumping core.
289 The arguments are printed a la printf (). */
293 fatal_dump_core (va_alist
)
300 string
= va_arg (args
, char *);
301 /* "internal error" is always correct, since GDB should never dump
302 core, no matter what the input. */
303 fprintf (stderr
, "\ngdb internal error: ");
304 vfprintf (stderr
, string
, args
);
305 fprintf (stderr
, "\n");
308 signal (SIGQUIT
, SIG_DFL
);
309 kill (getpid (), SIGQUIT
);
310 /* We should never get here, but just in case... */
314 /* The strerror() function can return NULL for errno values that are
315 out of range. Provide a "safe" version that always returns a
319 safe_strerror (errnum
)
325 if ((msg
= strerror (errnum
)) == NULL
)
327 sprintf (buf
, "(undocumented errno %d)", errnum
);
333 /* The strsignal() function can return NULL for signal values that are
334 out of range. Provide a "safe" version that always returns a
338 safe_strsignal (signo
)
344 if ((msg
= strsignal (signo
)) == NULL
)
346 sprintf (buf
, "(undocumented signal %d)", signo
);
353 /* Print the system error message for errno, and also mention STRING
354 as the file name for which the error was encountered.
355 Then return to command level. */
358 perror_with_name (string
)
364 err
= safe_strerror (errno
);
365 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
366 strcpy (combined
, string
);
367 strcat (combined
, ": ");
368 strcat (combined
, err
);
370 /* I understand setting these is a matter of taste. Still, some people
371 may clear errno but not know about bfd_error. Doing this here is not
373 bfd_error
= no_error
;
376 error ("%s.", combined
);
379 /* Print the system error message for ERRCODE, and also mention STRING
380 as the file name for which the error was encountered. */
383 print_sys_errmsg (string
, errcode
)
390 err
= safe_strerror (errcode
);
391 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
392 strcpy (combined
, string
);
393 strcat (combined
, ": ");
394 strcat (combined
, err
);
396 fprintf (stderr
, "%s.\n", combined
);
399 /* Control C eventually causes this to be called, at a convenient time. */
404 target_terminal_ours ();
405 wrap_here ((char *)0); /* Force out any pending output */
406 #if !defined(__GO32__)
408 ioctl (fileno (stdout
), TCFLSH
, 1);
409 #else /* not HAVE_TERMIO */
410 ioctl (fileno (stdout
), TIOCFLUSH
, 0);
411 #endif /* not HAVE_TERMIO */
415 error ("Quit (expect signal %d when inferior is resumed)", SIGINT
);
416 #endif /* TIOCGPGRP */
425 /* In the absence of signals, poll keyboard for a quit.
426 Called from #define QUIT pollquit() in xm-go32.h. */
444 /* Control C comes here */
453 /* Restore the signal handler. */
454 signal (signo
, request_quit
);
462 /* Memory management stuff (malloc friends). */
464 #if defined (NO_MMALLOC)
471 return (malloc (size
));
475 mrealloc (md
, ptr
, size
)
480 if (ptr
== 0) /* Guard against old realloc's */
481 return malloc (size
);
483 return realloc (ptr
, size
);
494 #endif /* NO_MMALLOC */
496 #if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
504 #else /* have mmalloc and want corruption checking */
509 fatal_dump_core ("Memory corruption");
512 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
513 by MD, to detect memory corruption. Note that MD may be NULL to specify
514 the default heap that grows via sbrk.
516 Note that for freshly created regions, we must call mmcheck prior to any
517 mallocs in the region. Otherwise, any region which was allocated prior to
518 installing the checking hooks, which is later reallocated or freed, will
519 fail the checks! The mmcheck function only allows initial hooks to be
520 installed before the first mmalloc. However, anytime after we have called
521 mmcheck the first time to install the checking hooks, we can call it again
522 to update the function pointer to the memory corruption handler.
524 Returns zero on failure, non-zero on success. */
530 if (!mmcheck (md
, malloc_botch
))
532 warning ("internal error: failed to install memory consistency checks");
538 #endif /* Have mmalloc and want corruption checking */
540 /* Called when a memory allocation fails, with the number of bytes of
541 memory requested in SIZE. */
549 fatal ("virtual memory exhausted: can't allocate %ld bytes.", size
);
553 fatal ("virtual memory exhausted.");
557 /* Like mmalloc but get error if no storage available, and protect against
558 the caller wanting to allocate zero bytes. Whether to return NULL for
559 a zero byte request, or translate the request into a request for one
560 byte of zero'd storage, is a religious issue. */
573 else if ((val
= mmalloc (md
, size
)) == NULL
)
580 /* Like mrealloc but get error if no storage available. */
583 xmrealloc (md
, ptr
, size
)
592 val
= mrealloc (md
, ptr
, size
);
596 val
= mmalloc (md
, size
);
605 /* Like malloc but get error if no storage available, and protect against
606 the caller wanting to allocate zero bytes. */
612 return (xmmalloc ((void *) NULL
, size
));
615 /* Like mrealloc but get error if no storage available. */
622 return (xmrealloc ((void *) NULL
, ptr
, size
));
626 /* My replacement for the read system call.
627 Used like `read' but keeps going if `read' returns too soon. */
630 myread (desc
, addr
, len
)
640 val
= read (desc
, addr
, len
);
651 /* Make a copy of the string at PTR with SIZE characters
652 (and add a null character at the end in the copy).
653 Uses malloc to get the space. Returns the address of the copy. */
656 savestring (ptr
, size
)
660 register char *p
= (char *) xmalloc (size
+ 1);
661 memcpy (p
, ptr
, size
);
667 msavestring (md
, ptr
, size
)
672 register char *p
= (char *) xmmalloc (md
, size
+ 1);
673 memcpy (p
, ptr
, size
);
678 /* The "const" is so it compiles under DGUX (which prototypes strsave
679 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
680 Doesn't real strsave return NULL if out of memory? */
685 return savestring (ptr
, strlen (ptr
));
693 return (msavestring (md
, ptr
, strlen (ptr
)));
697 print_spaces (n
, file
)
705 /* Ask user a y-or-n question and return 1 iff answer is yes.
706 Takes three args which are given to printf to print the question.
707 The first, a control string, should end in "? ".
708 It should not say how to answer, because we do that. */
720 /* Automatically answer "yes" if input is not from a terminal. */
721 if (!input_from_terminal_p ())
726 wrap_here (""); /* Flush any buffered output */
729 ctlstr
= va_arg (args
, char *);
730 vfprintf_filtered (stdout
, ctlstr
, args
);
732 printf_filtered ("(y or n) ");
734 answer
= fgetc (stdin
);
735 clearerr (stdin
); /* in case of C-d */
736 if (answer
== EOF
) /* C-d */
738 if (answer
!= '\n') /* Eat rest of input line, to EOF or newline */
741 ans2
= fgetc (stdin
);
744 while (ans2
!= EOF
&& ans2
!= '\n');
751 printf_filtered ("Please answer y or n.\n");
756 /* Parse a C escape sequence. STRING_PTR points to a variable
757 containing a pointer to the string to parse. That pointer
758 should point to the character after the \. That pointer
759 is updated past the characters we use. The value of the
760 escape sequence is returned.
762 A negative value means the sequence \ newline was seen,
763 which is supposed to be equivalent to nothing at all.
765 If \ is followed by a null character, we return a negative
766 value and leave the string pointer pointing at the null character.
768 If \ is followed by 000, we return 0 and leave the string pointer
769 after the zeros. A value of 0 does not mean end of string. */
772 parse_escape (string_ptr
)
775 register int c
= *(*string_ptr
)++;
779 return 007; /* Bell (alert) char */
782 case 'e': /* Escape character */
800 c
= *(*string_ptr
)++;
802 c
= parse_escape (string_ptr
);
805 return (c
& 0200) | (c
& 037);
816 register int i
= c
- '0';
817 register int count
= 0;
820 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
838 /* Print the character C on STREAM as part of the contents of a literal
839 string whose delimiter is QUOTER. Note that this routine should only
840 be call for printing things which are independent of the language
841 of the program being debugged. */
844 gdb_printchar (c
, stream
, quoter
)
850 c
&= 0xFF; /* Avoid sign bit follies */
852 if ( c
< 0x20 || /* Low control chars */
853 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
854 (sevenbit_strings
&& c
>= 0x80)) { /* high order bit set */
858 fputs_filtered ("\\n", stream
);
861 fputs_filtered ("\\b", stream
);
864 fputs_filtered ("\\t", stream
);
867 fputs_filtered ("\\f", stream
);
870 fputs_filtered ("\\r", stream
);
873 fputs_filtered ("\\e", stream
);
876 fputs_filtered ("\\a", stream
);
879 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
883 if (c
== '\\' || c
== quoter
)
884 fputs_filtered ("\\", stream
);
885 fprintf_filtered (stream
, "%c", c
);
889 /* Number of lines per page or UINT_MAX if paging is disabled. */
890 static unsigned int lines_per_page
;
891 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
892 static unsigned int chars_per_line
;
893 /* Current count of lines printed on this page, chars on this line. */
894 static unsigned int lines_printed
, chars_printed
;
896 /* Buffer and start column of buffered text, for doing smarter word-
897 wrapping. When someone calls wrap_here(), we start buffering output
898 that comes through fputs_filtered(). If we see a newline, we just
899 spit it out and forget about the wrap_here(). If we see another
900 wrap_here(), we spit it out and remember the newer one. If we see
901 the end of the line, we spit out a newline, the indent, and then
904 wrap_column is the column number on the screen where wrap_buffer begins.
905 When wrap_column is zero, wrapping is not in effect.
906 wrap_buffer is malloc'd with chars_per_line+2 bytes.
907 When wrap_buffer[0] is null, the buffer is empty.
908 wrap_pointer points into it at the next character to fill.
909 wrap_indent is the string that should be used as indentation if the
912 static char *wrap_buffer
, *wrap_pointer
, *wrap_indent
;
913 static int wrap_column
;
917 set_width_command (args
, from_tty
, c
)
920 struct cmd_list_element
*c
;
924 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
925 wrap_buffer
[0] = '\0';
928 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
929 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
932 /* Wait, so the user can read what's on the screen. Prompt the user
933 to continue by pressing RETURN. */
936 prompt_for_continue ()
940 /* We must do this *before* we call gdb_readline, else it will eventually
941 call us -- thinking that we're trying to print beyond the end of the
943 reinitialize_more_filter ();
946 ignore
= gdb_readline ("---Type <return> to continue---");
951 /* Now we have to do this again, so that GDB will know that it doesn't
952 need to save the ---Type <return>--- line at the top of the screen. */
953 reinitialize_more_filter ();
955 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
958 /* Reinitialize filter; ie. tell it to reset to original values. */
961 reinitialize_more_filter ()
967 /* Indicate that if the next sequence of characters overflows the line,
968 a newline should be inserted here rather than when it hits the end.
969 If INDENT is nonzero, it is a string to be printed to indent the
970 wrapped part on the next line. INDENT must remain accessible until
971 the next call to wrap_here() or until a newline is printed through
974 If the line is already overfull, we immediately print a newline and
975 the indentation, and disable further wrapping.
977 If we don't know the width of lines, but we know the page height,
978 we must not wrap words, but should still keep track of newlines
979 that were explicitly printed.
981 INDENT should not contain tabs, as that
982 will mess up the char count on the next line. FIXME. */
990 *wrap_pointer
= '\0';
991 fputs (wrap_buffer
, stdout
);
993 wrap_pointer
= wrap_buffer
;
994 wrap_buffer
[0] = '\0';
995 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
999 else if (chars_printed
>= chars_per_line
)
1001 puts_filtered ("\n");
1002 puts_filtered (indent
);
1007 wrap_column
= chars_printed
;
1008 wrap_indent
= indent
;
1012 /* Ensure that whatever gets printed next, using the filtered output
1013 commands, starts at the beginning of the line. I.E. if there is
1014 any pending output for the current line, flush it and start a new
1015 line. Otherwise do nothing. */
1020 if (chars_printed
> 0)
1022 puts_filtered ("\n");
1026 /* Like fputs but pause after every screenful, and can wrap at points
1027 other than the final character of a line.
1028 Unlike fputs, fputs_filtered does not return a value.
1029 It is OK for LINEBUFFER to be NULL, in which case just don't print
1032 Note that a longjmp to top level may occur in this routine
1033 (since prompt_for_continue may do so) so this routine should not be
1034 called when cleanups are not in place. */
1037 fputs_filtered (linebuffer
, stream
)
1038 const char *linebuffer
;
1041 const char *lineptr
;
1043 if (linebuffer
== 0)
1046 /* Don't do any filtering if it is disabled. */
1047 if (stream
!= stdout
1048 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
1050 fputs (linebuffer
, stream
);
1054 /* Go through and output each character. Show line extension
1055 when this is necessary; prompt user for new page when this is
1058 lineptr
= linebuffer
;
1061 /* Possible new page. */
1062 if (lines_printed
>= lines_per_page
- 1)
1063 prompt_for_continue ();
1065 while (*lineptr
&& *lineptr
!= '\n')
1067 /* Print a single line. */
1068 if (*lineptr
== '\t')
1071 *wrap_pointer
++ = '\t';
1073 putc ('\t', stream
);
1074 /* Shifting right by 3 produces the number of tab stops
1075 we have already passed, and then adding one and
1076 shifting left 3 advances to the next tab stop. */
1077 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
1083 *wrap_pointer
++ = *lineptr
;
1085 putc (*lineptr
, stream
);
1090 if (chars_printed
>= chars_per_line
)
1092 unsigned int save_chars
= chars_printed
;
1096 /* If we aren't actually wrapping, don't output newline --
1097 if chars_per_line is right, we probably just overflowed
1098 anyway; if it's wrong, let us keep going. */
1100 putc ('\n', stream
);
1102 /* Possible new page. */
1103 if (lines_printed
>= lines_per_page
- 1)
1104 prompt_for_continue ();
1106 /* Now output indentation and wrapped string */
1110 fputs (wrap_indent
, stream
);
1111 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
1112 fputs (wrap_buffer
, stream
); /* and eject it */
1113 /* FIXME, this strlen is what prevents wrap_indent from
1114 containing tabs. However, if we recurse to print it
1115 and count its chars, we risk trouble if wrap_indent is
1116 longer than (the user settable) chars_per_line.
1117 Note also that this can set chars_printed > chars_per_line
1118 if we are printing a long string. */
1119 chars_printed
= strlen (wrap_indent
)
1120 + (save_chars
- wrap_column
);
1121 wrap_pointer
= wrap_buffer
; /* Reset buffer */
1122 wrap_buffer
[0] = '\0';
1123 wrap_column
= 0; /* And disable fancy wrap */
1128 if (*lineptr
== '\n')
1131 wrap_here ((char *)0); /* Spit out chars, cancel further wraps */
1133 putc ('\n', stream
);
1139 /* Print a variable number of ARGS using format FORMAT. If this
1140 information is going to put the amount written (since the last call
1141 to REINITIALIZE_MORE_FILTER or the last page break) over the page size,
1142 print out a pause message and do a gdb_readline to get the users
1143 permision to continue.
1145 Unlike fprintf, this function does not return a value.
1147 We implement three variants, vfprintf (takes a vararg list and stream),
1148 fprintf (takes a stream to write on), and printf (the usual).
1150 Note that this routine has a restriction that the length of the
1151 final output line must be less than 255 characters *or* it must be
1152 less than twice the size of the format string. This is a very
1153 arbitrary restriction, but it is an internal restriction, so I'll
1154 put it in. This means that the %s format specifier is almost
1155 useless; unless the caller can GUARANTEE that the string is short
1156 enough, fputs_filtered should be used instead.
1158 Note also that a longjmp to top level may occur in this routine
1159 (since prompt_for_continue may do so) so this routine should not be
1160 called when cleanups are not in place. */
1162 #define MIN_LINEBUF 255
1165 vfprintf_filtered (stream
, format
, args
)
1170 char line_buf
[MIN_LINEBUF
+10];
1171 char *linebuffer
= line_buf
;
1174 format_length
= strlen (format
);
1176 /* Reallocate buffer to a larger size if this is necessary. */
1177 if (format_length
* 2 > MIN_LINEBUF
)
1179 linebuffer
= alloca (10 + format_length
* 2);
1182 /* This won't blow up if the restrictions described above are
1184 vsprintf (linebuffer
, format
, args
);
1186 fputs_filtered (linebuffer
, stream
);
1190 vprintf_filtered (format
, args
)
1194 vfprintf_filtered (stdout
, format
, args
);
1199 fprintf_filtered (va_alist
)
1207 stream
= va_arg (args
, FILE *);
1208 format
= va_arg (args
, char *);
1210 /* This won't blow up if the restrictions described above are
1212 vfprintf_filtered (stream
, format
, args
);
1216 /* Like fprintf_filtered, but prints it's result indent.
1217 Called as fprintfi_filtered (spaces, format, arg1, arg2, ...); */
1221 fprintfi_filtered (va_alist
)
1230 spaces
= va_arg (args
, int);
1231 stream
= va_arg (args
, FILE *);
1232 format
= va_arg (args
, char *);
1233 print_spaces_filtered (spaces
, stream
);
1235 /* This won't blow up if the restrictions described above are
1237 vfprintf_filtered (stream
, format
, args
);
1243 printf_filtered (va_alist
)
1250 format
= va_arg (args
, char *);
1252 vfprintf_filtered (stdout
, format
, args
);
1256 /* Like printf_filtered, but prints it's result indented.
1257 Called as printfi_filtered (spaces, format, arg1, arg2, ...); */
1261 printfi_filtered (va_alist
)
1269 spaces
= va_arg (args
, int);
1270 format
= va_arg (args
, char *);
1271 print_spaces_filtered (spaces
, stdout
);
1272 vfprintf_filtered (stdout
, format
, args
);
1276 /* Easy -- but watch out!
1278 This routine is *not* a replacement for puts()! puts() appends a newline.
1279 This one doesn't, and had better not! */
1282 puts_filtered (string
)
1285 fputs_filtered (string
, stdout
);
1288 /* Return a pointer to N spaces and a null. The pointer is good
1289 until the next call to here. */
1295 static char *spaces
;
1296 static int max_spaces
;
1302 spaces
= (char *) xmalloc (n
+1);
1303 for (t
= spaces
+n
; t
!= spaces
;)
1309 return spaces
+ max_spaces
- n
;
1312 /* Print N spaces. */
1314 print_spaces_filtered (n
, stream
)
1318 fputs_filtered (n_spaces (n
), stream
);
1321 /* C++ demangler stuff. */
1323 /* fprintf_symbol_filtered attempts to demangle NAME, a symbol in language
1324 LANG, using demangling args ARG_MODE, and print it filtered to STREAM.
1325 If the name is not mangled, or the language for the name is unknown, or
1326 demangling is off, the name is printed in its "raw" form. */
1329 fprintf_symbol_filtered (stream
, name
, lang
, arg_mode
)
1339 /* If user wants to see raw output, no problem. */
1342 fputs_filtered (name
, stream
);
1348 case language_cplus
:
1349 demangled
= cplus_demangle (name
, arg_mode
);
1351 case language_chill
:
1352 demangled
= chill_demangle (name
);
1358 fputs_filtered (demangled
? demangled
: name
, stream
);
1359 if (demangled
!= NULL
)
1367 /* Do a strcmp() type operation on STRING1 and STRING2, ignoring any
1368 differences in whitespace. Returns 0 if they match, non-zero if they
1369 don't (slightly different than strcmp()'s range of return values).
1371 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
1372 This "feature" is useful when searching for matching C++ function names
1373 (such as if the user types 'break FOO', where FOO is a mangled C++
1377 strcmp_iw (string1
, string2
)
1378 const char *string1
;
1379 const char *string2
;
1381 while ((*string1
!= '\0') && (*string2
!= '\0'))
1383 while (isspace (*string1
))
1387 while (isspace (*string2
))
1391 if (*string1
!= *string2
)
1395 if (*string1
!= '\0')
1401 return (*string1
!= '\0' && *string1
!= '(') || (*string2
!= '\0');
1406 _initialize_utils ()
1408 struct cmd_list_element
*c
;
1410 c
= add_set_cmd ("width", class_support
, var_uinteger
,
1411 (char *)&chars_per_line
,
1412 "Set number of characters gdb thinks are in a line.",
1414 add_show_from_set (c
, &showlist
);
1415 c
->function
.sfunc
= set_width_command
;
1418 (add_set_cmd ("height", class_support
,
1419 var_uinteger
, (char *)&lines_per_page
,
1420 "Set number of lines gdb thinks are in a page.", &setlist
),
1423 /* These defaults will be used if we are unable to get the correct
1424 values from termcap. */
1425 #if defined(__GO32__)
1426 lines_per_page
= ScreenRows();
1427 chars_per_line
= ScreenCols();
1429 lines_per_page
= 24;
1430 chars_per_line
= 80;
1431 /* Initialize the screen height and width from termcap. */
1433 char *termtype
= getenv ("TERM");
1435 /* Positive means success, nonpositive means failure. */
1438 /* 2048 is large enough for all known terminals, according to the
1439 GNU termcap manual. */
1440 char term_buffer
[2048];
1444 status
= tgetent (term_buffer
, termtype
);
1449 val
= tgetnum ("li");
1451 lines_per_page
= val
;
1453 /* The number of lines per page is not mentioned
1454 in the terminal description. This probably means
1455 that paging is not useful (e.g. emacs shell window),
1456 so disable paging. */
1457 lines_per_page
= UINT_MAX
;
1459 val
= tgetnum ("co");
1461 chars_per_line
= val
;
1466 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1468 /* If there is a better way to determine the window size, use it. */
1469 SIGWINCH_HANDLER ();
1472 /* If the output is not a terminal, don't paginate it. */
1473 if (!ISATTY (stdout
))
1474 lines_per_page
= UINT_MAX
;
1476 set_width_command ((char *)NULL
, 0, c
);
1479 (add_set_cmd ("demangle", class_support
, var_boolean
,
1481 "Set demangling of encoded C++ names when displaying symbols.",
1486 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
1487 (char *)&sevenbit_strings
,
1488 "Set printing of 8-bit characters in strings as \\nnn.",
1493 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
1494 (char *)&asm_demangle
,
1495 "Set demangling of C++ names in disassembly listings.",
1500 /* Machine specific function to handle SIGWINCH signal. */
1502 #ifdef SIGWINCH_HANDLER_BODY
1503 SIGWINCH_HANDLER_BODY
This page took 0.05935 seconds and 4 git commands to generate.