Added comments to gdb_test.go
This commit is contained in:
parent
554ae92194
commit
3d9ecdca27
@ -10,6 +10,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// buildSimple calls make in the testdata-directory in order to build the
|
||||||
|
// test-binary `simple` that is linked against python3.7. If this fails, make
|
||||||
|
// necessary adjustments to the Makefile and/or your environment and try again.
|
||||||
func buildSimple() error {
|
func buildSimple() error {
|
||||||
cmd := exec.Command("make")
|
cmd := exec.Command("make")
|
||||||
cmd.Dir = "testdata"
|
cmd.Dir = "testdata"
|
||||||
@ -19,6 +22,9 @@ func buildSimple() error {
|
|||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestSimpeGDB runs the program testdata/simple multiple times and uses gdb to
|
||||||
|
// extract the address of the symbol _PyRuntime for each pid. It compares
|
||||||
|
// those with the results from Scanner.Run().
|
||||||
func TestSimpleGDB(t *testing.T) {
|
func TestSimpleGDB(t *testing.T) {
|
||||||
ourResults := map[int]uint64{}
|
ourResults := map[int]uint64{}
|
||||||
gdbResults := map[int]uint64{}
|
gdbResults := map[int]uint64{}
|
||||||
@ -43,10 +49,10 @@ func TestSimpleGDB(t *testing.T) {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
simple.Process.Kill()
|
simple.Process.Kill()
|
||||||
go simple.Wait()
|
simple.Wait()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
t.Logf("asking Gdb about PID %d", simple.Process.Pid)
|
t.Logf("Asking Gdb about PID %d", simple.Process.Pid)
|
||||||
|
|
||||||
offset, err := extractOffsetWithGdb(simple.Process.Pid, t)
|
offset, err := extractOffsetWithGdb(simple.Process.Pid, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,8 +76,13 @@ func TestSimpleGDB(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// searchRX should match the output of gdb when it prints the address of the
|
||||||
|
// symbol
|
||||||
var searchRX = regexp.MustCompile(`Symbol "_PyRuntime" is static storage at address 0x([0-9a-fA-F]+)`)
|
var searchRX = regexp.MustCompile(`Symbol "_PyRuntime" is static storage at address 0x([0-9a-fA-F]+)`)
|
||||||
|
|
||||||
|
// extractOffsetWithGdb calls gdb in batch-mode on a pid and looks up the
|
||||||
|
// address of the symbol _PyRuntime by calling `info address _PyRuntime`. If
|
||||||
|
// found, it extracts the address from the gdb-output.
|
||||||
func extractOffsetWithGdb(pid int, t *testing.T) (offset uint64, err error) {
|
func extractOffsetWithGdb(pid int, t *testing.T) (offset uint64, err error) {
|
||||||
cmd := exec.Command("gdb",
|
cmd := exec.Command("gdb",
|
||||||
"--batch",
|
"--batch",
|
||||||
@ -102,5 +113,5 @@ func extractOffsetWithGdb(pid int, t *testing.T) (offset uint64, err error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, fmt.Errorf("symbol not found with gdb")
|
return 0, fmt.Errorf("Symbol not found with gdb")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user