-kdp_remove_all_breakpoints()
-{
- int i;
- boolean_t breakpoint_found = FALSE;
-
- if (breakpoints_initialized)
- {
- for(i=0;i < MAX_BREAKPOINTS; i++)
- {
- if (breakpoint_list[i].address)
- {
- kdp_vm_write((caddr_t)&(breakpoint_list[i].old_instruction), (caddr_t)breakpoint_list[i].address, sizeof(int));
- breakpoint_found = TRUE;
- breakpoint_list[i].address = 0;
- }
- }
- if (breakpoint_found)
- printf("kdp_remove_all_breakpoints: found extant breakpoints, removing them.\n");
- }
- return breakpoint_found;
-}
-
-
-#define MAX_FRAMES 1000
-
-static int pid_from_task(task_t task)
-{
- int pid = -1;
-
- if (task->bsd_info)
- pid = proc_pid(task->bsd_info);
-
- return pid;
-}
-
-int
-kdp_stackshot(int pid, uint32_t tracebuf, uint32_t tracebuf_size, unsigned trace_options, uint32_t *pbytesTraced)
-{
- uint32_t tracepos = (uint32_t) tracebuf;
- uint32_t tracebound = tracepos + tracebuf_size;
- uint32_t tracebytes = 0;
- int error = 0;
-
- processor_set_t pset = &default_pset;
- task_t task = TASK_NULL;
- thread_t thread = THREAD_NULL;
- int nframes = trace_options;
- thread_snapshot_t tsnap = NULL;
- unsigned framesize = 2 * sizeof(vm_offset_t);
-
- if ((nframes <= 0) || nframes > MAX_FRAMES)
- nframes = MAX_FRAMES;
-
- queue_iterate(&pset->tasks, task, task_t, pset_tasks) {
- /* Trace everything, unless a process was specified */
- if ((pid == -1) || (pid == pid_from_task(task)))
- queue_iterate(&task->threads, thread, thread_t, task_threads){
- if ((tracepos + 4 * sizeof(struct thread_snapshot)) > tracebound) {
- error = -1;
- goto error_exit;
- }
-/* Populate the thread snapshot header */
- tsnap = (thread_snapshot_t) tracepos;
- tsnap->thread_id = thread;
- tsnap->state = thread->state;
- tsnap->wait_queue = thread->wait_queue;
- tsnap->wait_event = thread->wait_event;
- tsnap->kernel_stack = thread->kernel_stack;
- tsnap->reserved_stack = thread->reserved_stack;
- tsnap->continuation = thread->continuation;
-/* Add the BSD process identifiers */
- if ((tsnap->pid = pid_from_task(task)) != -1)
- proc_name(tsnap->pid, tsnap->p_comm, MAXCOMLEN + 1);
- else
- tsnap->p_comm[0] = '\0';
-
- tsnap->snapshot_magic = 0xfeedface;
- tracepos += sizeof(struct thread_snapshot);
-
-/* Call through to the machine specific trace routines
- * Frames are added past the snapshot header.
- */
- if (tsnap->kernel_stack != 0)
- tracebytes = machine_trace_thread(thread, tracepos, tracebound, nframes, FALSE);
- tsnap->nkern_frames = tracebytes/(2 * sizeof(vm_offset_t));
- tracepos += tracebytes;
- tracebytes = 0;
- tsnap->user64_p = 0;
-/* Trace user stack, if any */
- if (thread->task->map != kernel_map) {
-/* 64-bit task? */
- if (task_has_64BitAddr(thread->task)) {
- tracebytes = machine_trace_thread64(thread, tracepos, tracebound, nframes, TRUE);
- tsnap->user64_p = 1;
- framesize = 2 * sizeof(addr64_t);
- }
- else {
- tracebytes = machine_trace_thread(thread, tracepos, tracebound, nframes, TRUE);
- framesize = 2 * sizeof(vm_offset_t);
- }
- }
- tsnap->nuser_frames = tracebytes/framesize;
- tracepos += tracebytes;
- tracebytes = 0;
+kdp_breakpoint64_remove(
+ kdp_pkt_t *pkt,
+ int *len,
+ unsigned short *reply_port
+ )
+{
+ kdp_breakpoint64_req_t *rq = &pkt->breakpoint64_req;
+ kdp_breakpoint64_reply_t *rp = &pkt->breakpoint64_reply;
+ size_t plen = *len;
+ kdp_error_t kerr;
+
+ if (plen < sizeof(*rq)) {
+ return FALSE;
+ }
+
+ dprintf(("kdp_breakpoint64_remove %llx\n", rq->address));
+
+ kerr = kdp_remove_breakpoint_internal((mach_vm_address_t)rq->address);
+
+ rp->error = kerr;
+
+ rp->hdr.is_reply = 1;
+ rp->hdr.len = sizeof(*rp);
+ *reply_port = kdp.reply_port;
+ *len = rp->hdr.len;
+
+ return TRUE;
+}
+
+
+kdp_error_t
+kdp_set_breakpoint_internal(
+ mach_vm_address_t address
+ )
+{
+ uint8_t breakinstr[MAX_BREAKINSN_BYTES], oldinstr[MAX_BREAKINSN_BYTES];
+ uint32_t breakinstrsize = sizeof(breakinstr);
+ mach_vm_size_t cnt;
+ int i;
+
+ kdp_machine_get_breakinsn(breakinstr, &breakinstrsize);
+
+ if (breakpoints_initialized == 0) {
+ for (i = 0; (i < MAX_BREAKPOINTS); breakpoint_list[i].address = 0, i++) {
+ ;
+ }
+ breakpoints_initialized++;
+ }
+
+ cnt = kdp_machine_vm_read(address, (caddr_t)&oldinstr, (mach_vm_size_t)breakinstrsize);
+
+ if (0 == memcmp(oldinstr, breakinstr, breakinstrsize)) {
+ printf("A trap was already set at that address, not setting new breakpoint\n");
+
+ return KDPERR_BREAKPOINT_ALREADY_SET;
+ }
+
+ for (i = 0; (i < MAX_BREAKPOINTS) && (breakpoint_list[i].address != 0); i++) {
+ ;
+ }
+
+ if (i == MAX_BREAKPOINTS) {
+ return KDPERR_MAX_BREAKPOINTS;
+ }
+
+ breakpoint_list[i].address = address;
+ memcpy(breakpoint_list[i].oldbytes, oldinstr, breakinstrsize);
+ breakpoint_list[i].bytesused = breakinstrsize;
+
+ cnt = kdp_machine_vm_write((caddr_t)&breakinstr, address, breakinstrsize);
+
+ return KDPERR_NO_ERROR;
+}
+
+kdp_error_t
+kdp_remove_breakpoint_internal(
+ mach_vm_address_t address
+ )
+{
+ mach_vm_size_t cnt;
+ int i;
+
+ for (i = 0; (i < MAX_BREAKPOINTS) && (breakpoint_list[i].address != address); i++) {
+ ;
+ }
+
+ if (i == MAX_BREAKPOINTS) {
+ return KDPERR_BREAKPOINT_NOT_FOUND;
+ }
+
+ breakpoint_list[i].address = 0;
+ cnt = kdp_machine_vm_write((caddr_t)&breakpoint_list[i].oldbytes, address, breakpoint_list[i].bytesused);
+
+ return KDPERR_NO_ERROR;
+}
+
+boolean_t
+kdp_remove_all_breakpoints(void)
+{
+ int i;
+ boolean_t breakpoint_found = FALSE;
+
+ if (breakpoints_initialized) {
+ for (i = 0; i < MAX_BREAKPOINTS; i++) {
+ if (breakpoint_list[i].address) {
+ kdp_machine_vm_write((caddr_t)&(breakpoint_list[i].oldbytes), (mach_vm_address_t)breakpoint_list[i].address, (mach_vm_size_t)breakpoint_list[i].bytesused);
+ breakpoint_found = TRUE;
+ breakpoint_list[i].address = 0;