1
0

debug: add parameters to set ssh addr/port

This commit is contained in:
dump_stack() 2023-02-28 19:11:28 +00:00
parent 71f5530fed
commit 0e153b2763
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 17 additions and 1 deletions

View File

@ -23,6 +23,9 @@ type DebugCmd struct {
Kernel string `help:"regexp (first match)" required:""` Kernel string `help:"regexp (first match)" required:""`
Gdb string `help:"gdb listen address" default:"tcp::1234"` Gdb string `help:"gdb listen address" default:"tcp::1234"`
SshAddr string `help:"ssh address to listen" default:"127.0.0.1"`
SshPort int `help:"ssh port to listen" default:"50022"`
ArtifactConfig string `help:"path to artifact config" type:"path"` ArtifactConfig string `help:"path to artifact config" type:"path"`
Kaslr bool `help:"Enable KASLR"` Kaslr bool `help:"Enable KASLR"`
@ -69,6 +72,11 @@ func (cmd *DebugCmd) Run(g *Globals) (err error) {
return return
} }
err = q.SetSSHAddrPort(cmd.SshAddr, cmd.SshPort)
if err != nil {
return
}
if ka.Qemu.Cpus != 0 { if ka.Qemu.Cpus != 0 {
q.Cpus = ka.Qemu.Cpus q.Cpus = ka.Qemu.Cpus
} }

View File

@ -127,6 +127,12 @@ func NewSystem(arch arch, kernel Kernel, drivePath string) (q *System, err error
return return
} }
func (q *System) SetSSHAddrPort(addr string, port int) (err error) {
// TODO validate
q.sshAddrPort = fmt.Sprintf("%s:%d", addr, port)
return
}
func getRandomAddrPort() (addr string) { func getRandomAddrPort() (addr string) {
// 127.1-255.0-255.0-255:10000-50000 // 127.1-255.0-255.0-255:10000-50000
ip := fmt.Sprintf("127.%d.%d.%d", ip := fmt.Sprintf("127.%d.%d.%d",
@ -215,7 +221,9 @@ func (q System) cmdline() (s string) {
// Start qemu process // Start qemu process
func (q *System) Start() (err error) { func (q *System) Start() (err error) {
rand.Seed(time.Now().UnixNano()) // Are you sure? rand.Seed(time.Now().UnixNano()) // Are you sure?
if q.sshAddrPort == "" {
q.sshAddrPort = getFreeAddrPort() q.sshAddrPort = getFreeAddrPort()
}
hostfwd := fmt.Sprintf("hostfwd=tcp:%s-:22", q.sshAddrPort) hostfwd := fmt.Sprintf("hostfwd=tcp:%s-:22", q.sshAddrPort)
qemuArgs := []string{"-nographic", qemuArgs := []string{"-nographic",
"-hda", q.drivePath, "-hda", q.drivePath,