From 0e813c4cb7079c33d3fa896dd89d6982aa4f45ad Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 25 Sep 2018 20:17:46 +0200 Subject: [PATCH] main: add -no-debug flag to avoid DWARF debug info --- main.go | 17 +++++++++-------- main_test.go | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 59ccf23a..43f09f7a 100644 --- a/main.go +++ b/main.go @@ -16,10 +16,10 @@ import ( ) // Helper function for Compiler object. -func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA bool, printSizes string, action func(string) error) error { +func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA, debug bool, printSizes string, action func(string) error) error { config := compiler.Config{ Triple: spec.Triple, - Debug: true, // TODO: make configurable + Debug: debug, DumpSSA: dumpSSA, RootDir: sourceDir(), BuildTags: spec.BuildTags, @@ -139,13 +139,13 @@ func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA bool, p } } -func Build(pkgName, outpath, target string, printIR, dumpSSA bool, printSizes string) error { +func Build(pkgName, outpath, target string, printIR, dumpSSA, debug bool, printSizes string) error { spec, err := LoadTarget(target) if err != nil { return err } - return Compile(pkgName, outpath, spec, printIR, dumpSSA, printSizes, func(tmppath string) error { + return Compile(pkgName, outpath, spec, printIR, dumpSSA, debug, printSizes, func(tmppath string) error { if err := os.Rename(tmppath, outpath); err != nil { // Moving failed. Do a file copy. inf, err := os.Open(tmppath) @@ -173,13 +173,13 @@ func Build(pkgName, outpath, target string, printIR, dumpSSA bool, printSizes st }) } -func Flash(pkgName, target, port string, printIR, dumpSSA bool, printSizes string) error { +func Flash(pkgName, target, port string, printIR, dumpSSA, debug bool, printSizes string) error { spec, err := LoadTarget(target) if err != nil { return err } - return Compile(pkgName, ".hex", spec, printIR, dumpSSA, printSizes, func(tmppath string) error { + return Compile(pkgName, ".hex", spec, printIR, dumpSSA, debug, printSizes, func(tmppath string) error { // Create the command. flashCmd := spec.Flasher flashCmd = strings.Replace(flashCmd, "{hex}", tmppath, -1) @@ -247,6 +247,7 @@ func main() { dumpSSA := flag.Bool("dumpssa", false, "dump internal Go SSA") target := flag.String("target", llvm.DefaultTargetTriple(), "LLVM target") printSize := flag.String("size", "", "print sizes (none, short, full)") + nodebug := flag.Bool("no-debug", false, "disable DWARF debug symbol generation") port := flag.String("port", "/dev/ttyACM0", "flash port") if len(os.Args) < 2 { @@ -272,7 +273,7 @@ func main() { usage() os.Exit(1) } - err := Build(flag.Arg(0), *outpath, *target, *printIR, *dumpSSA, *printSize) + err := Build(flag.Arg(0), *outpath, *target, *printIR, *dumpSSA, !*nodebug, *printSize) if err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) @@ -283,7 +284,7 @@ func main() { usage() os.Exit(1) } - err := Flash(flag.Arg(0), *target, *port, *printIR, *dumpSSA, *printSize) + err := Flash(flag.Arg(0), *target, *port, *printIR, *dumpSSA, !*nodebug, *printSize) if err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) diff --git a/main_test.go b/main_test.go index d6680720..21f6c702 100644 --- a/main_test.go +++ b/main_test.go @@ -52,7 +52,7 @@ func runTest(path, tmpdir string, t *testing.T) { // Build the test binary. binary := filepath.Join(tmpdir, "test") - err = Build(path, binary, "", false, false, "") + err = Build(path, binary, "", false, false, false, "") if err != nil { t.Log("failed to build:", err) t.Fail()