X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fguile%2Fscm-pretty-print.c;h=d621ed5e912f049e286d632074cf708b9899f6a7;hb=aed57c537116ae91f553ac835b3f96d1f87b3bb0;hp=a28e4e685ff8e6321b138496447618f86285102e;hpb=61baf725eca99af2569262d10aca03dcde2698f6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c index a28e4e685f..d621ed5e91 100644 --- a/gdb/guile/scm-pretty-print.c +++ b/gdb/guile/scm-pretty-print.c @@ -1,6 +1,6 @@ /* GDB/Scheme pretty-printing. - Copyright (C) 2008-2017 Free Software Foundation, Inc. + Copyright (C) 2008-2019 Free Software Foundation, Inc. This file is part of GDB. @@ -327,16 +327,10 @@ gdbscm_pretty_printer_worker_p (SCM scm) static SCM ppscm_make_pp_type_error_exception (const char *message, SCM object) { - char *msg = xstrprintf ("%s: ~S", message); - struct cleanup *cleanup = make_cleanup (xfree, msg); - SCM exception - = gdbscm_make_error (pp_type_error_symbol, - NULL /* func */, msg, - scm_list_1 (object), scm_list_1 (object)); - - do_cleanups (cleanup); - - return exception; + std::string msg = string_printf ("%s: ~S", message); + return gdbscm_make_error (pp_type_error_symbol, + NULL /* func */, msg.c_str (), + scm_list_1 (object), scm_list_1 (object)); } /* Print MESSAGE as an exception (meaning it is controlled by @@ -381,7 +375,6 @@ ppscm_search_pp_list (SCM list, SCM value) SCM matcher = scm_car (list); SCM worker; pretty_printer_smob *pp_smob; - int rc; if (!ppscm_is_pretty_printer (matcher)) { @@ -434,19 +427,18 @@ ppscm_search_pp_list (SCM list, SCM value) static SCM ppscm_find_pretty_printer_from_objfiles (SCM value) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) - { - objfile_smob *o_smob = ofscm_objfile_smob_from_objfile (objfile); - SCM pp = ppscm_search_pp_list (ofscm_objfile_smob_pretty_printers (o_smob), - value); - - /* Note: This will return if pp is a object, - which is what we want. */ - if (gdbscm_is_true (pp)) - return pp; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + objfile_smob *o_smob = ofscm_objfile_smob_from_objfile (objfile); + SCM pp + = ppscm_search_pp_list (ofscm_objfile_smob_pretty_printers (o_smob), + value); + + /* Note: This will return if pp is a object, + which is what we want. */ + if (gdbscm_is_true (pp)) + return pp; + } return SCM_BOOL_F; } @@ -534,7 +526,6 @@ ppscm_pretty_print_one_value (SCM printer, struct value **out_value, *out_value = NULL; TRY { - int rc; pretty_printer_worker_smob *w_smob = (pretty_printer_worker_smob *) SCM_SMOB_DATA (printer); @@ -622,25 +613,24 @@ ppscm_print_exception_unless_memory_error (SCM exception, { if (gdbscm_memory_error_p (gdbscm_exception_key (exception))) { - char *msg = gdbscm_exception_message_to_string (exception); - struct cleanup *cleanup = make_cleanup (xfree, msg); + gdb::unique_xmalloc_ptr msg + = gdbscm_exception_message_to_string (exception); /* This "shouldn't happen", but play it safe. */ - if (msg == NULL || *msg == '\0') + if (msg == NULL || msg.get ()[0] == '\0') fprintf_filtered (stream, _("")); else { /* Remove the trailing newline. We could instead call a special routine for printing memory error messages, but this is easy enough for now. */ - size_t len = strlen (msg); + char *msg_text = msg.get (); + size_t len = strlen (msg_text); - if (msg[len - 1] == '\n') - msg[len - 1] = '\0'; - fprintf_filtered (stream, _(""), msg); + if (msg_text[len - 1] == '\n') + msg_text[len - 1] = '\0'; + fprintf_filtered (stream, _(""), msg_text); } - - do_cleanups (cleanup); } else gdbscm_print_gdb_exception (SCM_BOOL_F, exception); @@ -677,18 +667,16 @@ ppscm_print_string_repr (SCM printer, enum display_hint hint, } else if (scm_is_string (str_scm)) { - struct cleanup *cleanup; size_t length; - char *string + gdb::unique_xmalloc_ptr string = gdbscm_scm_to_string (str_scm, &length, target_charset (gdbarch), 0 /*!strict*/, NULL); - cleanup = make_cleanup (xfree, string); if (hint == HINT_STRING) { struct type *type = builtin_type (gdbarch)->builtin_char; - LA_PRINT_STRING (stream, type, (gdb_byte *) string, + LA_PRINT_STRING (stream, type, (gdb_byte *) string.get (), length, NULL, 0, options); } else @@ -699,14 +687,13 @@ ppscm_print_string_repr (SCM printer, enum display_hint hint, for (i = 0; i < length; ++i) { - if (string[i] == '\0') + if (string.get ()[i] == '\0') fputs_filtered ("\\000", stream); else - fputc_filtered (string[i], stream); + fputc_filtered (string.get ()[i], stream); } } result = STRING_REPR_OK; - do_cleanups (cleanup); } else if (lsscm_is_lazy_string (str_scm)) { @@ -744,9 +731,8 @@ ppscm_print_children (SCM printer, enum display_hint hint, = (pretty_printer_worker_smob *) SCM_SMOB_DATA (printer); int is_map, is_array, done_flag, pretty; unsigned int i; - SCM children, status; + SCM children; SCM iter = SCM_BOOL_F; /* -Wall */ - struct cleanup *cleanups; if (gdbscm_is_false (w_smob->children)) return; @@ -758,8 +744,6 @@ ppscm_print_children (SCM printer, enum display_hint hint, return; } - cleanups = make_cleanup (null_cleanup, NULL); - /* If we are printing a map or an array, we want special formatting. */ is_map = hint == HINT_MAP; is_array = hint == HINT_ARRAY; @@ -799,11 +783,8 @@ ppscm_print_children (SCM printer, enum display_hint hint, done_flag = 0; for (i = 0; i < options->print_max; ++i) { - int rc; SCM scm_name, v_scm; - char *name; SCM item = itscm_safe_call_next_x (iter, gdbscm_memory_error_p); - struct cleanup *inner_cleanup = make_cleanup (null_cleanup, NULL); if (gdbscm_is_exception (item)) { @@ -835,8 +816,8 @@ ppscm_print_children (SCM printer, enum display_hint hint, " a string"), item); continue; } - name = gdbscm_scm_to_c_string (scm_name); - make_cleanup (xfree, name); + gdb::unique_xmalloc_ptr name + = gdbscm_scm_to_c_string (scm_name); /* Print initial "{". For other elements, there are three cases: 1. Maps. Print a "," after each value element. @@ -887,7 +868,7 @@ ppscm_print_children (SCM printer, enum display_hint hint, } else if (! is_map) { - fputs_filtered (name, stream); + fputs_filtered (name.get (), stream); fputs_filtered (" = ", stream); } @@ -900,10 +881,9 @@ ppscm_print_children (SCM printer, enum display_hint hint, } else if (scm_is_string (v_scm)) { - char *output = gdbscm_scm_to_c_string (v_scm); - - fputs_filtered (output, stream); - xfree (output); + gdb::unique_xmalloc_ptr output + = gdbscm_scm_to_c_string (v_scm); + fputs_filtered (output.get (), stream); } else { @@ -923,8 +903,6 @@ ppscm_print_children (SCM printer, enum display_hint hint, if (is_map && i % 2 == 0) fputs_filtered ("] = ", stream); - - do_cleanups (inner_cleanup); } if (i) @@ -947,8 +925,6 @@ ppscm_print_children (SCM printer, enum display_hint hint, } done: - do_cleanups (cleanups); - /* Play it safe, make sure ITER doesn't get GC'd. */ scm_remember_upto_here_1 (iter); } @@ -970,10 +946,11 @@ gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang, SCM val_obj = SCM_BOOL_F; struct value *value; enum display_hint hint; - struct cleanup *cleanups; enum ext_lang_rc result = EXT_LANG_RC_NOP; enum string_repr_result print_result; - const gdb_byte *valaddr = value_contents_for_printing (val); + + if (value_lazy (val)) + value_fetch_lazy (val); /* No pretty-printer support for unavailable values. */ if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) @@ -982,8 +959,6 @@ gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang, if (!gdb_scheme_initialized) return EXT_LANG_RC_NOP; - cleanups = make_cleanup (null_cleanup, NULL); - /* Instantiate the printer. */ value = value_from_component (val, type, embedded_offset); @@ -1037,7 +1012,6 @@ gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang, done: if (gdbscm_is_exception (exception)) ppscm_print_exception_unless_memory_error (exception, stream); - do_cleanups (cleanups); return result; }