From 2f6a87df98d42744f1ee08a1a23563040c4f4517 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 28 Sep 2023 09:09:31 +0200 Subject: [PATCH 1/4] Build lazygit without optimizations and inlining when debugging This makes the debugging experience better. --- pkg/integration/components/runner.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index 821319dc1..09b01a71c 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -42,7 +42,7 @@ func RunTests( testDir := filepath.Join(projectRootDir, "test", "_results") - if err := buildLazygit(raceDetector); err != nil { + if err := buildLazygit(waitForDebugger, raceDetector); err != nil { return err } @@ -138,12 +138,17 @@ func prepareTestDir( return createFixture(test, paths, rootDir) } -func buildLazygit(raceDetector bool) error { +func buildLazygit(debug bool, raceDetector bool) error { // // TODO: remove this line! // // skipping this because I'm not making changes to the app code atm. // return nil args := []string{"go", "build"} + if debug { + // Disable compiler optimizations (-N) and inlining (-l) because this + // makes debugging work better + args = append(args, "-gcflags=all=-N -l") + } if raceDetector { args = append(args, "-race") } From 92e107f52ddea709fa91ebb4ee1df304331cfc7a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 11 Sep 2023 21:25:57 +0200 Subject: [PATCH 2/4] Use constant for WAIT_FOR_DEBUGGER env var --- pkg/integration/clients/injector/main.go | 2 +- pkg/integration/components/runner.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/integration/clients/injector/main.go b/pkg/integration/clients/injector/main.go index 63c3e2a07..223ff4ecb 100644 --- a/pkg/integration/clients/injector/main.go +++ b/pkg/integration/clients/injector/main.go @@ -31,7 +31,7 @@ func main() { integrationTest := getIntegrationTest() - if os.Getenv("WAIT_FOR_DEBUGGER") != "" { + if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) != "" { println("Waiting for debugger to attach...") for !isDebuggerAttached() { time.Sleep(time.Millisecond * 100) diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index 09b01a71c..d84ee4a22 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -16,6 +16,7 @@ import ( const ( TEST_NAME_ENV_VAR = "TEST_NAME" SANDBOX_ENV_VAR = "SANDBOX" + WAIT_FOR_DEBUGGER_ENV_VAR = "WAIT_FOR_DEBUGGER" GIT_CONFIG_GLOBAL_ENV_VAR = "GIT_CONFIG_GLOBAL" ) @@ -215,7 +216,7 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", SANDBOX_ENV_VAR, "true")) } if waitForDebugger { - cmdObj.AddEnvVars("WAIT_FOR_DEBUGGER=true") + cmdObj.AddEnvVars(fmt.Sprintf("%s=true", WAIT_FOR_DEBUGGER_ENV_VAR)) } // Set a race detector log path only to avoid spamming the terminal with the // logs. We are not showing this anywhere yet. From 40b8557608aa318aa15f4a8560e5648a2b5fd427 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 11 Sep 2023 21:28:31 +0200 Subject: [PATCH 3/4] Disable the 40-second timeout for integration tests when debugging Pausing at breakpoints and stepping through code can often take longer than 40s, so the timeout is annoying when debugging. --- pkg/gui/test_mode.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/gui/test_mode.go b/pkg/gui/test_mode.go index e24e922a9..151cb7246 100644 --- a/pkg/gui/test_mode.go +++ b/pkg/gui/test_mode.go @@ -45,10 +45,12 @@ func (gui *Gui) handleTestMode() { log.Fatal("gocui should have already exited") }() - go utils.Safe(func() { - time.Sleep(time.Second * 40) - log.Fatal("40 seconds is up, lazygit recording took too long to complete") - }) + if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == "" { + go utils.Safe(func() { + time.Sleep(time.Second * 40) + log.Fatal("40 seconds is up, lazygit recording took too long to complete") + }) + } } } From e1ceb6892a138b85b50a3270a5451f75f01f99ab Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 28 Sep 2023 09:46:34 +0200 Subject: [PATCH 4/4] Disable deadlock reporting when debugging an integration test --- pkg/gui/gui.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 1f76e281c..2ded4a5c5 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -623,7 +623,10 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error { deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() { gui.g.Close() }) - deadlock.Opts.Disable = !gui.Debug + // disable deadlock reporting if we're not running in debug mode, or if + // we're debugging an integration test. In this latter case, stopping at + // breakpoints and stepping through code can easily take more than 30s. + deadlock.Opts.Disable = !gui.Debug || os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == "" if err := gui.Config.ReloadUserConfig(); err != nil { return nil