How to trace Makefile targets for troubleshooting?

故事扮演 提交于 2019-11-28 21:21:16

Use make -d or make --debug[=flags] options:

‘-d’

Print debugging information in addition to normal processing. The debugging information says which files are being considered for remaking, which file-times are being compared and with what results, which files actually need to be remade, which implicit rules are considered and which are applied—everything interesting about how make decides what to do. The -d option is equivalent to ‘--debug=a’ (see below).

‘--debug[=options]’

Print debugging information in addition to normal processing. Various levels and types of output can be chosen. With no arguments, print the “basic” level of debugging. Possible arguments are below; only the first character is considered, and values must be comma- or space-separated.

a (all) All types of debugging output are enabled. This is equivalent to using ‘-d’.

b (basic) Basic debugging prints each target that was found to be out-of-date, and whether the build was successful or not.

v (verbose) A level above ‘basic’; includes messages about which makefiles were parsed, prerequisites that did not need to be rebuilt, etc. This option also enables ‘basic’ messages.

i (implicit) Prints messages describing the implicit rule searches for each target. This option also enables ‘basic’ messages.

j (jobs) Prints messages giving details on the invocation of specific subcommands.

m (makefile) By default, the above messages are not enabled while trying to remake the makefiles. This option enables messages while rebuilding makefiles, too. Note that the ‘all’ option does enable this option. This option also enables ‘basic’ messages.

Another option is to use remake - a patched version of GNU Make that adds improved error reporting, the ability to trace execution, and a debugger.

ElectricMake can generate an XML-marked-up version of your build log with lots of information that would help in this situation:

  • The full command-lines for all commands invoked during the build (even those that were marked as "silent" commands with the @ modifier).
  • The origin (makefile and line number) of the commands invoked.
  • Runtime of the commands.
  • Dependency relationships between the targets in the build.
  • Structural relationship between targets and recursive makes in the build.
  • Files read/written by the commands invoked in the build.

Here's a sample of that output:

<job id="J0824ab08" thread="5e72bb0" node="linbuild1-2" type="rule" name="../../i686_Linux/testmain/testmain.d" file="../config/rules.mak" line="109">
<command line="110">
<argv>echo Rebuilding '../../i686_Linux/testmain/testmain.d'</argv>
<output src="prog">Rebuilding ../../i686_Linux/testmain/testmain.d
</output>
</command>
<command line="111-114">
<argv>set -e; g++ -MM -w  -DUSE_PROFILING -DUSE_LOGGING -DHAVE_UNIX -DHAVE_LINUX -I.. testmain.cpp \
        | sed 's!\(testmain\)\.o[ :]*!../../i686_Linux/testmain/\1.o '../../i686_Linux/testmain/testmain.d' : !g' \
        &gt; '../../i686_Linux/testmain/testmain.d'; \
        [ -s '../../i686_Linux/testmain/testmain.d' ] || touch '../../i686_Linux/testmain/testmain.d'</argv>
</command>
<opList>
<op type="read" file="/home/ericm/src/testmain/testmain.cpp"/>
<op type="read" file="/home/ericm/src/minidumper/ExceptionReport.h"/>
<op type="read" file="/home/ericm/src/util/ECAssert.h"/>
<op type="create" file="/home/ericm/i686_Linux/ecloud/testmain/testmain.d" found="0"/>
</opList>
<timing invoked="1.919926" completed="3.600491" node="linbuild1-2"/>
<waitingJobs idList="J0824ae38"/>
</job>

How to Quickly Navigate an Unfamiliar Makefile shows an example of using the annotated build log to find your way around a makefile.

Data Mining ElectricAccelerator Annotation shows how you can use the annotated build log to generate a bill-of-materials for the build.

ElectricMake is GNU Make compatible, so it can process makefiles that work with GNU make.

Disclaimer: I'm the architect and lead developer of ElectricAccelerator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!