]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: display program name when reporting crash
authorRuss Cox <rsc@golang.org>
Fri, 26 Sep 2014 17:48:30 +0000 (13:48 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 26 Sep 2014 17:48:30 +0000 (13:48 -0400)
Fix by atom (from CL 89190044), comment and test by me.

Fixes #6823.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=0xe2.0x9a.0x9b, adg, golang-codereviews, iant, r
https://golang.org/cl/148180043

src/cmd/go/build.go
src/cmd/go/test.bash
src/cmd/ld/pobj.c

index c72631ae9e8541b29702412d7fffe3b77bc06e8e..e2e17fd0367f5afc9181ede096da4482044e7632 100644 (file)
@@ -1469,6 +1469,14 @@ func (b *builder) runOut(dir string, desc string, env []string, cmdargs ...inter
                        continue
                }
 
+               // err can be something like 'exit status 1'.
+               // Add information about what program was running.
+               // Note that if buf.Bytes() is non-empty, the caller usually
+               // shows buf.Bytes() and does not print err at all, so the
+               // prefix here does not make most output any more verbose.
+               if err != nil {
+                       err = errors.New(cmdline[0] + ": " + err.Error())
+               }
                return buf.Bytes(), err
        }
 }
index 243467ba9d0715df673784274f641e018d270160..80af61ae0edf83852a1fff446aa9fda0e39260c2 100755 (executable)
@@ -60,6 +60,17 @@ if ! grep -q "^$fn:" $d/err.out; then
 fi
 rm -r $d
 
+TEST 'program name in crash messages'
+linker=$(./testgo env GOCHAR)l
+d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
+./testgo build -ldflags -crash_for_testing $(./testgo env GOROOT)/test/helloworld.go 2>$d/err.out || true
+if ! grep -q "/tool/.*/$linker" $d/err.out; then
+       echo "missing linker name in error message"
+       cat $d/err.out
+       ok=false
+fi
+rm -r $d
+
 # Test local (./) imports.
 testlocal() {
        local="$1"
index 54c5ef247281e84f0b53102d212031c11cf76eaf..63460df30afa9ecbaa85202d73e6f1d13058a16c 100644 (file)
@@ -45,6 +45,8 @@ char* paramspace      = "FP";
 void
 main(int argc, char *argv[])
 {
+       int i;
+
        linkarchinit();
        ctxt = linknew(thelinkarch);
        ctxt->thechar = thechar;
@@ -64,6 +66,13 @@ main(int argc, char *argv[])
        INITENTRY = 0;
        linkmode = LinkAuto;
        
+       // For testing behavior of go command when tools crash.
+       // Undocumented, not in standard flag parser to avoid
+       // exposing in usage message.
+       for(i=1; i<argc; i++)
+               if(strcmp(argv[i], "-crash_for_testing") == 0)
+                       *(volatile int*)0 = 0;
+       
        if(thechar == '5' && ctxt->goarm == 5)
                debug['F'] = 1;