citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 7eb6f3214cafefcde9e2c48435374e9fbb43a65c
parent a9b6c5a848ffc8f6380c8946f6677c4b72374c7c
Author: Kyle Milz <kyle@windows.krwm.net>
Date:   Mon,  2 Jan 2017 21:50:00 -0800

inst: sometimes cl.exe links too

Diffstat:
Minst_frontend.cc | 9++++++++-
Dt/inst_basic_link.sh | 28----------------------------
At/inst_basic_link.t | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 29 deletions(-)

diff --git a/inst_frontend.cc b/inst_frontend.cc @@ -223,7 +223,14 @@ void InstFrontend::if_link_add_runtime(bool object_arg, bool compile_arg) { #ifdef _WIN32 - bool linking = (std::strcmp(m_args[0], "link") == 0); + bool linking = false; + + if (std::strcmp(m_args[0], "link") == 0) + // If we're called as link.exe we're linking for sure. + linking = true; + if (!compile_arg) + // cl.exe main.c + linking = true; if (!linking) return; diff --git a/t/inst_basic_link.sh b/t/inst_basic_link.sh @@ -1,28 +0,0 @@ -#!/bin/sh -u -# -# Check that the most basic of compile command lines works. -# -. t/utils.subr -plan 4 - -empty_main - -ok "is instrumented compile successful" cc main.c - -cat <<EOF > check.good -Summary: - 1 Source files used as input - 1 Application link commands - 1 Rewrite successes - 1 Rewritten source compile successes - -Totals: - 6 Lines of source code - 1 Function definitions - 1 Return statement values - 3 Total statements -EOF - -ok "running citrun_check" citrun_check -o check.out -strip_millis check.out -ok "citrun_check diff" diff -u check.good check.out diff --git a/t/inst_basic_link.t b/t/inst_basic_link.t @@ -0,0 +1,53 @@ +# +# Check that the most basic of compile command lines works. +# +use strict; +use warnings; +use Test::Cmd; +use Test::Differences; +use Test::More tests => 3; +unified_diff; + + +my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' ); + +$wrap->write( 'main.c', 'int main(void) { return 0; }' ); + +if ($^O eq "MSWin32") { + $wrap->run( args => 'cl /nologo main.c', chdir => $wrap->curdir ); +} else { + $wrap->run( args => 'cc main.c', chdir => $wrap->curdir ); +} + +my $log_good = <<EOF; +>> citrun_inst +CITRUN_SHARE = '' +PATH='' +Found source file '' +Link detected, adding '' to command line. +Modified command line is '' +Added clangtool argument '' +Instrumentation of '' finished: + 1 Lines of source code + 1 Function definitions + 1 Return statement values + 3 Total statements +Modified source written successfully. +Rewriting successful. +Forked compiler '' +Rewritten source compile successful +Restored '' +EOF + +my $citrun_log; +$wrap->read( \$citrun_log, 'citrun.log' ); + +$citrun_log =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; +$citrun_log =~ s/^.*Milliseconds spent.*\n//gm; +$citrun_log =~ s/'.*'/''/gm; +$citrun_log =~ s/^[0-9]+: //gm; + +eq_or_diff( $citrun_log, $log_good, 'is citrun.log file identical', { context => 3 } ); +print $wrap->stdout; +is( $wrap->stderr, '', 'is citrun_wrap stderr empty' ); +is( $? >> 8, 0, 'is citrun_wrap exit code 0' );