Cleanup of printing and putsing

This commit is contained in:
Derek Parker
2015-02-27 15:27:48 -06:00
parent 52c8f8e972
commit 7f52928c03
7 changed files with 12 additions and 41 deletions

View File

@ -58,7 +58,6 @@ func NewFrameIndex() FrameDescriptionEntries {
}
func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry, error) {
fmt.Println("fdes for pc")
idx := sort.Search(len(fdes), func(i int) bool {
if fdes[i].Cover(pc) {
return true
@ -72,7 +71,6 @@ func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry,
if idx == len(fdes) {
return nil, fmt.Errorf("could not find FDE for PC %#v", pc)
}
fmt.Println("fin")
return fdes[idx], nil
}

View File

@ -27,6 +27,7 @@ static thread_act_t _global_thread;
kern_return_t
acquire_mach_task(int tid, mach_port_name_t *task, mach_port_t *exception_port) {
kern_return_t kret;
mach_port_t prev_not;
mach_port_t self = mach_task_self();
kret = task_for_pid(self, tid, task);
@ -38,6 +39,10 @@ acquire_mach_task(int tid, mach_port_name_t *task, mach_port_t *exception_port)
kret = mach_port_insert_right(self, *exception_port, *exception_port, MACH_MSG_TYPE_MAKE_SEND);
if (kret != KERN_SUCCESS) return kret;
kret = mach_port_request_notification(self, *task, MACH_NOTIFY_DEAD_NAME, 0, *exception_port, MACH_MSG_TYPE_MAKE_SEND_ONCE,
&prev_not);
if (kret != KERN_SUCCESS) return kret;
// Set exception port
return task_set_exception_ports(*task, EXC_MASK_BREAKPOINT|EXC_MASK_SOFTWARE, *exception_port,
EXCEPTION_DEFAULT, THREAD_STATE_NONE);
@ -91,11 +96,10 @@ typedef struct exc_msg {
thread_act_t
mach_port_wait(mach_port_t port) {
puts("begin mach wait");
mach_msg_return_t msg = mach_msg_server_once(exc_server, sizeof(exc_msg_t), port, MACH_MSG_TIMEOUT_NONE);
if (msg != MACH_MSG_SUCCESS) {
return -1;
}
puts("fin mach wait");
return _global_thread;
}
@ -110,8 +114,6 @@ catch_mach_exception_raise(
mach_exception_data_t code,
mach_msg_type_number_t codeCnt)
{
puts("caught exception raise");
fprintf(stderr, "My exception handler was called by exception_raise()\n");
return KERN_SUCCESS;
}
@ -127,8 +129,6 @@ catch_mach_exception_raise_state(
thread_state_t new_state,
mach_msg_type_number_t *new_stateCnt)
{
puts("caught raise state");
fprintf(stderr, "My exception handler was called by exception_raise()\n");
return KERN_SUCCESS;
}
@ -146,8 +146,6 @@ catch_mach_exception_raise_state_identity(
thread_state_t new_state,
mach_msg_type_number_t *new_stateCnt)
{
puts("caught identity");
fprintf(stderr, "My exception handler was called by exception_raise()\n");
return KERN_SUCCESS;
}
@ -179,8 +177,6 @@ catch_exception_raise_state(
thread_state_t new_state,
mach_msg_type_number_t *new_stateCnt)
{
puts("caught raise state");
fprintf(stderr, "My exception handler was called by exception_raise()\n");
return KERN_SUCCESS;
}
@ -198,7 +194,5 @@ catch_exception_raise_state_identity(
thread_state_t new_state,
mach_msg_type_number_t *new_stateCnt)
{
puts("caught identity");
fprintf(stderr, "My exception handler was called by exception_raise()\n");
return KERN_SUCCESS;
}

View File

@ -95,8 +95,11 @@ func (dbp *DebuggedProcess) updateThreadList() error {
kret C.kern_return_t
th *ThreadContext
count = C.thread_count(C.task_t(dbp.os.task))
list = make([]uint32, count)
)
if count == -1 {
return fmt.Errorf("could not get thread count")
}
list := make([]uint32, count)
// TODO(dp) might be better to malloc mem in C and them free it here
// instead of getting count above and passing in a slice
@ -209,7 +212,7 @@ func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
func trapWait(dbp *DebuggedProcess, pid int) (int, *sys.WaitStatus, error) {
port := C.mach_port_wait(dbp.os.exceptionPort)
if port == 0 {
return -1, nil, fmt.Errorf("mach port wait error")
return -1, nil, ProcessExitedError{}
}
dbp.updateThreadList()

View File

@ -1,5 +1,3 @@
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <libproc.h>
#include <mach/mach.h>

View File

@ -3,7 +3,6 @@ package proctl
import (
"bytes"
"encoding/binary"
"fmt"
"os"
"os/exec"
"path/filepath"
@ -79,16 +78,12 @@ func TestStep(t *testing.T) {
_, err := p.Break(helloworldaddr)
assertNoError(err, t, "Break()")
fmt.Println("continue")
assertNoError(p.Continue(), t, "Continue()")
fmt.Println("fin continue")
regs := getRegisters(p, t)
rip := regs.PC()
fmt.Println("begin step")
err = p.Step()
fmt.Println("fin step")
assertNoError(err, t, "Step()")
regs = getRegisters(p, t)
@ -98,21 +93,6 @@ func TestStep(t *testing.T) {
})
}
func TestContinue(t *testing.T) {
withTestProcess("../_fixtures/continuetestprog", t, func(p *DebuggedProcess) {
err := p.Continue()
if err != nil {
if _, ok := err.(ProcessExitedError); !ok {
t.Fatal(err)
}
}
if p.Status().ExitStatus() != 0 {
t.Fatal("Process did not exit successfully", p.Status().ExitStatus())
}
})
}
func TestBreakPoint(t *testing.T) {
withTestProcess("../_fixtures/testprog", t, func(p *DebuggedProcess) {
helloworldfunc := p.GoSymTable.LookupFunc("main.helloworld")
@ -141,7 +121,6 @@ func TestBreakPointInSeperateGoRoutine(t *testing.T) {
t.Fatal("No fn exists")
}
fmt.Printf("pid is %d set breakpoint for fn at %d\n", p.Pid, fn.Entry)
_, err := p.Break(fn.Entry)
if err != nil {
t.Fatal(err)
@ -240,7 +219,6 @@ func TestNext(t *testing.T) {
f, ln := currentLineNumber(p, t)
for _, tc := range testcases {
fmt.Println("BEGIN-----------------", tc.begin)
if ln != tc.begin {
t.Fatalf("Program not stopped at correct spot expected %d was %s:%d", tc.begin, f, ln)
}

View File

@ -92,6 +92,7 @@ single_step(thread_act_t thread) {
}
}
// TODO(dp) return kret
void
clear_trap_flag(thread_act_t thread) {
kern_return_t kret;

View File

@ -29,7 +29,6 @@ func (t *ThreadContext) singleStep() error {
}
func (t *ThreadContext) cont() error {
// debug.PrintStack()
// TODO(dp) set flag for ptrace stops
if err := PtraceCont(t.Process.Pid, 0); err == nil {
return nil