-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrkmalloc_test.go
More file actions
61 lines (51 loc) · 1.26 KB
/
brkmalloc_test.go
File metadata and controls
61 lines (51 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Distributed under the MIT license. See the LICENSE file.
* Copyright (c) 2014--2016 Thomas Fogal */
package main
import "errors"
import "log"
import "testing"
import "./bfd"
import "./debug"
import "./msg"
import "github.com/tfogal/ptrace"
var tst = msg.StdChan("testing")
func addr_main(program string) uintptr {
symbols, err := bfd.Symbols(program)
if err != nil {
log.Fatalf("err: %v\n", err)
}
symmain := symbol("main", symbols)
return symmain.Address()
}
func startproc(argv []string) (*ptrace.Tracee, error) {
inferior, err := ptrace.Exec(argv[0], argv)
if err != nil {
return nil, err
}
/* wait for 1 event, i.e. the notification that the child has exec'd */
status := <-inferior.Events()
if status == nil {
inferior.Close()
return nil, errors.New("no events?")
}
debug.WaitUntil(inferior, addr_main(argv[0]))
return inferior, nil
}
func TestBreakMalloc(t *testing.T) {
argv := []string{"./testprograms/pauser", "3"}
inferior, err := startproc(argv)
if err != nil {
t.Fatalf("%v\n", err)
}
symbols, err := bfd.SymbolsProcess(inferior)
if err != nil {
t.Fatalf("%v\n", err)
}
malloc := bfd.Symbol{}
for _, sym := range symbols {
if sym.Name() == "malloc" {
malloc = sym
}
}
tst.Printf("malloc is at 0x%x\n", malloc.Address())
}