Re: [PATCH] gdb: reject inserting breakpoints between functions

Lancelot SIX via Gdb-patches
2022-06-17T16:26:06Z

Hi,

I have just sent a patch[1] which sits on top of this one. I do not think
there have been feedbacks on this yet, so I'd like to ping on this one on
behalf on Simon.

For what it is worth, I do agree with the change proposed changes as
it is a pre-requisite for what I am proposing in [1].

Thanks,
Lancelot.

[1] https://sourceware.org/pipermail/gdb-patches/2022-June/190150.html

> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index 9d4707cbb4e7..dd31cf2a9fc4 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -2133,11 +2140,44 @@ create_sals_line_offset (struct linespec_state *self,
> struct symbol *sym = (blocks[i]
> ? block_containing_function (blocks[i])
> : NULL);
> + symtab_and_line *sal = &intermediate_results[i];
> +
> + /* Don't consider a match if:
> +
> + - the provided line did not give an exact match (so we started
> + looking for lines below until we found one with code
> + associated to it)
> + - the found location is exactly the start of a function
> + - the provided line is above the declaration line of the function
> +
> + Consider the following source:
> +
> + 10 } // end of a previous function
> + 11
> + 12 int
> + 13 main (void)
> + 14 {
> + 15 int i = 1;
> + 16
> + 17 return 0;
> + 18 }
> +
> + The intent of this heuristic is that a breakpoint requested on
> + line 11 and 12 will not result on a breakpoint on main, but a
> + breakpoint on line 13 will. A breakpoint requested on the empty
> + line 16 will also result in a breakpoint in main, at line 17. */
> + if (!was_exact
> + && sym != nullptr
> + && sym->aclass () == LOC_BLOCK
> + && sal->pc == BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym))

The BLOCK_ENTRY_PC and SYMBOL_BLOCK_VALUE macros have been removed.
This should now be:

+ && sal->pc == sym->value_block ()->entry_pc ()

> + && val.line < sym->line ())
> + continue;
>
> if (self->funfirstline)
> - skip_prologue_sal (&intermediate_results[i]);
> - intermediate_results[i].symbol = sym;
> - add_sal_to_sals (self, &values, &intermediate_results[i],
> + skip_prologue_sal (sal);
> +
> + sal->symbol = sym;
> + add_sal_to_sals (self, &values, sal,
> sym ? sym->natural_name () : NULL, 0);
> }
> }