Skip to content
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

debugger: operate on prebuilt binaries with exec command #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ type Debugger struct {
LastState *api.DebuggerState

// Project props
Path string
BinName string
Args []string
Test bool
Path string
BinName string
Args []string
Test bool
PreBuilt bool

// Run state
StackFrame int
Expand All @@ -41,7 +42,7 @@ type Debugger struct {
WatchesExpr []string
}

func NewDebugger(bin string, args []string, runImmediately bool, test bool) (*Debugger, error) {
func NewDebugger(bin string, args []string, runImmediately, test, preBuilt bool) (*Debugger, error) {
wd, _ := os.Getwd()

d := Debugger{
Expand All @@ -50,6 +51,7 @@ func NewDebugger(bin string, args []string, runImmediately bool, test bool) (*De
Args: args,
breakpoints: []*api.Breakpoint{},
Test: test,
PreBuilt: preBuilt,
}

if err := d.InitDebugger(); err != nil {
Expand Down Expand Up @@ -96,8 +98,10 @@ func (d *Debugger) runArgs() []string {
func (d *Debugger) InitDebugger() error {
config := d.DebugConfig()

if err := d.Compile(); err != nil {
return err
if !d.PreBuilt {
if err := d.Compile(); err != nil {
return err
}
}

deb, err := debugger.New(config, append([]string{d.BinName}, d.runArgs()...))
Expand Down Expand Up @@ -368,7 +372,7 @@ func (d *Debugger) Stop() {
func (d *Debugger) Restart() {
d.Stop()

_, err := d.Debugger.Restart(false, "", false, []string{}, [3]string{}, true)
_, err := d.Debugger.Restart(false, "", false, []string{}, [3]string{}, !d.PreBuilt)
if err != nil {
log.Printf("Error restarting: %s", err)
return
Expand Down Expand Up @@ -457,7 +461,6 @@ func (d *Debugger) cacheBreakpoints() {
}

d.breakpoints = abps

}

func (d *Debugger) findBreakpoint(id int) ([]int, []*proc.Breakpoint) {
Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {

cmdAndArgs := os.Args[1:]
if len(cmdAndArgs) == 0 {
log.Fatalln("debugger needs a command: `run` or `test`")
log.Fatalln("debugger needs a command: `run`, `exec` or `test`")
}

cmd := cmdAndArgs[0]
Expand All @@ -33,7 +33,19 @@ func main() {
args = cmdAndArgs[1:]
}

debugger, err := NewDebugger("debug", args, true, cmd == "test")
bin := "debug"

switch cmd {
case "run":
case "test":
case "exec":
bin = args[0]
args = args[1:]
default:
log.Fatalln("invalid command: ", cmd)
}

debugger, err := NewDebugger(bin, args, true, cmd == "test", cmd == "exec")
if err != nil {
log.Fatalln(err.Error())
}
Expand Down