Add removing of breakpoints

This commit is contained in:
2026-03-29 17:53:34 +02:00
parent 436a49b1b3
commit bb829286d1
4 changed files with 49 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import (
"io" "io"
"log/slog" "log/slog"
"os/exec" "os/exec"
"slices"
"sync" "sync"
) )
@@ -159,13 +160,19 @@ func (b *Bridge) Step() error {
return nil return nil
} }
func (b *Bridge) Breakpoint(file string, line int) error { func (b *Bridge) Breakpoint(file string, line int) (set bool, err error) {
// Check if breakpoint already exists here
if !b.running { if !b.running {
return ErrNotRunning return false, ErrNotRunning
} }
requestId, cmd := makeCommand(BreakCommand, map[string]any{ var command CommandType
if _, ok := b.breakpoints[file]; ok && slices.Contains(b.breakpoints[file], line) {
command = UnbreakCommand
} else {
command = BreakCommand
}
requestId, cmd := makeCommand(command, map[string]any{
"file": file, "file": file,
"line": line, "line": line,
}) })
@@ -175,18 +182,26 @@ func (b *Bridge) Breakpoint(file string, line int) error {
obj := <-c obj := <-c
var m map[string]any var m map[string]any
err := json.Unmarshal([]byte(obj), &m) err = json.Unmarshal([]byte(obj), &m)
if err != nil { if err != nil {
return err return false, err
} }
if m["status"] != "ok" { if m["status"] != "ok" {
return fmt.Errorf("error occured on break, err: %s", m["error"]) return false, fmt.Errorf("error occured on break, err: %s", m["error"])
} }
b.breakpoints[file] = append(b.breakpoints[file], line) if command == BreakCommand {
b.breakpoints[file] = append(b.breakpoints[file], line)
return true, nil
} else {
breakpointsLen := len(b.breakpoints[file])
index := slices.Index(b.breakpoints[file], line)
b.breakpoints[file][index] = b.breakpoints[file][breakpointsLen-1]
return nil b.breakpoints[file] = b.breakpoints[file][0 : breakpointsLen-1]
return false, nil
}
} }
func (b *Bridge) Continue() error { func (b *Bridge) Continue() error {

View File

@@ -11,6 +11,7 @@ type CommandType string
const ( const (
ContinueCommand CommandType = "continue" ContinueCommand CommandType = "continue"
BreakCommand CommandType = "break" BreakCommand CommandType = "break"
UnbreakCommand CommandType = "unbreak"
LocalsCommand CommandType = "locals" LocalsCommand CommandType = "locals"
StepCommand CommandType = "step" StepCommand CommandType = "step"
) )

View File

@@ -92,6 +92,25 @@ class PyBugBridgeDebugger(bdb.Bdb):
"status": "ok", "status": "ok",
} }
) )
case "unbreak":
err = self.clear_break(cmd["file"], cmd["line"])
if err:
self.send(
{
"request_id": cmd["request_id"],
"event": "unbreak",
"status": "error",
"error": err,
}
)
else:
self.send(
{
"request_id": cmd["request_id"],
"event": "unbreak",
"status": "ok",
}
)
def main(): def main():

View File

@@ -72,7 +72,10 @@ func (m Model) HandleKeyMsg(key tea.KeyMsg) (tea.Model, tea.Cmd) {
case "b": case "b":
lineNumber := m.codeViewer.Cursor + 1 lineNumber := m.codeViewer.Cursor + 1
m.bridge.Breakpoint(m.currentFile, lineNumber) set, err := m.bridge.Breakpoint(m.currentFile, lineNumber)
if err != nil {
slog.Error("could not set or unset breakpoint", "error", err)
}
if file, ok := m.breakpoints[m.currentFile]; ok { if file, ok := m.breakpoints[m.currentFile]; ok {
m.breakpoints[m.currentFile] = append(file, lineNumber) m.breakpoints[m.currentFile] = append(file, lineNumber)
} else { } else {
@@ -83,7 +86,7 @@ func (m Model) HandleKeyMsg(key tea.KeyMsg) (tea.Model, tea.Cmd) {
return m, func() tea.Msg { return m, func() tea.Msg {
// check if this is in currently viewed file // check if this is in currently viewed file
return codeviewer.BreakpointMsg{ return codeviewer.BreakpointMsg{
Added: true, Added: set,
Line: lineNumber, Line: lineNumber,
} }
} }