X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Futils.c;h=b957b0dc5c290546f52178f5183046659c30e3d9;hb=7c4e78cf63f6436ae43e8289badba78d81e2eb2c;hp=577f9df4ecc6d0a5838daaa9c20a6e2d9ecca7a6;hpb=b4987c956dfa44ca9fd8552f63e15f5fa094b2a4;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/utils.c b/gdb/utils.c index 577f9df4ec..b957b0dc5c 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -141,36 +141,6 @@ show_pagination_enabled (struct ui_file *file, int from_tty, because while they use the "cleanup API" they are not part of the "cleanup API". */ -static void -do_free_section_addr_info (void *arg) -{ - free_section_addr_info ((struct section_addr_info *) arg); -} - -struct cleanup * -make_cleanup_free_section_addr_info (struct section_addr_info *addrs) -{ - return make_cleanup (do_free_section_addr_info, addrs); -} - -/* Helper for make_cleanup_unpush_target. */ - -static void -do_unpush_target (void *arg) -{ - struct target_ops *ops = (struct target_ops *) arg; - - unpush_target (ops); -} - -/* Return a new cleanup that unpushes OPS. */ - -struct cleanup * -make_cleanup_unpush_target (struct target_ops *ops) -{ - return make_cleanup (do_unpush_target, ops); -} - /* Helper for make_cleanup_value_free_to_mark. */ static void @@ -1200,9 +1170,7 @@ parse_escape (struct gdbarch *gdbarch, const char **string_ptr) character. */ static void -printchar (int c, void (*do_fputs) (const char *, struct ui_file *), - void (*do_fprintf) (struct ui_file *, const char *, ...) - ATTRIBUTE_FPTR_PRINTF_2, struct ui_file *stream, int quoter) +printchar (int c, do_fputc_ftype do_fputc, ui_file *stream, int quoter) { c &= 0xFF; /* Avoid sign bit follies */ @@ -1210,39 +1178,45 @@ printchar (int c, void (*do_fputs) (const char *, struct ui_file *), (c >= 0x7F && c < 0xA0) || /* DEL, High controls */ (sevenbit_strings && c >= 0x80)) { /* high order bit set */ + do_fputc ('\\', stream); + switch (c) { case '\n': - do_fputs ("\\n", stream); + do_fputc ('n', stream); break; case '\b': - do_fputs ("\\b", stream); + do_fputc ('b', stream); break; case '\t': - do_fputs ("\\t", stream); + do_fputc ('t', stream); break; case '\f': - do_fputs ("\\f", stream); + do_fputc ('f', stream); break; case '\r': - do_fputs ("\\r", stream); + do_fputc ('r', stream); break; case '\033': - do_fputs ("\\e", stream); + do_fputc ('e', stream); break; case '\007': - do_fputs ("\\a", stream); + do_fputc ('a', stream); break; default: - do_fprintf (stream, "\\%.3o", (unsigned int) c); - break; + { + do_fputc ('0' + ((c >> 6) & 0x7), stream); + do_fputc ('0' + ((c >> 3) & 0x7), stream); + do_fputc ('0' + ((c >> 0) & 0x7), stream); + break; + } } } else { if (quoter != 0 && (c == '\\' || c == quoter)) - do_fputs ("\\", stream); - do_fprintf (stream, "%c", c); + do_fputc ('\\', stream); + do_fputc (c, stream); } } @@ -1255,34 +1229,30 @@ void fputstr_filtered (const char *str, int quoter, struct ui_file *stream) { while (*str) - printchar (*str++, fputs_filtered, fprintf_filtered, stream, quoter); + printchar (*str++, fputc_filtered, stream, quoter); } void fputstr_unfiltered (const char *str, int quoter, struct ui_file *stream) { while (*str) - printchar (*str++, fputs_unfiltered, fprintf_unfiltered, stream, quoter); + printchar (*str++, fputc_unfiltered, stream, quoter); } void fputstrn_filtered (const char *str, int n, int quoter, struct ui_file *stream) { - int i; - - for (i = 0; i < n; i++) - printchar (str[i], fputs_filtered, fprintf_filtered, stream, quoter); + for (int i = 0; i < n; i++) + printchar (str[i], fputc_filtered, stream, quoter); } void fputstrn_unfiltered (const char *str, int n, int quoter, - struct ui_file *stream) + do_fputc_ftype do_fputc, struct ui_file *stream) { - int i; - - for (i = 0; i < n; i++) - printchar (str[i], fputs_unfiltered, fprintf_unfiltered, stream, quoter); + for (int i = 0; i < n; i++) + printchar (str[i], do_fputc, stream, quoter); } @@ -1491,9 +1461,7 @@ set_screen_width_and_height (int width, int height) static void prompt_for_continue (void) { - char *ignore; char cont_prompt[120]; - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); /* Used to add duration we waited for user to respond to prompt_for_continue_wait_time. */ using namespace std::chrono; @@ -1516,8 +1484,7 @@ prompt_for_continue (void) /* Call gdb_readline_wrapper, not readline, in order to keep an event loop running. */ - ignore = gdb_readline_wrapper (cont_prompt); - make_cleanup (xfree, ignore); + gdb::unique_xmalloc_ptr ignore (gdb_readline_wrapper (cont_prompt)); /* Add time spend in this routine to prompt_for_continue_wait_time. */ prompt_for_continue_wait_time += steady_clock::now () - prompt_started; @@ -1527,7 +1494,7 @@ prompt_for_continue (void) if (ignore != NULL) { - char *p = ignore; + char *p = ignore.get (); while (*p == ' ' || *p == '\t') ++p; @@ -1541,8 +1508,6 @@ prompt_for_continue (void) reinitialize_more_filter (); dont_repeat (); /* Forget prev cmd -- CR won't repeat it. */ - - do_cleanups (old_chain); } /* Initialize timer to keep track of how long we waited for the user. */ @@ -2636,13 +2601,22 @@ strcmp_iw_ordered (const char *string1, const char *string2) } } -/* A simple comparison function with opposite semantics to strcmp. */ +/* See utils.h. */ -int +bool streq (const char *lhs, const char *rhs) { return !strcmp (lhs, rhs); } + +/* See utils.h. */ + +int +streq_hash (const void *lhs, const void *rhs) +{ + return streq ((const char *) lhs, (const char *) rhs); +} + /* @@ -2963,17 +2937,6 @@ compare_positive_ints (const void *ap, const void *bp) return * (int *) ap - * (int *) bp; } -/* String compare function for qsort. */ - -int -compare_strings (const void *arg1, const void *arg2) -{ - const char **s1 = (const char **) arg1; - const char **s2 = (const char **) arg2; - - return strcmp (*s1, *s2); -} - #define AMBIGUOUS_MESS1 ".\nMatching formats:" #define AMBIGUOUS_MESS2 \ ".\nUse \"set gnutarget format-name\" to specify the format." @@ -3052,30 +3015,6 @@ make_bpstat_clear_actions_cleanup (void) return make_cleanup (do_bpstat_clear_actions_cleanup, NULL); } - -/* Helper for make_cleanup_free_char_ptr_vec. */ - -static void -do_free_char_ptr_vec (void *arg) -{ - VEC (char_ptr) *char_ptr_vec = (VEC (char_ptr) *) arg; - - free_char_ptr_vec (char_ptr_vec); -} - -/* Make cleanup handler calling xfree for each element of CHAR_PTR_VEC and - final VEC_free for CHAR_PTR_VEC itself. - - You must not modify CHAR_PTR_VEC after this cleanup registration as the - CHAR_PTR_VEC base address may change on its updates. Contrary to VEC_free - this function does not (cannot) clear the pointer. */ - -struct cleanup * -make_cleanup_free_char_ptr_vec (VEC (char_ptr) *char_ptr_vec) -{ - return make_cleanup (do_free_char_ptr_vec, char_ptr_vec); -} - /* Substitute all occurences of string FROM by string TO in *STRINGP. *STRINGP must come from xrealloc-compatible allocator and it may be updated. FROM needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be