ponylang / corral

:horse: Pony dependency manager tool
https://ponylang.io
BSD 2-Clause "Simplified" License
194 stars 20 forks source link

Allow use of lldb for corral run target #82

Open KittyMac opened 4 years ago

KittyMac commented 4 years ago

With stable it was possible for me to debug ponyc while invoking it from the stable env.

stable env lldb ponyc -- -p ./lib/osx/  --pic 

With corral this doesn't seem to be possible:

beast:pony.bzip2 rjbowli$ corral run -- lldb ponyc
run: lldb ponyc
  exit: 0
  out: (lldb) target create "ponyc"
Current executable set to 'ponyc' (x86_64).

  err: 
beast:pony.bzip2 rjbowli$ 

I don't know if there is a work-around I am missing? If not, I will probably dig into fixing this tomorrow as this is a showstopper for me.

KittyMac commented 4 years ago

ok, got this working.

What I did was added another command ("exec") and all it does is execve() without forking, thus leaving all of the stdin/stdout/stderr in place for lldb to run. Not sure what kind of processing corral needs to after running the command (nothing I assume?).

Snippet from the apply() in CmdRun:

      // if we use the exec option, replace this process with the run command
      // allows for use of things like corral run -- lldb ponyc
      if exec then
        let cargs = Array[Pointer[U8] tag](32)
        for a in args.values() do
          cargs.push(a.cstring())
        end
        cargs.push(Pointer[U8])

        let cvars = Array[Pointer[U8] tag](32)
        for a in vars.values() do
          cvars.push(a.cstring())
        end
        cvars.push(Pointer[U8])

        @execve[I32](prog.path.path.cstring(), cargs.cpointer(), cvars.cpointer())
      end

      let a = Action(prog, recover args.slice(1) end, vars)
      if not ctx.nothing then
        Runner.run(a, {(result: ActionResult) => 
          result.print_to(ctx.env.out)
          if result.exit_code != 0 then
            ctx.env.exitcode(result.exit_code)
          end
        })
      end
SeanTAllen commented 4 years ago

@cquinn do you have any feedback?

KittyMac commented 4 years ago

one more noodle I missed.

corral exec -- lldb ponyc -- -p $(libdir)/osx/ --pic -b StarbaseOrionCore -o $(builddir)

By the time it gets to that @execve() mentioned above, the second "--" needed by lldb has been dropped from the args list. Looking as to why...

KittyMac commented 4 years ago

for the second (and any more) "--" being ignored corral is not at fault. The answer lies in command_parser.pony, _parse_command()

      let token = try tokens.shift()? else "" end
      if token == "--" then
        opt_stop = true

The above code eats all "--" option stops in the command line. I am unsure of the standard behind "--", but it seems logical to me that it should only swallow the first option stop and then leave the rest of the arguments unaltered.

      let token = try tokens.shift()? else "" end
      if (token == "--") and (opt_stop == false) then
        opt_stop = true

The above patch works for the issue described here.

cquinn commented 4 years ago

This sounds good to me.

KittyMac commented 4 years ago

@cquinn i did not make a PR. Would you like me to (both for the corral change and the ponyc/command_parser change)?

SeanTAllen commented 4 years ago

@KittyMac can you open a PR for these changes? it would be greatly appreciated.

KittyMac commented 4 years ago

https://github.com/ponylang/corral/pull/104

https://github.com/ponylang/ponyc/pull/3541