用于GNU make的Backtrace

时间:2011-02-17 17:19:56

标签: c makefile gnu-make

有没有办法让GNU make打印导致命令失败时执行的目标的“回溯”?我经常处理严重混淆的makefile,同时解决在新系统上构建软件的可移植性问题,看起来这对于make来说应该是一个非常简单的事情,这将极大地帮助调试,但我找不到任何方式来请求它。我希望看到的是:

gcc: error: ...
make[2]: error: gcc ...
make[2]: error building target bar
make[2]: error building dependency bar for target foo
make[1]: error: make -C subdir
make[1]: error building target subdir
make[1]: error building dependency subdir for target all
...

显示失败命令最终执行的完整依赖路径。

有没有办法做到这一点?

3 个答案:

答案 0 :(得分:4)

使用remake。它是GNU Make的补丁版本,它增加了改进的错误报告,以易于理解的方式跟踪执行的能力以及调试器。

答案 1 :(得分:3)

make -pmake -d提供了有趣的信息,但并不完全是您所要求的。请参阅make's man page

答案 2 :(得分:1)

是的,remake可以为您提供回溯。这是使用翻拍的Makefile显示的一个运行:

    remake --debugger Makefile
    GNU Make 4.1+dbg0.91
    Built for x86_64-unknown-linux-gnu
    Copyright (C) 1988-2014 Free Software Foundation, Inc.
    Copyright (C) 2015 Rocky Bernstein.
    License GPLv3+: GNU GPL version 3 or later 
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Reading makefiles...
    Updating makefiles....
    -> (/src/github/remake/Makefile:608)
    Makefile: Makefile.in config.status
    remake<0> bt
    =>#0  Makefile at /src/github/remake/Makefile:608
    remake<1> s
    -> (/src/github/remake/Makefile:594)
    Makefile.in: 
    remake<2> bt
    =>#0  Makefile.in at /src/github/remake/Makefile:594
      #1  Makefile at /src/github/remake/Makefile:608
    remake<3> s
    -> (/src/github/remake/Makefile:618)
    config.status: configure
    remake<4> bt
    =>#0  config.status at /src/github/remake/Makefile:618
      #1  Makefile at /src/github/remake/Makefile:608
    remake<5> s
    -> (/src/github/remake/Makefile:621)
    configure: 
    remake<6> bt
    =<#0  configure at /src/github/remake/Makefile:621
      #1  config.status at /src/github/remake/Makefile:618
      #2  Makefile at /src/github/remake/Makefile:608
    remake<7> 

您还可以在特定目标(break)设置断点,然后转到那里(continue)和backtrace。如果出现错误,您将获得坠毁时您所处的位置的回溯。

相关问题