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. */
22 #include <sys/ioctl.h>
23 #include <sys/param.h>
35 /* Prototypes for local functions */
37 #if !defined (NO_MALLOC_CHECK)
40 malloc_botch
PARAMS ((void));
42 #endif /* NO_MALLOC_CHECK */
45 fatal_dump_core (); /* Can't prototype with <varargs.h> usage... */
48 prompt_for_continue
PARAMS ((void));
51 set_width_command
PARAMS ((char *, int, struct cmd_list_element
*));
54 vfprintf_filtered
PARAMS ((FILE *, char *, va_list));
56 /* If this definition isn't overridden by the header files, assume
57 that isatty and fileno exist on this system. */
59 #define ISATTY(FP) (isatty (fileno (FP)))
62 /* Chain of cleanup actions established with make_cleanup,
63 to be executed if an error happens. */
65 static struct cleanup
*cleanup_chain
;
67 /* Nonzero means a quit has been requested. */
71 /* Nonzero means quit immediately if Control-C is typed now,
72 rather than waiting until QUIT is executed. */
76 /* Nonzero means that encoded C++ names should be printed out in their
77 C++ form rather than raw. */
81 /* Nonzero means that encoded C++ names should be printed out in their
82 C++ form even in assembler language displays. If this is set, but
83 DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls. */
87 /* Nonzero means that strings with character values >0x7F should be printed
88 as octal escapes. Zero means just print the value (e.g. it's an
89 international character, and the terminal or window can cope.) */
91 int sevenbit_strings
= 0;
93 /* String to be printed before error messages, if any. */
95 char *error_pre_print
;
96 char *warning_pre_print
= "\nwarning: ";
98 /* Add a new cleanup to the cleanup_chain,
99 and return the previous chain pointer
100 to be passed later to do_cleanups or discard_cleanups.
101 Args are FUNCTION to clean up with, and ARG to pass to it. */
104 make_cleanup (function
, arg
)
105 void (*function
) PARAMS ((PTR
));
108 register struct cleanup
*new
109 = (struct cleanup
*) xmalloc (sizeof (struct cleanup
));
110 register struct cleanup
*old_chain
= cleanup_chain
;
112 new->next
= cleanup_chain
;
113 new->function
= function
;
120 /* Discard cleanups and do the actions they describe
121 until we get back to the point OLD_CHAIN in the cleanup_chain. */
124 do_cleanups (old_chain
)
125 register struct cleanup
*old_chain
;
127 register struct cleanup
*ptr
;
128 while ((ptr
= cleanup_chain
) != old_chain
)
130 cleanup_chain
= ptr
->next
; /* Do this first incase recursion */
131 (*ptr
->function
) (ptr
->arg
);
136 /* Discard cleanups, not doing the actions they describe,
137 until we get back to the point OLD_CHAIN in the cleanup_chain. */
140 discard_cleanups (old_chain
)
141 register struct cleanup
*old_chain
;
143 register struct cleanup
*ptr
;
144 while ((ptr
= cleanup_chain
) != old_chain
)
146 cleanup_chain
= ptr
->next
;
151 /* Set the cleanup_chain to 0, and return the old cleanup chain. */
155 struct cleanup
*old_chain
= cleanup_chain
;
161 /* Restore the cleanup chain from a previously saved chain. */
163 restore_cleanups (chain
)
164 struct cleanup
*chain
;
166 cleanup_chain
= chain
;
169 /* This function is useful for cleanups.
173 old_chain = make_cleanup (free_current_contents, &foo);
175 to arrange to free the object thus allocated. */
178 free_current_contents (location
)
184 /* Provide a known function that does nothing, to use as a base for
185 for a possibly long chain of cleanups. This is useful where we
186 use the cleanup chain for handling normal cleanups as well as dealing
187 with cleanups that need to be done as a result of a call to error().
188 In such cases, we may not be certain where the first cleanup is, unless
189 we have a do-nothing one to always use as the base. */
199 /* Provide a hook for modules wishing to print their own warning messages
200 to set up the terminal state in a compatible way, without them having
201 to import all the target_<...> macros. */
206 target_terminal_ours ();
207 wrap_here(""); /* Force out any buffered output */
211 /* Print a warning message.
212 The first argument STRING is the warning message, used as a fprintf string,
213 and the remaining args are passed as arguments to it.
214 The primary difference between warnings and errors is that a warning
215 does not force the return to command level. */
226 target_terminal_ours ();
227 wrap_here(""); /* Force out any buffered output */
229 if (warning_pre_print
)
230 fprintf (stderr
, warning_pre_print
);
231 string
= va_arg (args
, char *);
232 vfprintf (stderr
, string
, args
);
233 fprintf (stderr
, "\n");
237 /* Print an error message and return to command level.
238 The first argument STRING is the error message, used as a fprintf string,
239 and the remaining args are passed as arguments to it. */
250 target_terminal_ours ();
251 wrap_here(""); /* Force out any buffered output */
254 fprintf (stderr
, error_pre_print
);
255 string
= va_arg (args
, char *);
256 vfprintf (stderr
, string
, args
);
257 fprintf (stderr
, "\n");
259 return_to_top_level ();
262 /* Print an error message and exit reporting failure.
263 This is for a error that we cannot continue from.
264 The arguments are printed a la printf.
266 This function cannot be declared volatile (NORETURN) in an
267 ANSI environment because exit() is not declared volatile. */
278 string
= va_arg (args
, char *);
279 fprintf (stderr
, "\ngdb: ");
280 vfprintf (stderr
, string
, args
);
281 fprintf (stderr
, "\n");
286 /* Print an error message and exit, dumping core.
287 The arguments are printed a la printf (). */
291 fatal_dump_core (va_alist
)
298 string
= va_arg (args
, char *);
299 /* "internal error" is always correct, since GDB should never dump
300 core, no matter what the input. */
301 fprintf (stderr
, "\ngdb internal error: ");
302 vfprintf (stderr
, string
, args
);
303 fprintf (stderr
, "\n");
306 signal (SIGQUIT
, SIG_DFL
);
307 kill (getpid (), SIGQUIT
);
308 /* We should never get here, but just in case... */
312 /* The strerror() function can return NULL for errno values that are
313 out of range. Provide a "safe" version that always returns a
317 safe_strerror (errnum
)
323 if ((msg
= strerror (errnum
)) == NULL
)
325 sprintf (buf
, "(undocumented errno %d)", errnum
);
331 /* The strsignal() function can return NULL for signal values that are
332 out of range. Provide a "safe" version that always returns a
336 safe_strsignal (signo
)
342 if ((msg
= strsignal (signo
)) == NULL
)
344 sprintf (buf
, "(undocumented signal %d)", signo
);
351 /* Print the system error message for errno, and also mention STRING
352 as the file name for which the error was encountered.
353 Then return to command level. */
356 perror_with_name (string
)
362 err
= safe_strerror (errno
);
363 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
364 strcpy (combined
, string
);
365 strcat (combined
, ": ");
366 strcat (combined
, err
);
368 /* I understand setting these is a matter of taste. Still, some people
369 may clear errno but not know about bfd_error. Doing this here is not
371 bfd_error
= no_error
;
374 error ("%s.", combined
);
377 /* Print the system error message for ERRCODE, and also mention STRING
378 as the file name for which the error was encountered. */
381 print_sys_errmsg (string
, errcode
)
388 err
= safe_strerror (errcode
);
389 combined
= (char *) alloca (strlen (err
) + strlen (string
) + 3);
390 strcpy (combined
, string
);
391 strcat (combined
, ": ");
392 strcat (combined
, err
);
394 printf ("%s.\n", combined
);
397 /* Control C eventually causes this to be called, at a convenient time. */
402 target_terminal_ours ();
403 wrap_here ((char *)0); /* Force out any pending output */
405 ioctl (fileno (stdout
), TCFLSH
, 1);
406 #else /* not HAVE_TERMIO */
407 ioctl (fileno (stdout
), TIOCFLUSH
, 0);
408 #endif /* not HAVE_TERMIO */
412 error ("Quit (expect signal %d when inferior is resumed)", SIGINT
);
413 #endif /* TIOCGPGRP */
416 /* Control C comes here */
425 /* Restore the signal handler. */
426 signal (signo
, request_quit
);
434 /* Memory management stuff (malloc friends). */
436 #if defined (NO_MMALLOC)
443 return (malloc (size
));
447 mrealloc (md
, ptr
, size
)
452 if (ptr
== 0) /* Guard against old realloc's */
453 return malloc (size
);
455 return realloc (ptr
, size
);
466 #endif /* NO_MMALLOC */
468 #if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
476 #else /* have mmalloc and want corruption checking */
481 fatal_dump_core ("Memory corruption");
484 /* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
485 by MD, to detect memory corruption. Note that MD may be NULL to specify
486 the default heap that grows via sbrk.
488 Note that for freshly created regions, we must call mmcheck prior to any
489 mallocs in the region. Otherwise, any region which was allocated prior to
490 installing the checking hooks, which is later reallocated or freed, will
491 fail the checks! The mmcheck function only allows initial hooks to be
492 installed before the first mmalloc. However, anytime after we have called
493 mmcheck the first time to install the checking hooks, we can call it again
494 to update the function pointer to the memory corruption handler.
496 Returns zero on failure, non-zero on success. */
502 if (!mmcheck (md
, malloc_botch
))
504 warning ("internal error: failed to install memory consistency checks");
510 #endif /* Have mmalloc and want corruption checking */
512 /* Called when a memory allocation fails, with the number of bytes of
513 memory requested in SIZE. */
521 fatal ("virtual memory exhausted: can't allocate %ld bytes.", size
);
525 fatal ("virtual memory exhausted.");
529 /* Like mmalloc but get error if no storage available, and protect against
530 the caller wanting to allocate zero bytes. Whether to return NULL for
531 a zero byte request, or translate the request into a request for one
532 byte of zero'd storage, is a religious issue. */
545 else if ((val
= mmalloc (md
, size
)) == NULL
)
552 /* Like mrealloc but get error if no storage available. */
555 xmrealloc (md
, ptr
, size
)
564 val
= mrealloc (md
, ptr
, size
);
568 val
= mmalloc (md
, size
);
577 /* Like malloc but get error if no storage available, and protect against
578 the caller wanting to allocate zero bytes. */
584 return (xmmalloc ((void *) NULL
, size
));
587 /* Like mrealloc but get error if no storage available. */
594 return (xmrealloc ((void *) NULL
, ptr
, size
));
598 /* My replacement for the read system call.
599 Used like `read' but keeps going if `read' returns too soon. */
602 myread (desc
, addr
, len
)
612 val
= read (desc
, addr
, len
);
623 /* Make a copy of the string at PTR with SIZE characters
624 (and add a null character at the end in the copy).
625 Uses malloc to get the space. Returns the address of the copy. */
628 savestring (ptr
, size
)
632 register char *p
= (char *) xmalloc (size
+ 1);
633 bcopy (ptr
, p
, size
);
639 msavestring (md
, ptr
, size
)
644 register char *p
= (char *) xmmalloc (md
, size
+ 1);
645 bcopy (ptr
, p
, size
);
650 /* The "const" is so it compiles under DGUX (which prototypes strsave
651 in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
652 Doesn't real strsave return NULL if out of memory? */
657 return savestring (ptr
, strlen (ptr
));
665 return (msavestring (md
, ptr
, strlen (ptr
)));
669 print_spaces (n
, file
)
677 /* Ask user a y-or-n question and return 1 iff answer is yes.
678 Takes three args which are given to printf to print the question.
679 The first, a control string, should end in "? ".
680 It should not say how to answer, because we do that. */
692 /* Automatically answer "yes" if input is not from a terminal. */
693 if (!input_from_terminal_p ())
699 ctlstr
= va_arg (args
, char *);
700 vfprintf (stdout
, ctlstr
, args
);
702 printf ("(y or n) ");
704 answer
= fgetc (stdin
);
705 clearerr (stdin
); /* in case of C-d */
706 if (answer
== EOF
) /* C-d */
708 if (answer
!= '\n') /* Eat rest of input line, to EOF or newline */
711 ans2
= fgetc (stdin
);
714 while (ans2
!= EOF
&& ans2
!= '\n');
721 printf ("Please answer y or n.\n");
726 /* Parse a C escape sequence. STRING_PTR points to a variable
727 containing a pointer to the string to parse. That pointer
728 should point to the character after the \. That pointer
729 is updated past the characters we use. The value of the
730 escape sequence is returned.
732 A negative value means the sequence \ newline was seen,
733 which is supposed to be equivalent to nothing at all.
735 If \ is followed by a null character, we return a negative
736 value and leave the string pointer pointing at the null character.
738 If \ is followed by 000, we return 0 and leave the string pointer
739 after the zeros. A value of 0 does not mean end of string. */
742 parse_escape (string_ptr
)
745 register int c
= *(*string_ptr
)++;
749 return 007; /* Bell (alert) char */
752 case 'e': /* Escape character */
770 c
= *(*string_ptr
)++;
772 c
= parse_escape (string_ptr
);
775 return (c
& 0200) | (c
& 037);
786 register int i
= c
- '0';
787 register int count
= 0;
790 if ((c
= *(*string_ptr
)++) >= '0' && c
<= '7')
808 /* Print the character C on STREAM as part of the contents
809 of a literal string whose delimiter is QUOTER. */
812 printchar (c
, stream
, quoter
)
818 c
&= 0xFF; /* Avoid sign bit follies */
820 if ( c
< 0x20 || /* Low control chars */
821 (c
>= 0x7F && c
< 0xA0) || /* DEL, High controls */
822 (sevenbit_strings
&& c
>= 0x80)) { /* high order bit set */
826 fputs_filtered ("\\n", stream
);
829 fputs_filtered ("\\b", stream
);
832 fputs_filtered ("\\t", stream
);
835 fputs_filtered ("\\f", stream
);
838 fputs_filtered ("\\r", stream
);
841 fputs_filtered ("\\e", stream
);
844 fputs_filtered ("\\a", stream
);
847 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
851 if (c
== '\\' || c
== quoter
)
852 fputs_filtered ("\\", stream
);
853 fprintf_filtered (stream
, "%c", c
);
857 /* Number of lines per page or UINT_MAX if paging is disabled. */
858 static unsigned int lines_per_page
;
859 /* Number of chars per line or UNIT_MAX is line folding is disabled. */
860 static unsigned int chars_per_line
;
861 /* Current count of lines printed on this page, chars on this line. */
862 static unsigned int lines_printed
, chars_printed
;
864 /* Buffer and start column of buffered text, for doing smarter word-
865 wrapping. When someone calls wrap_here(), we start buffering output
866 that comes through fputs_filtered(). If we see a newline, we just
867 spit it out and forget about the wrap_here(). If we see another
868 wrap_here(), we spit it out and remember the newer one. If we see
869 the end of the line, we spit out a newline, the indent, and then
872 wrap_column is the column number on the screen where wrap_buffer begins.
873 When wrap_column is zero, wrapping is not in effect.
874 wrap_buffer is malloc'd with chars_per_line+2 bytes.
875 When wrap_buffer[0] is null, the buffer is empty.
876 wrap_pointer points into it at the next character to fill.
877 wrap_indent is the string that should be used as indentation if the
880 static char *wrap_buffer
, *wrap_pointer
, *wrap_indent
;
881 static int wrap_column
;
885 set_width_command (args
, from_tty
, c
)
888 struct cmd_list_element
*c
;
892 wrap_buffer
= (char *) xmalloc (chars_per_line
+ 2);
893 wrap_buffer
[0] = '\0';
896 wrap_buffer
= (char *) xrealloc (wrap_buffer
, chars_per_line
+ 2);
897 wrap_pointer
= wrap_buffer
; /* Start it at the beginning */
901 prompt_for_continue ()
906 ignore
= gdb_readline ("---Type <return> to continue---");
909 chars_printed
= lines_printed
= 0;
911 dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */
914 /* Reinitialize filter; ie. tell it to reset to original values. */
917 reinitialize_more_filter ()
923 /* Indicate that if the next sequence of characters overflows the line,
924 a newline should be inserted here rather than when it hits the end.
925 If INDENT is nonzero, it is a string to be printed to indent the
926 wrapped part on the next line. INDENT must remain accessible until
927 the next call to wrap_here() or until a newline is printed through
930 If the line is already overfull, we immediately print a newline and
931 the indentation, and disable further wrapping.
933 If we don't know the width of lines, but we know the page height,
934 we must not wrap words, but should still keep track of newlines
935 that were explicitly printed.
937 INDENT should not contain tabs, as that
938 will mess up the char count on the next line. FIXME. */
946 *wrap_pointer
= '\0';
947 fputs (wrap_buffer
, stdout
);
949 wrap_pointer
= wrap_buffer
;
950 wrap_buffer
[0] = '\0';
951 if (chars_per_line
== UINT_MAX
) /* No line overflow checking */
955 else if (chars_printed
>= chars_per_line
)
957 puts_filtered ("\n");
958 puts_filtered (indent
);
963 wrap_column
= chars_printed
;
964 wrap_indent
= indent
;
968 /* Like fputs but pause after every screenful, and can wrap at points
969 other than the final character of a line.
970 Unlike fputs, fputs_filtered does not return a value.
971 It is OK for LINEBUFFER to be NULL, in which case just don't print
974 Note that a longjmp to top level may occur in this routine
975 (since prompt_for_continue may do so) so this routine should not be
976 called when cleanups are not in place. */
979 fputs_filtered (linebuffer
, stream
)
980 const char *linebuffer
;
988 /* Don't do any filtering if it is disabled. */
990 || (lines_per_page
== UINT_MAX
&& chars_per_line
== UINT_MAX
))
992 fputs (linebuffer
, stream
);
996 /* Go through and output each character. Show line extension
997 when this is necessary; prompt user for new page when this is
1000 lineptr
= linebuffer
;
1003 /* Possible new page. */
1004 if (lines_printed
>= lines_per_page
- 1)
1005 prompt_for_continue ();
1007 while (*lineptr
&& *lineptr
!= '\n')
1009 /* Print a single line. */
1010 if (*lineptr
== '\t')
1013 *wrap_pointer
++ = '\t';
1015 putc ('\t', stream
);
1016 /* Shifting right by 3 produces the number of tab stops
1017 we have already passed, and then adding one and
1018 shifting left 3 advances to the next tab stop. */
1019 chars_printed
= ((chars_printed
>> 3) + 1) << 3;
1025 *wrap_pointer
++ = *lineptr
;
1027 putc (*lineptr
, stream
);
1032 if (chars_printed
>= chars_per_line
)
1034 unsigned int save_chars
= chars_printed
;
1038 /* If we aren't actually wrapping, don't output newline --
1039 if chars_per_line is right, we probably just overflowed
1040 anyway; if it's wrong, let us keep going. */
1042 putc ('\n', stream
);
1044 /* Possible new page. */
1045 if (lines_printed
>= lines_per_page
- 1)
1046 prompt_for_continue ();
1048 /* Now output indentation and wrapped string */
1052 fputs (wrap_indent
, stream
);
1053 *wrap_pointer
= '\0'; /* Null-terminate saved stuff */
1054 fputs (wrap_buffer
, stream
); /* and eject it */
1055 /* FIXME, this strlen is what prevents wrap_indent from
1056 containing tabs. However, if we recurse to print it
1057 and count its chars, we risk trouble if wrap_indent is
1058 longer than (the user settable) chars_per_line.
1059 Note also that this can set chars_printed > chars_per_line
1060 if we are printing a long string. */
1061 chars_printed
= strlen (wrap_indent
)
1062 + (save_chars
- wrap_column
);
1063 wrap_pointer
= wrap_buffer
; /* Reset buffer */
1064 wrap_buffer
[0] = '\0';
1065 wrap_column
= 0; /* And disable fancy wrap */
1070 if (*lineptr
== '\n')
1073 wrap_here ((char *)0); /* Spit out chars, cancel further wraps */
1075 putc ('\n', stream
);
1082 /* fputs_demangled is a variant of fputs_filtered that
1083 demangles g++ names.*/
1086 fputs_demangled (linebuffer
, stream
, arg_mode
)
1091 #define SYMBOL_MAX 1024
1093 #define SYMBOL_CHAR(c) (isascii(c) \
1094 && (isalnum(c) || (c) == '_' || (c) == CPLUS_MARKER))
1096 char buf
[SYMBOL_MAX
+1];
1097 # define SLOP 5 /* How much room to leave in buf */
1100 if (linebuffer
== NULL
)
1103 /* If user wants to see raw output, no problem. */
1105 fputs_filtered (linebuffer
, stream
);
1111 while ( *p
!= (char) 0 ) {
1114 /* collect non-interesting characters into buf */
1115 while ( *p
!= (char) 0 && !SYMBOL_CHAR(*p
) && i
< (int)sizeof(buf
)-SLOP
) {
1120 /* output the non-interesting characters without demangling */
1122 fputs_filtered(buf
, stream
);
1123 i
= 0; /* reset buf */
1126 /* and now the interesting characters */
1127 while (i
< SYMBOL_MAX
1130 && i
< (int)sizeof(buf
) - SLOP
) {
1138 if ( (result
= cplus_demangle(buf
, arg_mode
)) != NULL
) {
1139 fputs_filtered(result
, stream
);
1143 fputs_filtered(buf
, stream
);
1149 /* Print a variable number of ARGS using format FORMAT. If this
1150 information is going to put the amount written (since the last call
1151 to INITIALIZE_MORE_FILTER or the last page break) over the page size,
1152 print out a pause message and do a gdb_readline to get the users
1153 permision to continue.
1155 Unlike fprintf, this function does not return a value.
1157 We implement three variants, vfprintf (takes a vararg list and stream),
1158 fprintf (takes a stream to write on), and printf (the usual).
1160 Note that this routine has a restriction that the length of the
1161 final output line must be less than 255 characters *or* it must be
1162 less than twice the size of the format string. This is a very
1163 arbitrary restriction, but it is an internal restriction, so I'll
1164 put it in. This means that the %s format specifier is almost
1165 useless; unless the caller can GUARANTEE that the string is short
1166 enough, fputs_filtered should be used instead.
1168 Note also that a longjmp to top level may occur in this routine
1169 (since prompt_for_continue may do so) so this routine should not be
1170 called when cleanups are not in place. */
1173 vfprintf_filtered (stream
, format
, args
)
1178 static char *linebuffer
= (char *) 0;
1179 static int line_size
;
1182 format_length
= strlen (format
);
1184 /* Allocated linebuffer for the first time. */
1187 linebuffer
= (char *) xmalloc (255);
1191 /* Reallocate buffer to a larger size if this is necessary. */
1192 if (format_length
* 2 > line_size
)
1194 line_size
= format_length
* 2;
1196 /* You don't have to copy. */
1198 linebuffer
= (char *) xmalloc (line_size
);
1202 /* This won't blow up if the restrictions described above are
1204 (void) vsprintf (linebuffer
, format
, args
);
1206 fputs_filtered (linebuffer
, stream
);
1211 fprintf_filtered (va_alist
)
1219 stream
= va_arg (args
, FILE *);
1220 format
= va_arg (args
, char *);
1222 /* This won't blow up if the restrictions described above are
1224 vfprintf_filtered (stream
, format
, args
);
1230 printf_filtered (va_alist
)
1237 format
= va_arg (args
, char *);
1239 vfprintf_filtered (stdout
, format
, args
);
1246 puts_filtered (string
)
1249 fputs_filtered (string
, stdout
);
1252 /* Return a pointer to N spaces and a null. The pointer is good
1253 until the next call to here. */
1259 static char *spaces
;
1260 static int max_spaces
;
1266 spaces
= (char *) xmalloc (n
+1);
1267 for (t
= spaces
+n
; t
!= spaces
;)
1273 return spaces
+ max_spaces
- n
;
1276 /* Print N spaces. */
1278 print_spaces_filtered (n
, stream
)
1282 fputs_filtered (n_spaces (n
), stream
);
1285 /* C++ demangler stuff. */
1287 /* Print NAME on STREAM, demangling if necessary. */
1289 fprint_symbol (stream
, name
)
1294 if ((!demangle
) || NULL
== (demangled
= cplus_demangle (name
, 1)))
1295 fputs_filtered (name
, stream
);
1298 fputs_filtered (demangled
, stream
);
1304 _initialize_utils ()
1306 struct cmd_list_element
*c
;
1308 c
= add_set_cmd ("width", class_support
, var_uinteger
,
1309 (char *)&chars_per_line
,
1310 "Set number of characters gdb thinks are in a line.",
1312 add_show_from_set (c
, &showlist
);
1313 c
->function
.sfunc
= set_width_command
;
1316 (add_set_cmd ("height", class_support
,
1317 var_uinteger
, (char *)&lines_per_page
,
1318 "Set number of lines gdb thinks are in a page.", &setlist
),
1321 /* These defaults will be used if we are unable to get the correct
1322 values from termcap. */
1323 lines_per_page
= 24;
1324 chars_per_line
= 80;
1325 /* Initialize the screen height and width from termcap. */
1327 char *termtype
= getenv ("TERM");
1329 /* Positive means success, nonpositive means failure. */
1332 /* 2048 is large enough for all known terminals, according to the
1333 GNU termcap manual. */
1334 char term_buffer
[2048];
1338 status
= tgetent (term_buffer
, termtype
);
1343 val
= tgetnum ("li");
1345 lines_per_page
= val
;
1347 /* The number of lines per page is not mentioned
1348 in the terminal description. This probably means
1349 that paging is not useful (e.g. emacs shell window),
1350 so disable paging. */
1351 lines_per_page
= UINT_MAX
;
1353 val
= tgetnum ("co");
1355 chars_per_line
= val
;
1360 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1362 /* If there is a better way to determine the window size, use it. */
1363 SIGWINCH_HANDLER ();
1366 /* If the output is not a terminal, don't paginate it. */
1367 if (!ISATTY (stdout
))
1368 lines_per_page
= UINT_MAX
;
1370 set_width_command ((char *)NULL
, 0, c
);
1373 (add_set_cmd ("demangle", class_support
, var_boolean
,
1375 "Set demangling of encoded C++ names when displaying symbols.",
1380 (add_set_cmd ("sevenbit-strings", class_support
, var_boolean
,
1381 (char *)&sevenbit_strings
,
1382 "Set printing of 8-bit characters in strings as \\nnn.",
1387 (add_set_cmd ("asm-demangle", class_support
, var_boolean
,
1388 (char *)&asm_demangle
,
1389 "Set demangling of C++ names in disassembly listings.",
1394 /* Machine specific function to handle SIGWINCH signal. */
1396 #ifdef SIGWINCH_HANDLER_BODY
1397 SIGWINCH_HANDLER_BODY
This page took 0.058574 seconds and 4 git commands to generate.