X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Futils.c;h=402fe8ee240eb7c6a5119d88229e629f072ff2a0;hb=0cf4063e29439cdf8693d2357ead6659c6defd74;hp=c25dadfe286b686d3f40509518d4a9b130e9d095;hpb=48be7c1b927d5f7a8a73aef6cf840284b272dde4;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/utils.c b/gdb/utils.c index c25dadfe28..402fe8ee24 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -66,8 +66,6 @@ #include "inferior.h" /* for signed_pointer_to_address */ -#include /* For MAXPATHLEN */ - #include "gdb_curses.h" #include "readline/readline.h" @@ -187,14 +185,6 @@ show_sevenbit_strings (struct ui_file *file, int from_tty, value); } -/* String to be printed before error messages, if any. */ - -char *error_pre_print; - -/* String to be printed before quit messages, if any. */ - -char *quit_pre_print; - /* String to be printed before warning messages, if any. */ char *warning_pre_print = "\nwarning: "; @@ -833,7 +823,7 @@ void internal_verror (const char *file, int line, const char *fmt, va_list ap) { internal_vproblem (&internal_error_problem, file, line, fmt, ap); - deprecated_throw_reason (RETURN_ERROR); + fatal (_("Command aborted.")); } void @@ -967,6 +957,26 @@ add_internal_problem_command (struct internal_problem *problem) xfree (show_doc); } +/* Return a newly allocated string, containing the PREFIX followed + by the system error message for errno (separated by a colon). + + The result must be deallocated after use. */ + +static char * +perror_string (const char *prefix) +{ + char *err; + char *combined; + + err = safe_strerror (errno); + combined = (char *) xmalloc (strlen (err) + strlen (prefix) + 3); + strcpy (combined, prefix); + strcat (combined, ": "); + strcat (combined, err); + + return combined; +} + /* Print the system error message for errno, and also mention STRING as the file name for which the error was encountered. Use ERRCODE for the thrown exception. Then return to command level. */ @@ -974,14 +984,10 @@ add_internal_problem_command (struct internal_problem *problem) void throw_perror_with_name (enum errors errcode, const char *string) { - char *err; char *combined; - err = safe_strerror (errno); - combined = (char *) alloca (strlen (err) + strlen (string) + 3); - strcpy (combined, string); - strcat (combined, ": "); - strcat (combined, err); + combined = perror_string (string); + make_cleanup (xfree, combined); /* I understand setting these is a matter of taste. Still, some people may clear errno but not know about bfd_error. Doing this here is not @@ -1127,16 +1133,15 @@ get_regcomp_error (int code, regex_t *rx) } /* Compile a regexp and throw an exception on error. This returns a - cleanup to free the resulting pattern on success. If RX is NULL, - this does nothing and returns NULL. */ + cleanup to free the resulting pattern on success. RX must not be + NULL. */ struct cleanup * compile_rx_or_error (regex_t *pattern, const char *rx, const char *message) { int code; - if (!rx) - return NULL; + gdb_assert (rx != NULL); code = regcomp (pattern, rx, REG_NOSUB); if (code != 0) @@ -1423,7 +1428,7 @@ host_char_to_target (struct gdbarch *gdbarch, int c, int *target_c) after the zeros. A value of 0 does not mean end of string. */ int -parse_escape (struct gdbarch *gdbarch, char **string_ptr) +parse_escape (struct gdbarch *gdbarch, const char **string_ptr) { int target_char = -2; /* Initialize to avoid GCC warnings. */ int c = *(*string_ptr)++; @@ -1671,12 +1676,16 @@ init_page_info (void) lines_per_page = rows; chars_per_line = cols; - /* Readline should have fetched the termcap entry for us. */ - if (tgetnum ("li") < 0 || getenv ("EMACS")) + /* Readline should have fetched the termcap entry for us. + Only try to use tgetnum function if rl_get_screen_size + did not return a useful value. */ + if (((rows <= 0) && (tgetnum ("li") < 0)) + /* Also disable paging if inside EMACS. */ + || getenv ("EMACS")) { - /* The number of lines per page is not mentioned in the - terminal description. This probably means that paging is - not useful (e.g. emacs shell window), so disable paging. */ + /* The number of lines per page is not mentioned in the terminal + description or EMACS evironment variable is set. This probably + means that paging is not useful, so disable paging. */ lines_per_page = UINT_MAX; } @@ -3131,22 +3140,14 @@ gdb_realpath (const char *filename) path. Use that and realpath() to canonicalize the name. This is the most common case. Note that, if there isn't a compile time upper bound, you want to avoid realpath() at all costs. */ -#if defined(HAVE_REALPATH) +#if defined (HAVE_REALPATH) && defined (PATH_MAX) { -# if defined (PATH_MAX) char buf[PATH_MAX]; -# define USE_REALPATH -# elif defined (MAXPATHLEN) - char buf[MAXPATHLEN]; -# define USE_REALPATH -# endif -# if defined (USE_REALPATH) const char *rp = realpath (filename, buf); if (rp == NULL) rp = filename; return xstrdup (rp); -# endif } #endif /* HAVE_REALPATH */ @@ -3180,7 +3181,7 @@ gdb_realpath (const char *filename) pathconf()) making it impossible to pass a correctly sized buffer to realpath() (it could always overflow). On those systems, we skip this. */ -#if defined (HAVE_REALPATH) && defined (HAVE_UNISTD_H) && defined(HAVE_ALLOCA) +#if defined (HAVE_REALPATH) && defined (_PC_PATH_MAX) && defined(HAVE_ALLOCA) { /* Find out the max path size. */ long path_max = pathconf ("/", _PC_PATH_MAX); @@ -3235,6 +3236,23 @@ align_down (ULONGEST v, int n) return (v & -n); } +/* See utils.h. */ + +LONGEST +gdb_sign_extend (LONGEST value, int bit) +{ + gdb_assert (bit >= 1 && bit <= 8 * sizeof (LONGEST)); + + if (((value >> (bit - 1)) & 1) != 0) + { + LONGEST signbit = ((LONGEST) 1) << (bit - 1); + + value = (value ^ signbit) - signbit; + } + + return value; +} + /* Allocation function for the libiberty hash table which uses an obstack. The obstack is passed as DATA. */