Re: [PATCH v8] gdb: Add source-tracking breakpoints feature
Kevin Buettner <[email protected]>
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Organization | Red Hat |
| Message-ID | <20260717203133.0b3abbde@f44-mesa-1> |
On Tue, 14 Jul 2026 11:40:52 +0200 Alexandra Hajkova <[email protected]> wrote: > +/* Match BREAKPOINT_SRC_CTX_LINES lines of the initially stored source in a > + BREAKPOINT_SRC_CTX_LINES * BREAKPOINT_SRC_SEARCH_MULTIPLIER lines current > + source window. > + > + Returns new breakpoint line on success or -1 on failure. */ > + > +static int > +sliding_window_match (breakpoint_source *bp_source, > + breakpoint_source *tmp_source) > +{ > + /* The index into BP_SOURCE's lines where the breakpoint was placed. */ > + size_t bp_stored = bp_source->bp_line_stored; > + size_t bp_size = bp_source->source_lines.size (); > + > + /* An empty string, used if the breakpoint line is at the start or end of > + the context window. */ > + static std::string empty_string; > + > + /* The lines immediately before and after the breakpoint in BP_SOURCE. > + If the breakpoint is the first or last line in BP_SOURCE then use > + EMPTY_STRING as a stand in. */ > + const std::string &bp_prev > + = (bp_stored == 0 > + ? empty_string : bp_source->source_lines[bp_stored - 1]); > + const std::string &bp_next > + = ((bp_stored + 1) == bp_size > + ? empty_string : bp_source->source_lines[bp_stored + 1]); > + > + /* Now search TMP_SOURCE for the breakpoint line. */ > + size_t tmp_size = tmp_source->source_lines.size (); > + for (size_t i = 0; i < tmp_size; i++) > + { > + if (bp_source->source_lines[bp_stored] == tmp_source->source_lines[i]) > + { > + /* Found the breakpoint line. Capture the lines before and after > + the breakpoint line from TMP_SOURCE. As above, if the > + breakpoint is at the start or end of TMP_SOURCE then use > + EMPTY_STRING as a stand in. */ > + const std::string &tmp_prev > + = (i == 0 ? empty_string : tmp_source->source_lines[i - 1]); > + const std::string &tmp_next > + = ((i + 1) == tmp_size > + ? empty_string : tmp_source->source_lines[i + 1]); > + > + /* If the previous and next lines match then this is the new > + location of the breakpoint, calculate and return the updated > + line number. */ > + if (bp_prev == tmp_prev && bp_next == tmp_next) > + return tmp_source->bp_line + i - tmp_source->bp_line_stored; If BREAKPOINT_SRC_CTX_LINES were changed from 3 to, say, 5 or 7, I don't think that this code will attempt to match all of the lines. It appears to me that it hard codes support for only 3. If the intent is to match the full context window, the algorithm should compare all captured lines, not just the lines before and after the candidate line. If 3-line matching is intentional, the comment or documentation should be updated to clarify that the matching is limited to the breakpoint line and its immediate neighbors, regardless of the BREAKPOINT_SRC_CTX_LINES constant. Kevin