mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-04 06:32:16 +08:00 
			
		
		
		
	Cleanup of printing and putsing
This commit is contained in:
		@ -58,7 +58,6 @@ func NewFrameIndex() FrameDescriptionEntries {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry, error) {
 | 
					func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry, error) {
 | 
				
			||||||
	fmt.Println("fdes for pc")
 | 
					 | 
				
			||||||
	idx := sort.Search(len(fdes), func(i int) bool {
 | 
						idx := sort.Search(len(fdes), func(i int) bool {
 | 
				
			||||||
		if fdes[i].Cover(pc) {
 | 
							if fdes[i].Cover(pc) {
 | 
				
			||||||
			return true
 | 
								return true
 | 
				
			||||||
@ -72,7 +71,6 @@ func (fdes FrameDescriptionEntries) FDEForPC(pc uint64) (*FrameDescriptionEntry,
 | 
				
			|||||||
	if idx == len(fdes) {
 | 
						if idx == len(fdes) {
 | 
				
			||||||
		return nil, fmt.Errorf("could not find FDE for PC %#v", pc)
 | 
							return nil, fmt.Errorf("could not find FDE for PC %#v", pc)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	fmt.Println("fin")
 | 
					 | 
				
			||||||
	return fdes[idx], nil
 | 
						return fdes[idx], nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -27,6 +27,7 @@ static thread_act_t _global_thread;
 | 
				
			|||||||
kern_return_t
 | 
					kern_return_t
 | 
				
			||||||
acquire_mach_task(int tid, mach_port_name_t *task, mach_port_t *exception_port) {
 | 
					acquire_mach_task(int tid, mach_port_name_t *task, mach_port_t *exception_port) {
 | 
				
			||||||
  kern_return_t kret;
 | 
					  kern_return_t kret;
 | 
				
			||||||
 | 
					  mach_port_t prev_not;
 | 
				
			||||||
  mach_port_t self = mach_task_self();
 | 
					  mach_port_t self = mach_task_self();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  kret = task_for_pid(self, tid, task);
 | 
					  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);
 | 
					  kret = mach_port_insert_right(self, *exception_port, *exception_port, MACH_MSG_TYPE_MAKE_SEND);
 | 
				
			||||||
  if (kret != KERN_SUCCESS) return kret;
 | 
					  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
 | 
					  // Set exception port
 | 
				
			||||||
  return task_set_exception_ports(*task, EXC_MASK_BREAKPOINT|EXC_MASK_SOFTWARE, *exception_port,
 | 
					  return task_set_exception_ports(*task, EXC_MASK_BREAKPOINT|EXC_MASK_SOFTWARE, *exception_port,
 | 
				
			||||||
    EXCEPTION_DEFAULT, THREAD_STATE_NONE);
 | 
					    EXCEPTION_DEFAULT, THREAD_STATE_NONE);
 | 
				
			||||||
@ -91,11 +96,10 @@ typedef struct exc_msg {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
thread_act_t
 | 
					thread_act_t
 | 
				
			||||||
mach_port_wait(mach_port_t port) {
 | 
					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);
 | 
					  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) {
 | 
					  if (msg != MACH_MSG_SUCCESS) {
 | 
				
			||||||
 | 
					    return -1;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  puts("fin mach wait");
 | 
					 | 
				
			||||||
  return _global_thread;
 | 
					  return _global_thread;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -110,8 +114,6 @@ catch_mach_exception_raise(
 | 
				
			|||||||
  mach_exception_data_t code,
 | 
					  mach_exception_data_t code,
 | 
				
			||||||
  mach_msg_type_number_t codeCnt)
 | 
					  mach_msg_type_number_t codeCnt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  puts("caught exception raise");
 | 
					 | 
				
			||||||
  fprintf(stderr, "My exception handler was called by exception_raise()\n");
 | 
					 | 
				
			||||||
  return KERN_SUCCESS;
 | 
					  return KERN_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -127,8 +129,6 @@ catch_mach_exception_raise_state(
 | 
				
			|||||||
  thread_state_t new_state,
 | 
					  thread_state_t new_state,
 | 
				
			||||||
  mach_msg_type_number_t *new_stateCnt)
 | 
					  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;
 | 
					  return KERN_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -146,8 +146,6 @@ catch_mach_exception_raise_state_identity(
 | 
				
			|||||||
  thread_state_t new_state,
 | 
					  thread_state_t new_state,
 | 
				
			||||||
  mach_msg_type_number_t *new_stateCnt)
 | 
					  mach_msg_type_number_t *new_stateCnt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  puts("caught identity");
 | 
					 | 
				
			||||||
  fprintf(stderr, "My exception handler was called by exception_raise()\n");
 | 
					 | 
				
			||||||
  return KERN_SUCCESS;
 | 
					  return KERN_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -179,8 +177,6 @@ catch_exception_raise_state(
 | 
				
			|||||||
  thread_state_t new_state,
 | 
					  thread_state_t new_state,
 | 
				
			||||||
  mach_msg_type_number_t *new_stateCnt)
 | 
					  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;
 | 
					  return KERN_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -198,7 +194,5 @@ catch_exception_raise_state_identity(
 | 
				
			|||||||
  thread_state_t new_state,
 | 
					  thread_state_t new_state,
 | 
				
			||||||
  mach_msg_type_number_t *new_stateCnt)
 | 
					  mach_msg_type_number_t *new_stateCnt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  puts("caught identity");
 | 
					 | 
				
			||||||
  fprintf(stderr, "My exception handler was called by exception_raise()\n");
 | 
					 | 
				
			||||||
  return KERN_SUCCESS;
 | 
					  return KERN_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -95,8 +95,11 @@ func (dbp *DebuggedProcess) updateThreadList() error {
 | 
				
			|||||||
		kret  C.kern_return_t
 | 
							kret  C.kern_return_t
 | 
				
			||||||
		th    *ThreadContext
 | 
							th    *ThreadContext
 | 
				
			||||||
		count = C.thread_count(C.task_t(dbp.os.task))
 | 
							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
 | 
						// 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
 | 
						// 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) {
 | 
					func trapWait(dbp *DebuggedProcess, pid int) (int, *sys.WaitStatus, error) {
 | 
				
			||||||
	port := C.mach_port_wait(dbp.os.exceptionPort)
 | 
						port := C.mach_port_wait(dbp.os.exceptionPort)
 | 
				
			||||||
	if port == 0 {
 | 
						if port == 0 {
 | 
				
			||||||
		return -1, nil, fmt.Errorf("mach port wait error")
 | 
							return -1, nil, ProcessExitedError{}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dbp.updateThreadList()
 | 
						dbp.updateThreadList()
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,3 @@
 | 
				
			|||||||
#include <errno.h>
 | 
					 | 
				
			||||||
#include <stdio.h>
 | 
					 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
#include <libproc.h>
 | 
					#include <libproc.h>
 | 
				
			||||||
#include <mach/mach.h>
 | 
					#include <mach/mach.h>
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,6 @@ package proctl
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"encoding/binary"
 | 
						"encoding/binary"
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
@ -79,16 +78,12 @@ func TestStep(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		_, err := p.Break(helloworldaddr)
 | 
							_, err := p.Break(helloworldaddr)
 | 
				
			||||||
		assertNoError(err, t, "Break()")
 | 
							assertNoError(err, t, "Break()")
 | 
				
			||||||
		fmt.Println("continue")
 | 
					 | 
				
			||||||
		assertNoError(p.Continue(), t, "Continue()")
 | 
							assertNoError(p.Continue(), t, "Continue()")
 | 
				
			||||||
		fmt.Println("fin continue")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		regs := getRegisters(p, t)
 | 
							regs := getRegisters(p, t)
 | 
				
			||||||
		rip := regs.PC()
 | 
							rip := regs.PC()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fmt.Println("begin step")
 | 
					 | 
				
			||||||
		err = p.Step()
 | 
							err = p.Step()
 | 
				
			||||||
		fmt.Println("fin step")
 | 
					 | 
				
			||||||
		assertNoError(err, t, "Step()")
 | 
							assertNoError(err, t, "Step()")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		regs = getRegisters(p, t)
 | 
							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) {
 | 
					func TestBreakPoint(t *testing.T) {
 | 
				
			||||||
	withTestProcess("../_fixtures/testprog", t, func(p *DebuggedProcess) {
 | 
						withTestProcess("../_fixtures/testprog", t, func(p *DebuggedProcess) {
 | 
				
			||||||
		helloworldfunc := p.GoSymTable.LookupFunc("main.helloworld")
 | 
							helloworldfunc := p.GoSymTable.LookupFunc("main.helloworld")
 | 
				
			||||||
@ -141,7 +121,6 @@ func TestBreakPointInSeperateGoRoutine(t *testing.T) {
 | 
				
			|||||||
			t.Fatal("No fn exists")
 | 
								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)
 | 
							_, err := p.Break(fn.Entry)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			t.Fatal(err)
 | 
								t.Fatal(err)
 | 
				
			||||||
@ -240,7 +219,6 @@ func TestNext(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		f, ln := currentLineNumber(p, t)
 | 
							f, ln := currentLineNumber(p, t)
 | 
				
			||||||
		for _, tc := range testcases {
 | 
							for _, tc := range testcases {
 | 
				
			||||||
			fmt.Println("BEGIN-----------------", tc.begin)
 | 
					 | 
				
			||||||
			if ln != tc.begin {
 | 
								if ln != tc.begin {
 | 
				
			||||||
				t.Fatalf("Program not stopped at correct spot expected %d was %s:%d", tc.begin, f, ln)
 | 
									t.Fatalf("Program not stopped at correct spot expected %d was %s:%d", tc.begin, f, ln)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
				
			|||||||
@ -92,6 +92,7 @@ single_step(thread_act_t thread) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO(dp) return kret
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
clear_trap_flag(thread_act_t thread) {
 | 
					clear_trap_flag(thread_act_t thread) {
 | 
				
			||||||
	kern_return_t kret;
 | 
						kern_return_t kret;
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ func (t *ThreadContext) singleStep() error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (t *ThreadContext) cont() error {
 | 
					func (t *ThreadContext) cont() error {
 | 
				
			||||||
	// debug.PrintStack()
 | 
					 | 
				
			||||||
	// TODO(dp) set flag for ptrace stops
 | 
						// TODO(dp) set flag for ptrace stops
 | 
				
			||||||
	if err := PtraceCont(t.Process.Pid, 0); err == nil {
 | 
						if err := PtraceCont(t.Process.Pid, 0); err == nil {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user