github.com/undoio/delve@v1.9.0/pkg/proc/proc_linux_test.go (about)

     1  package proc_test
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/undoio/delve/pkg/proc/native"
    10  	protest "github.com/undoio/delve/pkg/proc/test"
    11  )
    12  
    13  func TestLoadingExternalDebugInfo(t *testing.T) {
    14  	fixture := protest.BuildFixture("locationsprog", 0)
    15  	defer os.Remove(fixture.Path)
    16  	stripAndCopyDebugInfo(fixture, t)
    17  	p, err := native.Launch(append([]string{fixture.Path}, ""), "", 0, []string{filepath.Dir(fixture.Path)}, "", [3]string{})
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  	p.Detach(true)
    22  }
    23  
    24  func stripAndCopyDebugInfo(f protest.Fixture, t *testing.T) {
    25  	name := filepath.Base(f.Path)
    26  	// Copy the debug information to an external file.
    27  	copyCmd := exec.Command("objcopy", "--only-keep-debug", name, name+".debug")
    28  	copyCmd.Dir = filepath.Dir(f.Path)
    29  	if err := copyCmd.Run(); err != nil {
    30  		t.Fatal(err)
    31  	}
    32  
    33  	// Strip the original binary of the debug information.
    34  	stripCmd := exec.Command("strip", "--strip-debug", "--strip-unneeded", name)
    35  	stripCmd.Dir = filepath.Dir(f.Path)
    36  	if err := stripCmd.Run(); err != nil {
    37  		t.Fatal(err)
    38  	}
    39  }