2

I'm new to waf and trying to implement an analogue to a GNU make trick I often use:

gdb: application.elf
    gdb -x gdbinit-debug $<

That is, allow 'make gdb' to launch an interactive GDB session for debugging.

I've written a GDB task for waf, a feature that uses it, and hooked it up to a top-level command. But I don't see any of the I/O from GDB. It is running, according to ps, but I seem to not be allowed to play along.

Is there a way to make this happen in waf?

Edit: here's the relevant part of the script, I think:

class gdb_task(Task):
    def run(self):
        cmd = [ self.env.GDB, '--silent', '--batch' ]
        for script in self.inputs[:-1]:
            cmd.extend(['-x', script.abspath()])
        cmd.append(self.inputs[-1].abspath())

        return self.exec_command(cmd)

    color = 'CYAN'

    def runnable_status(self):
        return RUN_ME

    def keyword(self):
        return 'GDB'

    def __str__(self):
        node = self.inputs[-1]
        return node.path_from(node.ctx.launch_node())

It works fine, but if i take the --batch off, it just hangs with no output when run.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • Could you post waf wscript reproducing the problem ? This python one-liner works for me: `python -c 'import subprocess; subprocess.call(["gdb", "a.out"])'.` – ks1322 May 26 '17 at 08:39
  • I'm almost certain waf is not using subprocess.call; I think it must be consuming the I/O streams. – Carl Norum May 26 '17 at 16:26

1 Answers1

2

What you want to do is add

from sys import stderr,stdout

and then replace

return self.exec_command(cmd)

with

return self.exec_command(cmd,stdout=stdout,stderr=stderr)

(Tested with Waf 1.9.11 and Python 2.7.6)

Adam
  • 1,342
  • 7
  • 15