X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fbreakpoint.c;h=055a8c9ee29a3793eac3c13ad02c81b03c33ec6d;hb=3061113bf336048d538241282c39baf684de31bf;hp=8ef3aac0c1aa8baa38b38d6417fba56db783abfc;hpb=491144b5e21bbfd41969c175aebb663976f59058;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8ef3aac0c1..055a8c9ee2 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1,6 +1,6 @@ /* Everything about breakpoints, for GDB. - Copyright (C) 1986-2019 Free Software Foundation, Inc. + Copyright (C) 1986-2020 Free Software Foundation, Inc. This file is part of GDB. @@ -59,9 +59,7 @@ #include "gdb_regex.h" #include "probe.h" #include "cli/cli-utils.h" -#include "continuations.h" #include "stack.h" -#include "skip.h" #include "ax-gdb.h" #include "dummy-frame.h" #include "interps.h" @@ -69,11 +67,9 @@ #include "thread-fsm.h" #include "tid-parse.h" #include "cli/cli-style.h" -#include "mi/mi-main.h" /* readline include files */ -#include "readline/readline.h" -#include "readline/history.h" +#include "readline/tilde.h" /* readline defines this. */ #undef savestring @@ -250,6 +246,9 @@ struct breakpoint_ops bkpt_breakpoint_ops; /* Breakpoints set on probes. */ static struct breakpoint_ops bkpt_probe_breakpoint_ops; +/* Tracepoints set on probes. */ +static struct breakpoint_ops tracepoint_probe_breakpoint_ops; + /* Dynamic printf class type. */ struct breakpoint_ops dprintf_breakpoint_ops; @@ -521,9 +520,9 @@ bool target_exact_watchpoints = false; /* Chains of all breakpoints defined. */ -struct breakpoint *breakpoint_chain; +static struct breakpoint *breakpoint_chain; -/* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ +/* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ static struct bp_location **bp_locations; @@ -777,7 +776,7 @@ show_condition_evaluation_mode (struct ui_file *file, int from_tty, /* A comparison function for bp_location AP and BP that is used by bsearch. This comparison function only cares about addresses, unlike - the more general bp_locations_compare function. */ + the more general bp_location_is_less_than function. */ static int bp_locations_compare_addrs (const void *ap, const void *bp) @@ -1727,7 +1726,7 @@ update_watchpoint (struct watchpoint *b, int reparse) to the user when the old value and the new value may actually be completely different objects. */ b->val = NULL; - b->val_valid = 0; + b->val_valid = false; /* Note that unlike with breakpoints, the watchpoint's condition expression is stored in the breakpoint object, not in the @@ -1780,7 +1779,7 @@ update_watchpoint (struct watchpoint *b, int reparse) if (b->val_bitsize != 0) v = extract_bitfield_from_watchpoint_value (b, v); b->val = release_value (v); - b->val_valid = 1; + b->val_valid = true; } frame_pspace = get_frame_program_space (get_selected_frame (NULL)); @@ -3900,7 +3899,7 @@ breakpoint_init_inferior (enum inf_context context) /* Reset val field to force reread of starting value in insert_breakpoints. */ w->val.reset (nullptr); - w->val_valid = 0; + w->val_valid = false; } } } @@ -4457,7 +4456,7 @@ static void watchpoint_value_print (struct value *val, struct ui_file *stream) { if (val == NULL) - fprintf_unfiltered (stream, _("")); + fprintf_styled (stream, metadata_style.style (), _("")); else { struct value_print_options opts; @@ -4877,7 +4876,7 @@ watchpoint_check (bpstat bs) { bs->old_val = b->val; b->val = release_value (new_val); - b->val_valid = 1; + b->val_valid = true; if (new_val != NULL) value_free_to_mark (mark); return WP_VALUE_CHANGED; @@ -4912,10 +4911,10 @@ watchpoint_check (bpstat bs) if (uiout->is_mi_like_p ()) uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); - uiout->text ("\nWatchpoint "); - uiout->field_signed ("wpnum", b->number); - uiout->text (" deleted because the program has left the block in\n" - "which its expression is valid.\n"); + uiout->message ("\nWatchpoint %pF deleted because the program has " + "left the block in\n" + "which its expression is valid.\n", + signed_field ("wpnum", b->number)); } /* Make sure the watchpoint's commands aren't executed. */ @@ -5822,15 +5821,15 @@ print_breakpoint_location (struct breakpoint *b, if (sym) { uiout->text ("in "); - uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), - ui_out_style_kind::FUNCTION); + uiout->field_string ("func", sym->print_name (), + function_name_style.style ()); uiout->text (" "); uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); uiout->text ("at "); } uiout->field_string ("file", symtab_to_filename_for_display (loc->symtab), - ui_out_style_kind::FILE); + file_name_style.style ()); uiout->text (":"); if (uiout->is_mi_like_p ()) @@ -6055,9 +6054,11 @@ print_one_breakpoint_location (struct breakpoint *b, { annotate_field (4); if (header_of_multiple) - uiout->field_string ("addr", ""); + uiout->field_string ("addr", "", + metadata_style.style ()); else if (b->loc == NULL || loc->shlib_disabled) - uiout->field_string ("addr", ""); + uiout->field_string ("addr", "", + metadata_style.style ()); else uiout->field_core_addr ("addr", loc->gdbarch, loc->address); @@ -6141,10 +6142,9 @@ print_one_breakpoint_location (struct breakpoint *b, && breakpoint_condition_evaluation_mode () == condition_evaluation_target) { - uiout->text (" ("); - uiout->field_string ("evaluated-by", - bp_condition_evaluator (b)); - uiout->text (" evals)"); + uiout->message (" (%pF evals)", + string_field ("evaluated-by", + bp_condition_evaluator (b))); } uiout->text ("\n"); } @@ -6193,9 +6193,8 @@ print_one_breakpoint_location (struct breakpoint *b, if (!part_of_multiple && b->ignore_count) { annotate_field (8); - uiout->text ("\tignore next "); - uiout->field_signed ("ignore", b->ignore_count); - uiout->text (" hits\n"); + uiout->message ("\tignore next %pF hits\n", + signed_field ("ignore", b->ignore_count)); } /* Note that an enable count of 1 corresponds to "enable once" @@ -6658,9 +6657,9 @@ describe_other_breakpoints (struct gdbarch *gdbarch, (others > 1) ? "," : ((others == 1) ? " and" : "")); } - printf_filtered (_("also set at pc ")); - fputs_styled (paddress (gdbarch, pc), address_style.style (), gdb_stdout); - printf_filtered (".\n"); + current_uiout->message (_("also set at pc %ps.\n"), + styled_string (address_style.style (), + paddress (gdbarch, pc))); } } @@ -7089,7 +7088,7 @@ set_breakpoint_location_function (struct bp_location *loc) { struct breakpoint *b = loc->owner; - function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol); + function_name = loc->msymbol->linkage_name (); if (b->type == bp_breakpoint && b->loc == loc && loc->next == NULL && b->related_breakpoint == b) @@ -9167,6 +9166,41 @@ decode_static_tracepoint_spec (const char **arg_p) return sals; } +/* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and + according to IS_TRACEPOINT. */ + +static const struct breakpoint_ops * +breakpoint_ops_for_event_location_type (enum event_location_type location_type, + bool is_tracepoint) +{ + if (is_tracepoint) + { + if (location_type == PROBE_LOCATION) + return &tracepoint_probe_breakpoint_ops; + else + return &tracepoint_breakpoint_ops; + } + else + { + if (location_type == PROBE_LOCATION) + return &bkpt_probe_breakpoint_ops; + else + return &bkpt_breakpoint_ops; + } +} + +/* See breakpoint.h. */ + +const struct breakpoint_ops * +breakpoint_ops_for_event_location (const struct event_location *location, + bool is_tracepoint) +{ + if (location != nullptr) + return breakpoint_ops_for_event_location_type + (event_location_type (location), is_tracepoint); + return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; +} + /* See breakpoint.h. */ int @@ -9348,16 +9382,10 @@ break_command_1 (const char *arg, int flag, int from_tty) enum bptype type_wanted = (flag & BP_HARDWAREFLAG ? bp_hardware_breakpoint : bp_breakpoint); - struct breakpoint_ops *ops; event_location_up location = string_to_event_location (&arg, current_language); - - /* Matching breakpoints on probes. */ - if (location != NULL - && event_location_type (location.get ()) == PROBE_LOCATION) - ops = &bkpt_probe_breakpoint_ops; - else - ops = &bkpt_breakpoint_ops; + const struct breakpoint_ops *ops = breakpoint_ops_for_event_location + (location.get (), false /* is_tracepoint */); create_breakpoint (get_current_arch (), location.get (), @@ -10717,7 +10745,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, w->val = val; w->val_bitpos = saved_bitpos; w->val_bitsize = saved_bitsize; - w->val_valid = 1; + w->val_valid = true; } if (cond_start) @@ -11432,41 +11460,36 @@ breakpoint_auto_delete (bpstat bs) } /* A comparison function for bp_location AP and BP being interfaced to - qsort. Sort elements primarily by their ADDRESS (no matter what + std::sort. Sort elements primarily by their ADDRESS (no matter what bl_address_is_meaningful says), secondarily by ordering first permanent elements and terciarily just ensuring the array is sorted - stable way despite qsort being an unstable algorithm. */ + stable way despite std::sort being an unstable algorithm. */ static int -bp_locations_compare (const void *ap, const void *bp) +bp_location_is_less_than (const bp_location *a, const bp_location *b) { - const struct bp_location *a = *(const struct bp_location **) ap; - const struct bp_location *b = *(const struct bp_location **) bp; - if (a->address != b->address) - return (a->address > b->address) - (a->address < b->address); + return a->address < b->address; /* Sort locations at the same address by their pspace number, keeping locations of the same inferior (in a multi-inferior environment) grouped. */ if (a->pspace->num != b->pspace->num) - return ((a->pspace->num > b->pspace->num) - - (a->pspace->num < b->pspace->num)); + return a->pspace->num < b->pspace->num; /* Sort permanent breakpoints first. */ if (a->permanent != b->permanent) - return (a->permanent < b->permanent) - (a->permanent > b->permanent); + return a->permanent > b->permanent; /* Make the internal GDB representation stable across GDB runs where A and B memory inside GDB can differ. Breakpoint locations of the same type at the same address can be sorted in arbitrary order. */ if (a->owner->number != b->owner->number) - return ((a->owner->number > b->owner->number) - - (a->owner->number < b->owner->number)); + return a->owner->number < b->owner->number; - return (a > b) - (a < b); + return a < b; } /* Set bp_locations_placed_address_before_address_max and @@ -11681,8 +11704,8 @@ update_global_location_list (enum ugll_insert_mode insert_mode) ALL_BREAKPOINTS (b) for (loc = b->loc; loc; loc = loc->next) *locp++ = loc; - qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), - bp_locations_compare); + std::sort (bp_locations, bp_locations + bp_locations_count, + bp_location_is_less_than); bp_locations_target_extensions_update (); @@ -12075,23 +12098,21 @@ say_where (struct breakpoint *b) else { if (opts.addressprint || b->loc->symtab == NULL) - { - printf_filtered (" at "); - fputs_styled (paddress (b->loc->gdbarch, b->loc->address), - address_style.style (), - gdb_stdout); - } + printf_filtered (" at %ps", + styled_string (address_style.style (), + paddress (b->loc->gdbarch, + b->loc->address))); if (b->loc->symtab != NULL) { /* If there is a single location, we can print the location more nicely. */ if (b->loc->next == NULL) { - puts_filtered (": file "); - fputs_styled (symtab_to_filename_for_display (b->loc->symtab), - file_name_style.style (), - gdb_stdout); - printf_filtered (", line %d.", + const char *filename + = symtab_to_filename_for_display (b->loc->symtab); + printf_filtered (": file %ps, line %d.", + styled_string (file_name_style.style (), + filename), b->loc->line_number); } else @@ -12389,18 +12410,18 @@ bkpt_print_it (bpstat bs) annotate_breakpoint (b->number); maybe_print_thread_hit_breakpoint (uiout); - if (bp_temp) - uiout->text ("Temporary breakpoint "); - else - uiout->text ("Breakpoint "); if (uiout->is_mi_like_p ()) { uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); uiout->field_string ("disp", bpdisp_text (b->disposition)); } - uiout->field_signed ("bkptno", b->number); - uiout->text (", "); + if (bp_temp) + uiout->message ("Temporary breakpoint %pF, ", + signed_field ("bkptno", b->number)); + else + uiout->message ("Breakpoint %pF, ", + signed_field ("bkptno", b->number)); return PRINT_SRC_AND_LOC; } @@ -12716,10 +12737,9 @@ tracepoint_print_one_detail (const struct breakpoint *self, { gdb_assert (self->type == bp_static_tracepoint); - uiout->text ("\tmarker id is "); - uiout->field_string ("static-tracepoint-marker-string-id", - tp->static_trace_marker_id); - uiout->text ("\n"); + uiout->message ("\tmarker id is %pF\n", + string_field ("static-tracepoint-marker-string-id", + tp->static_trace_marker_id.c_str ())); } } @@ -12814,8 +12834,7 @@ tracepoint_decode_location (struct breakpoint *b, struct breakpoint_ops tracepoint_breakpoint_ops; -/* The breakpoint_ops structure to be use on tracepoints placed in a - static probe. */ +/* Virtual table for tracepoints on static probes. */ static void tracepoint_probe_create_sals_from_location @@ -12836,8 +12855,6 @@ tracepoint_probe_decode_location (struct breakpoint *b, return bkpt_probe_decode_location (b, location, search_pspace); } -static struct breakpoint_ops tracepoint_probe_breakpoint_ops; - /* Dprintf breakpoint_ops methods. */ static void @@ -13316,13 +13333,13 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) uiout->text ("Now in "); if (sym) { - uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), - ui_out_style_kind::FUNCTION); + uiout->field_string ("func", sym->print_name (), + function_name_style.style ()); uiout->text (" at "); } uiout->field_string ("file", symtab_to_filename_for_display (sal2.symtab), - ui_out_style_kind::FILE); + file_name_style.style ()); uiout->text (":"); if (uiout->is_mi_like_p ()) @@ -14375,7 +14392,7 @@ invalidate_bp_value_on_memory_change (struct inferior *inferior, && addr + len > loc->address) { wp->val = NULL; - wp->val_valid = 0; + wp->val_valid = false; } } } @@ -14479,15 +14496,10 @@ set_tracepoint_count (int num) static void trace_command (const char *arg, int from_tty) { - struct breakpoint_ops *ops; - event_location_up location = string_to_event_location (&arg, current_language); - if (location != NULL - && event_location_type (location.get ()) == PROBE_LOCATION) - ops = &tracepoint_probe_breakpoint_ops; - else - ops = &tracepoint_breakpoint_ops; + const struct breakpoint_ops *ops = breakpoint_ops_for_event_location + (location.get (), true /* is_tracepoint */); create_breakpoint (get_current_arch (), location.get (), @@ -15135,14 +15147,13 @@ save_command (const char *arg, int from_tty) } struct breakpoint * -iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), - void *data) +iterate_over_breakpoints (gdb::function_view callback) { struct breakpoint *b, *b_tmp; ALL_BREAKPOINTS_SAFE (b, b_tmp) { - if ((*callback) (b, data)) + if (callback (b)) return b; }