< prev index next >

src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m

Print this page




 376   alignedLength = round_page(numBytes);
 377   pageCount = alignedLength/vm_page_size;
 378 
 379   // Allocate storage for pages and flags.
 380   pages = malloc(pageCount * sizeof(vm_offset_t));
 381   if (pages == NULL) {
 382     (*env)->DeleteLocalRef(env, array);
 383     return NULL;
 384   }
 385   mapped = calloc(pageCount, sizeof(int));
 386   if (mapped == NULL) {
 387     (*env)->DeleteLocalRef(env, array);
 388     free(pages);
 389     return NULL;
 390   }
 391 
 392   task_t gTask = getTask(env, this_obj);
 393   // Try to read each of the pages.
 394   for (i = 0; i < pageCount; i++) {
 395     result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size,
 396                      &pages[i], &byteCount);
 397     mapped[i] = (result == KERN_SUCCESS);
 398     // assume all failures are unmapped pages
 399   }
 400 
 401   print_debug("%ld pages\n", pageCount);
 402 
 403   remaining = numBytes;
 404 
 405   for (i = 0; i < pageCount; i++) {
 406     unsigned long len = vm_page_size;
 407     unsigned long start = 0;
 408 
 409     if (i == 0) {
 410       start = addr - alignedAddress;
 411       len = vm_page_size - start;
 412     }
 413 
 414     if (i == (pageCount - 1)) {
 415       len = remaining;
 416     }


 682 
 683 /*
 684  * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
 685  * Method:    translateTID0
 686  * Signature: (I)I
 687  */
 688 JNIEXPORT jint JNICALL
 689 Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(
 690   JNIEnv *env, jobject this_obj, jint tid)
 691 {
 692   print_debug("translateTID0 called on tid = 0x%x\n", (int)tid);
 693 
 694   kern_return_t result;
 695   thread_t foreign_tid, usable_tid;
 696   mach_msg_type_name_t type;
 697 
 698   foreign_tid = tid;
 699 
 700   task_t gTask = getTask(env, this_obj);
 701   result = mach_port_extract_right(gTask, foreign_tid,
 702                                    MACH_MSG_TYPE_COPY_SEND,
 703                                    &usable_tid, &type);
 704   if (result != KERN_SUCCESS)
 705     return -1;
 706 
 707   print_debug("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
 708 
 709   return (jint) usable_tid;
 710 }
 711 
 712 // attach to a process/thread specified by "pid"
 713 static bool ptrace_attach(pid_t pid) {
 714   errno = 0;
 715   ptrace(PT_ATTACHEXC, pid, 0, 0);
 716 
 717   if (errno != 0) {
 718     print_error("ptrace_attach: ptrace(PT_ATTACHEXC,...) failed: %s", strerror(errno));
 719     return false;
 720   }
 721   return true;
 722 }
 723 




 376   alignedLength = round_page(numBytes);
 377   pageCount = alignedLength/vm_page_size;
 378 
 379   // Allocate storage for pages and flags.
 380   pages = malloc(pageCount * sizeof(vm_offset_t));
 381   if (pages == NULL) {
 382     (*env)->DeleteLocalRef(env, array);
 383     return NULL;
 384   }
 385   mapped = calloc(pageCount, sizeof(int));
 386   if (mapped == NULL) {
 387     (*env)->DeleteLocalRef(env, array);
 388     free(pages);
 389     return NULL;
 390   }
 391 
 392   task_t gTask = getTask(env, this_obj);
 393   // Try to read each of the pages.
 394   for (i = 0; i < pageCount; i++) {
 395     result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size,
 396                      &pages[i], &byteCount);
 397     mapped[i] = (result == KERN_SUCCESS);
 398     // assume all failures are unmapped pages
 399   }
 400 
 401   print_debug("%ld pages\n", pageCount);
 402 
 403   remaining = numBytes;
 404 
 405   for (i = 0; i < pageCount; i++) {
 406     unsigned long len = vm_page_size;
 407     unsigned long start = 0;
 408 
 409     if (i == 0) {
 410       start = addr - alignedAddress;
 411       len = vm_page_size - start;
 412     }
 413 
 414     if (i == (pageCount - 1)) {
 415       len = remaining;
 416     }


 682 
 683 /*
 684  * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
 685  * Method:    translateTID0
 686  * Signature: (I)I
 687  */
 688 JNIEXPORT jint JNICALL
 689 Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(
 690   JNIEnv *env, jobject this_obj, jint tid)
 691 {
 692   print_debug("translateTID0 called on tid = 0x%x\n", (int)tid);
 693 
 694   kern_return_t result;
 695   thread_t foreign_tid, usable_tid;
 696   mach_msg_type_name_t type;
 697 
 698   foreign_tid = tid;
 699 
 700   task_t gTask = getTask(env, this_obj);
 701   result = mach_port_extract_right(gTask, foreign_tid,
 702                                    MACH_MSG_TYPE_COPY_SEND,
 703                                    &usable_tid, &type);
 704   if (result != KERN_SUCCESS)
 705     return -1;
 706 
 707   print_debug("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
 708 
 709   return (jint) usable_tid;
 710 }
 711 
 712 // attach to a process/thread specified by "pid"
 713 static bool ptrace_attach(pid_t pid) {
 714   errno = 0;
 715   ptrace(PT_ATTACHEXC, pid, 0, 0);
 716 
 717   if (errno != 0) {
 718     print_error("ptrace_attach: ptrace(PT_ATTACHEXC,...) failed: %s", strerror(errno));
 719     return false;
 720   }
 721   return true;
 722 }
 723 


< prev index next >