提交 1d99e03f 编写于 作者: D Derek Parker

Reduce exported members of DebuggedProcess struct

上级 ccad114e
......@@ -128,7 +128,7 @@ func threads(p *proctl.DebuggedProcess, args ...string) error {
if err != nil {
return err
}
f, l, fn := th.Process.GoSymTable.PCToLine(pc)
f, l, fn := th.Process.PCToLine(pc)
if fn != nil {
fmt.Printf("%sThread %d at %#v %s:%d %s\n", prefix, th.Id, pc, f, l, fn.Name)
} else {
......@@ -294,16 +294,16 @@ func info(p *proctl.DebuggedProcess, args ...string) error {
switch args[0] {
case "sources":
data = make([]string, 0, len(p.GoSymTable.Files))
for f := range p.GoSymTable.Files {
data = make([]string, 0, len(p.Sources()))
for f := range p.Sources() {
if filter == nil || filter.Match([]byte(f)) {
data = append(data, f)
}
}
case "funcs":
data = make([]string, 0, len(p.GoSymTable.Funcs))
for _, f := range p.GoSymTable.Funcs {
data = make([]string, 0, len(p.Funcs()))
for _, f := range p.Funcs() {
if f.Sym != nil && (filter == nil || filter.Match([]byte(f.Name))) {
data = append(data, f.Name)
}
......@@ -352,7 +352,7 @@ func printcontext(p *proctl.DebuggedProcess) error {
return err
}
f, l, fn := p.GoSymTable.PCToLine(regs.PC())
f, l, fn := p.PCToLine(regs.PC())
if fn != nil {
fmt.Printf("current loc: %s %s:%d\n", fn.Name, f, l)
......
......@@ -72,7 +72,7 @@ func (dbp *DebuggedProcess) newBreakpoint(fn, f string, l int, addr uint64, data
}
func (dbp *DebuggedProcess) setBreakpoint(tid int, addr uint64) (*BreakPoint, error) {
var f, l, fn = dbp.GoSymTable.PCToLine(uint64(addr))
var f, l, fn = dbp.goSymTable.PCToLine(uint64(addr))
if fn == nil {
return nil, InvalidAddressError{address: addr}
}
......
......@@ -27,14 +27,14 @@ import (
type DebuggedProcess struct {
Pid int
Process *os.Process
Dwarf *dwarf.Data
GoSymTable *gosym.Table
FrameEntries frame.FrameDescriptionEntries
LineInfo *line.DebugLineInfo
HWBreakPoints [4]*BreakPoint
BreakPoints map[uint64]*BreakPoint
Threads map[int]*ThreadContext
CurrentThread *ThreadContext
dwarf *dwarf.Data
goSymTable *gosym.Table
frameEntries frame.FrameDescriptionEntries
lineInfo *line.DebugLineInfo
os *OSProcessDetails
ast *source.Searcher
breakpointIDCounter int
......@@ -143,7 +143,7 @@ func (dbp *DebuggedProcess) FindLocation(str string) (uint64, error) {
return 0, err
}
pc, _, err := dbp.GoSymTable.LineToPC(fileName, line)
pc, _, err := dbp.goSymTable.LineToPC(fileName, line)
if err != nil {
return 0, err
}
......@@ -151,7 +151,7 @@ func (dbp *DebuggedProcess) FindLocation(str string) (uint64, error) {
}
// Try to lookup by function name
fn := dbp.GoSymTable.LookupFunc(str)
fn := dbp.goSymTable.LookupFunc(str)
if fn != nil {
return fn.Entry, nil
}
......@@ -335,7 +335,7 @@ func (dbp *DebuggedProcess) resume() error {
}
}
// Check to see if we hit a runtime.breakpoint
fn := dbp.GoSymTable.PCToFunc(pc)
fn := dbp.goSymTable.PCToFunc(pc)
if fn != nil && fn.Name == "runtime.breakpoint" {
// step twice to get back to user code
for i := 0; i < 2; i++ {
......@@ -399,7 +399,19 @@ func (dbp *DebuggedProcess) CallFn(name string, fn func(*ThreadContext) error) e
// Returns a reader for the dwarf data
func (dbp *DebuggedProcess) DwarfReader() *reader.Reader {
return reader.New(dbp.Dwarf)
return reader.New(dbp.dwarf)
}
func (dbp *DebuggedProcess) Sources() map[string]*gosym.Obj {
return dbp.goSymTable.Files
}
func (dbp *DebuggedProcess) Funcs() []gosym.Func {
return dbp.goSymTable.Funcs
}
func (dbp *DebuggedProcess) PCToLine(pc uint64) (string, int, *gosym.Func) {
return dbp.goSymTable.PCToLine(pc)
}
// Finds the breakpoint for the given pc.
......
......@@ -92,7 +92,7 @@ func (dbp *DebuggedProcess) parseDebugFrame(exe *macho.File, wg *sync.WaitGroup)
fmt.Println("could not get __debug_frame section", err)
os.Exit(1)
}
dbp.FrameEntries = frame.Parse(debugFrame)
dbp.frameEntries = frame.Parse(debugFrame)
} else {
fmt.Println("could not find __debug_frame section in binary")
os.Exit(1)
......@@ -131,7 +131,7 @@ func (dbp *DebuggedProcess) obtainGoSymbols(exe *macho.File, wg *sync.WaitGroup)
os.Exit(1)
}
dbp.GoSymTable = tab
dbp.goSymTable = tab
}
func (dbp *DebuggedProcess) parseDebugLineInfo(exe *macho.File, wg *sync.WaitGroup) {
......@@ -143,7 +143,7 @@ func (dbp *DebuggedProcess) parseDebugLineInfo(exe *macho.File, wg *sync.WaitGro
fmt.Println("could not get __debug_line section", err)
os.Exit(1)
}
dbp.LineInfo = line.Parse(debugLine)
dbp.lineInfo = line.Parse(debugLine)
} else {
fmt.Println("could not find __debug_line section in binary")
os.Exit(1)
......@@ -167,7 +167,7 @@ func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
if err != nil {
return nil, err
}
dbp.Dwarf = data
dbp.dwarf = data
return exe, nil
}
......
......@@ -125,7 +125,7 @@ func (dbp *DebuggedProcess) findExecutable() (*elf.File, error) {
if err != nil {
return nil, err
}
dbp.Dwarf = data
dbp.dwarf = data
return elffile, nil
}
......@@ -139,7 +139,7 @@ func (dbp *DebuggedProcess) parseDebugFrame(exe *elf.File, wg *sync.WaitGroup) {
fmt.Println("could not get .debug_frame section", err)
os.Exit(1)
}
dbp.FrameEntries = frame.Parse(debugFrame)
dbp.frameEntries = frame.Parse(debugFrame)
} else {
fmt.Println("could not find .debug_frame section in binary")
os.Exit(1)
......@@ -178,7 +178,7 @@ func (dbp *DebuggedProcess) obtainGoSymbols(exe *elf.File, wg *sync.WaitGroup) {
os.Exit(1)
}
dbp.GoSymTable = tab
dbp.goSymTable = tab
}
func (dbp *DebuggedProcess) parseDebugLineInfo(exe *elf.File, wg *sync.WaitGroup) {
......@@ -190,7 +190,7 @@ func (dbp *DebuggedProcess) parseDebugLineInfo(exe *elf.File, wg *sync.WaitGroup
fmt.Println("could not get .debug_line section", err)
os.Exit(1)
}
dbp.LineInfo = line.Parse(debugLine)
dbp.lineInfo = line.Parse(debugLine)
} else {
fmt.Println("could not find .debug_line section in binary")
os.Exit(1)
......
......@@ -66,7 +66,7 @@ func currentPC(p *DebuggedProcess, t *testing.T) uint64 {
func currentLineNumber(p *DebuggedProcess, t *testing.T) (string, int) {
pc := currentPC(p, t)
f, l, _ := p.GoSymTable.PCToLine(pc)
f, l, _ := p.goSymTable.PCToLine(pc)
return f, l
}
......@@ -89,7 +89,7 @@ func TestExit(t *testing.T) {
func TestStep(t *testing.T) {
withTestProcess("../_fixtures/testprog", t, func(p *DebuggedProcess) {
helloworldfunc := p.GoSymTable.LookupFunc("main.helloworld")
helloworldfunc := p.goSymTable.LookupFunc("main.helloworld")
helloworldaddr := helloworldfunc.Entry
_, err := p.Break(helloworldaddr)
......@@ -111,7 +111,7 @@ func TestStep(t *testing.T) {
func TestBreakPoint(t *testing.T) {
withTestProcess("../_fixtures/testprog", t, func(p *DebuggedProcess) {
helloworldfunc := p.GoSymTable.LookupFunc("main.helloworld")
helloworldfunc := p.goSymTable.LookupFunc("main.helloworld")
helloworldaddr := helloworldfunc.Entry
bp, err := p.Break(helloworldaddr)
......@@ -124,7 +124,7 @@ func TestBreakPoint(t *testing.T) {
}
if pc-1 != bp.Addr && pc != bp.Addr {
f, l, _ := p.GoSymTable.PCToLine(pc)
f, l, _ := p.goSymTable.PCToLine(pc)
t.Fatalf("Break not respected:\nPC:%#v %s:%d\nFN:%#v \n", pc, f, l, bp.Addr)
}
})
......@@ -132,7 +132,7 @@ func TestBreakPoint(t *testing.T) {
func TestBreakPointInSeperateGoRoutine(t *testing.T) {
withTestProcess("../_fixtures/testthreads", t, func(p *DebuggedProcess) {
fn := p.GoSymTable.LookupFunc("main.anotherthread")
fn := p.goSymTable.LookupFunc("main.anotherthread")
if fn == nil {
t.Fatal("No fn exists")
}
......@@ -152,7 +152,7 @@ func TestBreakPointInSeperateGoRoutine(t *testing.T) {
t.Fatal(err)
}
f, l, _ := p.GoSymTable.PCToLine(pc)
f, l, _ := p.goSymTable.PCToLine(pc)
if f != "testthreads.go" && l != 8 {
t.Fatal("Program did not hit breakpoint")
}
......@@ -170,7 +170,7 @@ func TestBreakPointWithNonExistantFunction(t *testing.T) {
func TestClearBreakPoint(t *testing.T) {
withTestProcess("../_fixtures/testprog", t, func(p *DebuggedProcess) {
fn := p.GoSymTable.LookupFunc("main.sleepytime")
fn := p.goSymTable.LookupFunc("main.sleepytime")
bp, err := p.Break(fn.Entry)
assertNoError(err, t, "Break()")
......@@ -227,7 +227,7 @@ func TestNext(t *testing.T) {
}
withTestProcess(executablePath, t, func(p *DebuggedProcess) {
pc, _, _ := p.GoSymTable.LineToPC(fp, testcases[0].begin)
pc, _, _ := p.goSymTable.LineToPC(fp, testcases[0].begin)
_, err := p.Break(pc)
assertNoError(err, t, "Break()")
assertNoError(p.Continue(), t, "Continue()")
......@@ -264,8 +264,8 @@ func TestFindReturnAddress(t *testing.T) {
withTestProcess(testfile, t, func(p *DebuggedProcess) {
var (
fdes = p.FrameEntries
gsd = p.GoSymTable
fdes = p.frameEntries
gsd = p.goSymTable
)
testsourcefile := testfile + ".go"
......@@ -376,7 +376,7 @@ func TestFunctionCall(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fn := p.GoSymTable.PCToFunc(pc)
fn := p.goSymTable.PCToFunc(pc)
if fn == nil {
t.Fatalf("Could not find func for PC: %#v", pc)
}
......@@ -388,7 +388,7 @@ func TestFunctionCall(t *testing.T) {
if err != nil {
t.Fatal(err)
}
f := th.Process.GoSymTable.LookupFunc("runtime.getg")
f := th.Process.goSymTable.LookupFunc("runtime.getg")
if f == nil {
t.Fatalf("could not find function %s", "runtime.getg")
}
......@@ -403,7 +403,7 @@ func TestFunctionCall(t *testing.T) {
if err != nil {
t.Fatal(err)
}
fn = p.GoSymTable.PCToFunc(pc)
fn = p.goSymTable.PCToFunc(pc)
if fn == nil {
t.Fatalf("Could not find func for PC: %#v", pc)
}
......
......@@ -109,7 +109,7 @@ func (thread *ThreadContext) Step() (err error) {
// Call a function named `name`. This is currently _NOT_ safe.
func (thread *ThreadContext) CallFn(name string, fn func(*ThreadContext) error) error {
f := thread.Process.GoSymTable.LookupFunc(name)
f := thread.Process.goSymTable.LookupFunc(name)
if f == nil {
return fmt.Errorf("could not find function %s", name)
}
......@@ -159,13 +159,13 @@ func (thread *ThreadContext) Next() (err error) {
// Grab info on our current stack frame. Used to determine
// whether we may be stepping outside of the current function.
fde, err := thread.Process.FrameEntries.FDEForPC(curpc)
fde, err := thread.Process.frameEntries.FDEForPC(curpc)
if err != nil {
return err
}
// Get current file/line.
f, l, _ := thread.Process.GoSymTable.PCToLine(curpc)
f, l, _ := thread.Process.goSymTable.PCToLine(curpc)
// Find any line we could potentially get to.
lines, err := thread.Process.ast.NextLines(f, l)
......@@ -175,7 +175,7 @@ func (thread *ThreadContext) Next() (err error) {
// Set a breakpoint at every line reachable from our location.
for _, l := range lines {
pcs := thread.Process.LineInfo.AllPCsForFileLine(f, l)
pcs := thread.Process.lineInfo.AllPCsForFileLine(f, l)
for _, pc := range pcs {
if pc == curpc {
continue
......@@ -243,7 +243,7 @@ func (thread *ThreadContext) curG() (*G, error) {
if err != nil {
return err
}
reader := t.Process.Dwarf.Reader()
reader := t.Process.dwarf.Reader()
g, err = parseG(t.Process, regs.SP()+uint64(ptrsize), reader)
return err
})
......
......@@ -49,7 +49,7 @@ func (t *ThreadContext) resume() error {
func (t *ThreadContext) blocked() bool {
// TODO(dp) cache the func pc to remove this lookup
pc, _ := t.CurrentPC()
fn := t.Process.GoSymTable.PCToFunc(pc)
fn := t.Process.goSymTable.PCToFunc(pc)
if fn != nil && ((fn.Name == "runtime.mach_semaphore_wait") || (fn.Name == "runtime.usleep")) {
return true
}
......
......@@ -43,7 +43,7 @@ func (t *ThreadContext) singleStep() error {
func (t *ThreadContext) blocked() bool {
// TODO(dp) cache the func pc to remove this lookup
pc, _ := t.CurrentPC()
fn := t.Process.GoSymTable.PCToFunc(pc)
fn := t.Process.goSymTable.PCToFunc(pc)
if fn != nil && ((fn.Name == "runtime.futex") || (fn.Name == "runtime.usleep") || (fn.Name == "runtime.clone")) {
return true
}
......
......@@ -41,7 +41,7 @@ const ptrsize uintptr = unsafe.Sizeof(int(1))
// Parses and returns select info on the internal M
// data structures used by the Go scheduler.
func (thread *ThreadContext) AllM() ([]*M, error) {
reader := thread.Process.Dwarf.Reader()
reader := thread.Process.dwarf.Reader()
allmaddr, err := parseAllMPtr(thread.Process, reader)
if err != nil {
......@@ -206,7 +206,7 @@ func parseAllMPtr(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
}
func (dbp *DebuggedProcess) PrintGoroutinesInfo() error {
reader := dbp.Dwarf.Reader()
reader := dbp.dwarf.Reader()
allglen, err := allglenval(dbp, reader)
if err != nil {
......@@ -226,7 +226,7 @@ func (dbp *DebuggedProcess) PrintGoroutinesInfo() error {
if err != nil {
return err
}
f, l, fn := dbp.GoSymTable.PCToLine(g.pc)
f, l, fn := dbp.goSymTable.PCToLine(g.pc)
fname := ""
if fn != nil {
fname = fn.Name
......@@ -479,7 +479,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
return nil, fmt.Errorf("type assertion failed")
}
data := thread.Process.Dwarf
data := thread.Process.dwarf
t, err := data.Type(offset)
if err != nil {
return nil, err
......@@ -520,7 +520,7 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
return nil, fmt.Errorf("type assertion failed")
}
data := thread.Process.Dwarf
data := thread.Process.dwarf
t, err := data.Type(offset)
if err != nil {
return nil, err
......@@ -546,7 +546,7 @@ func (thread *ThreadContext) executeStackProgram(instructions []byte) (int64, er
return 0, err
}
fde, err := thread.Process.FrameEntries.FDEForPC(regs.PC())
fde, err := thread.Process.frameEntries.FDEForPC(regs.PC())
if err != nil {
return 0, err
}
......
......@@ -74,7 +74,7 @@ func TestVariableEvaluation(t *testing.T) {
}
withTestProcess(executablePath, t, func(p *DebuggedProcess) {
pc, _, _ := p.GoSymTable.LineToPC(fp, 57)
pc, _, _ := p.goSymTable.LineToPC(fp, 57)
_, err := p.Break(pc)
assertNoError(err, t, "Break() returned an error")
......@@ -105,7 +105,7 @@ func TestVariableFunctionScoping(t *testing.T) {
}
withTestProcess(executablePath, t, func(p *DebuggedProcess) {
pc, _, _ := p.GoSymTable.LineToPC(fp, 57)
pc, _, _ := p.goSymTable.LineToPC(fp, 57)
_, err := p.Break(pc)
assertNoError(err, t, "Break() returned an error")
......@@ -120,7 +120,7 @@ func TestVariableFunctionScoping(t *testing.T) {
assertNoError(err, t, "Unable to find variable a1")
// Move scopes, a1 exists here by a2 does not
pc, _, _ = p.GoSymTable.LineToPC(fp, 23)
pc, _, _ = p.goSymTable.LineToPC(fp, 23)
_, err = p.Break(pc)
assertNoError(err, t, "Break() returned an error")
......@@ -203,7 +203,7 @@ func TestLocalVariables(t *testing.T) {
}
withTestProcess(executablePath, t, func(p *DebuggedProcess) {
pc, _, _ := p.GoSymTable.LineToPC(fp, 57)
pc, _, _ := p.goSymTable.LineToPC(fp, 57)
_, err := p.Break(pc)
assertNoError(err, t, "Break() returned an error")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册