-
Notifications
You must be signed in to change notification settings - Fork 0
[14] enhance basic debugger #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0032e63
docs: update Readme
Egzavyer 49be66b
chore: rewrite basic debugger
Egzavyer 8c007b0
chore(lefthook.yml): remove unit and integration tests
Egzavyer 3c384d2
chore: suggested changes
Egzavyer 5304e17
chore(justfile): replace Makefile with justfile
Egzavyer fcce23d
chore: add just
Egzavyer f2075ae
feat: client interface with state tracking
xsachax b666c52
wip: refactor logic into debugger package
Egzavyer 934f238
docs: clean up
Egzavyer b9d3414
fix: prevent client from sending command while not on breakpoint
xsachax 48e6ecf
refactor: rename server-side client to connection
xsachax b57f125
chore: remove dead commented code
xsachax 598ddd3
feat: restructure debugger to be owned by hub with command forwarding
xsachax 5fe4bf5
feat: getSessions endpoint
xsachax 028ce73
feat: create session id when none provided
Egzavyer 3ce2bbc
feat: send ack with sessionID back to client on connect
xsachax d121193
feat: wire debugger to hub
Egzavyer b3eb2e2
feat: adds wiring for setting breakpoints
Egzavyer f344c20
feat: send state update on initial breakpoint
Egzavyer e1efef9
fix: change make to just in lefthook.yml
Egzavyer c90befa
fix: log when parsing failed
Egzavyer bed02f0
wip: bruh
xsachax 982ac37
chore: improve logging
xsachax 06d2bf8
chore: improve dummy client for debugging
xsachax 479c08b
feat: add proper line reader to cli
xsachax 914a7fd
feat: cli config
xsachax 8744cd2
feat: graceful exit
xsachax 52f8547
fix: don't hang client on server shutdown
xsachax f3e45e9
fix: insane clutch
Egzavyer 87f5ff7
fix: send state update on end of debug session
xsachax 35b13bd
fix: remove faulty state updates on client
xsachax 4d1b531
fix: sanitize input path
Egzavyer 240f00a
fix: remove redundant config info
xsachax 15538a3
fix: initialbreakpointhit protocol
Egzavyer 5e92aad
chore: remove incomplete code related to attach
xsachax b92b43b
feat: works
Egzavyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
| "log" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/bingosuite/bingo/config" | ||
| "github.com/bingosuite/bingo/pkg/client" | ||
| "github.com/peterh/liner" | ||
| "golang.org/x/term" | ||
| ) | ||
|
|
||
| func main() { | ||
| cfg, err := config.Load("config/config.yml") | ||
| if err != nil { | ||
| log.Printf("Failed to load config: %v", err) | ||
| } | ||
|
|
||
| if cfg == nil { | ||
| cfg = config.Default() | ||
| } | ||
|
|
||
| defaultAddr := cfg.Server.Addr | ||
| if strings.HasPrefix(defaultAddr, ":") { | ||
| defaultAddr = "localhost" + defaultAddr | ||
| } | ||
|
|
||
| server := flag.String("server", defaultAddr, "WebSocket server host:port") | ||
| session := flag.String("session", "", "Existing session ID (optional)") | ||
| flag.Parse() | ||
|
|
||
| c := client.NewClient(*server, *session) | ||
| if err := c.Connect(); err != nil { | ||
| log.Fatalf("Failed to connect: %v", err) | ||
| } | ||
| if err := c.Run(); err != nil { | ||
| log.Fatalf("Failed to start client: %v", err) | ||
| } | ||
|
|
||
| log.Println("Connected. Commands: start <path>, stop, c=continue, s=step, b=<file> <line>, state, q=quit") | ||
|
|
||
| inputReader := bufio.NewReader(os.Stdin) | ||
| useRawInput := term.IsTerminal(int(os.Stdin.Fd())) | ||
| var lineEditor *liner.State | ||
| if useRawInput { | ||
| lineEditor = liner.NewLiner() | ||
| lineEditor.SetCtrlCAborts(true) | ||
| lineEditor.SetTabCompletionStyle(liner.TabPrints) | ||
| defer func() { | ||
| _ = lineEditor.Close() | ||
| }() | ||
| } | ||
|
|
||
| go func() { | ||
| if err := c.Wait(); err != nil { | ||
| log.Println("Server disconnected") | ||
| if lineEditor != nil { | ||
| _ = lineEditor.Close() | ||
| } | ||
| os.Exit(1) | ||
| } | ||
| }() | ||
|
|
||
| history := make([]string, 0, 64) | ||
|
|
||
| for { | ||
| prompt := "" | ||
| var rawLine string | ||
| var readErr error | ||
| if useRawInput { | ||
| rawLine, readErr = lineEditor.Prompt(prompt) | ||
| } else { | ||
| fmt.Print(prompt) | ||
| line, err := inputReader.ReadString('\n') | ||
| if err != nil { | ||
| if err != io.EOF { | ||
| log.Printf("Stdin error: %v", err) | ||
| } | ||
| break | ||
| } | ||
| rawLine = strings.TrimRight(line, "\r\n") | ||
| } | ||
| if readErr != nil { | ||
| if readErr == liner.ErrPromptAborted || readErr == io.EOF { | ||
| break | ||
| } | ||
| log.Printf("Stdin error: %v", readErr) | ||
| break | ||
| } | ||
|
|
||
| raw := strings.TrimSpace(rawLine) | ||
| if raw != "" { | ||
| if len(history) == 0 || history[len(history)-1] != rawLine { | ||
| history = append(history, rawLine) | ||
| if lineEditor != nil { | ||
| lineEditor.AppendHistory(rawLine) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| input := strings.ToLower(raw) | ||
| fields := strings.Fields(raw) | ||
| var cmdErr error | ||
| switch input { | ||
| case "c", "continue": | ||
| cmdErr = c.Continue() | ||
| time.Sleep(100 * time.Millisecond) | ||
| case "s", "step", "stepover": | ||
| cmdErr = c.StepOver() | ||
| time.Sleep(100 * time.Millisecond) | ||
| case "state": | ||
| fmt.Printf("state=%s session=%s\n", c.State(), c.SessionID()) | ||
| case "stop": | ||
| cmdErr = c.Stop() | ||
| time.Sleep(100 * time.Millisecond) | ||
| case "q", "quit", "exit": | ||
| _ = c.Close() | ||
| return | ||
| case "": | ||
| continue | ||
| default: | ||
| if len(fields) > 0 && strings.EqualFold(fields[0], "start") { | ||
| cmdErr = handleStartCommand(c, fields) | ||
| if cmdErr != nil { | ||
| fmt.Println(cmdErr.Error()) | ||
| cmdErr = nil | ||
| break | ||
| } | ||
| // Give async state updates time to arrive before showing next prompt | ||
| time.Sleep(100 * time.Millisecond) | ||
| break | ||
| } | ||
| cmdErr = handleBreakpointCommand(c, raw) | ||
| if cmdErr != nil { | ||
| fmt.Println(cmdErr.Error()) | ||
| cmdErr = nil | ||
| } | ||
| } | ||
| if cmdErr != nil { | ||
| log.Printf("Command error: %v", cmdErr) | ||
| } | ||
| } | ||
|
|
||
| _ = c.Close() | ||
| } | ||
|
|
||
| func handleBreakpointCommand(c *client.Client, raw string) error { | ||
| fields := strings.Fields(raw) | ||
| if len(fields) == 0 { | ||
| return nil | ||
| } | ||
| cmd := strings.ToLower(fields[0]) | ||
| if cmd != "b" && cmd != "break" && cmd != "breakpoint" { | ||
| return fmt.Errorf("unknown command") | ||
| } | ||
| if len(fields) < 2 || len(fields) > 3 { | ||
| return fmt.Errorf("usage: b <line> or b <file> <line>") | ||
| } | ||
| filename := "" | ||
| lineStr := "" | ||
| if len(fields) == 2 { | ||
| lineStr = fields[1] | ||
| } else { | ||
| filename = fields[1] | ||
| lineStr = fields[2] | ||
| } | ||
| line, err := strconv.Atoi(lineStr) | ||
| if err != nil || line <= 0 { | ||
| return fmt.Errorf("invalid line number") | ||
| } | ||
| return c.SetBreakpoint(filename, line) | ||
| } | ||
|
|
||
| func handleStartCommand(c *client.Client, fields []string) error { | ||
| if len(fields) != 2 { | ||
| return fmt.Errorf("usage: start <path>") | ||
| } | ||
| return c.StartDebug(fields[1]) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.