From eedd8cb58b131e6a67154b3a6de40b4f2a747fbf Mon Sep 17 00:00:00 2001 From: Hannes Domani Date: Sat, 6 Jul 2024 21:42:22 +0200 Subject: [PATCH] Use the block which contains the symbol for breakpoint conditions Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26651 --- gdb/breakpoint.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 3b14aa17fc4..1dcf9fae685 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1033,6 +1033,19 @@ show_condition_evaluation_mode (struct ui_file *file, int from_tty, value); } +static const block * +block_for_pc_sym (CORE_ADDR pc, const symbol *sym) +{ + if (sym != nullptr) + { + const block *b = sym->value_block (); + if (b != nullptr) + return b; + } + + return block_for_pc (pc); +} + /* Parse COND_STRING in the context of LOC and set as the condition expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is the number of LOC within its owner. In case of parsing error, mark @@ -1046,7 +1059,8 @@ set_breakpoint_location_condition (const char *cond_string, bp_location *loc, try { expression_up new_exp = parse_exp_1 (&cond_string, loc->address, - block_for_pc (loc->address), 0); + block_for_pc_sym (loc->address, + loc->symbol), 0); if (*cond_string != 0) has_junk = true; else @@ -1153,7 +1167,7 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp, { const char *arg = exp; parse_exp_1 (&arg, loc.address, - block_for_pc (loc.address), 0); + block_for_pc_sym (loc.address, loc.symbol), 0); if (*arg != 0) error (_("Junk at end of expression")); break; @@ -2599,7 +2613,7 @@ build_target_condition_list (struct bp_location *bl) Return NULL if there was any error during parsing. */ static agent_expr_up -parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) +parse_cmd_to_aexpr (CORE_ADDR scope, const symbol *sym, char *cmd) { const char *cmdrest; const char *format_start, *format_end; @@ -2643,7 +2657,8 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) const char *cmd1; cmd1 = cmdrest; - expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), + expression_up expr = parse_exp_1 (&cmd1, scope, + block_for_pc_sym (scope, sym), PARSER_COMMA_TERMINATES); argvec.push_back (expr.release ()); cmdrest = cmd1; @@ -2720,7 +2735,7 @@ build_target_command_list (struct bp_location *bl) force_breakpoint_reinsertion). We just need to parse the command to bytecodes again. */ loc->cmd_bytecode - = parse_cmd_to_aexpr (bl->address, + = parse_cmd_to_aexpr (bl->address, bl->symbol, loc->owner->extra_string.get ()); } @@ -8987,7 +9002,7 @@ check_fast_tracepoint_sals (struct gdbarch *gdbarch, PC identifies the context at which the condition should be parsed. */ static void -find_condition_and_thread (const char *tok, CORE_ADDR pc, +find_condition_and_thread (const char *tok, const symtab_and_line &sal, gdb::unique_xmalloc_ptr *cond_string, int *thread, int *inferior, int *task, gdb::unique_xmalloc_ptr *rest) @@ -9023,7 +9038,8 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc, tok = cond_start = end_tok + 1; try { - parse_exp_1 (&tok, pc, block_for_pc (pc), 0); + parse_exp_1 (&tok, sal.pc, + block_for_pc_sym (sal.pc, sal.symbol), 0); } catch (const gdb_exception_error &) { @@ -9141,7 +9157,7 @@ find_condition_and_thread_for_sals (const std::vector &sals, condition in the context of each sal. */ try { - find_condition_and_thread (input, sal.pc, &cond, &thread_id, + find_condition_and_thread (input, sal, &cond, &thread_id, &inferior_id, &task_id, &remaining); *cond_string = std::move (cond); /* A value of -1 indicates that these fields are unset. At most @@ -9377,7 +9393,8 @@ create_breakpoint (struct gdbarch *gdbarch, const char *cond = cond_string; try { - parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); + parse_exp_1 (&cond, sal.pc, + block_for_pc_sym (sal.pc, sal.symbol), 0); /* One success is sufficient to keep going. */ break; } @@ -13071,7 +13088,8 @@ update_breakpoint_locations (code_breakpoint *b, try { new_loc->cond = parse_exp_1 (&s, sal.pc, - block_for_pc (sal.pc), + block_for_pc_sym (sal.pc, + sal.symbol), 0); } catch (const gdb_exception_error &e)