src/os/windows/vm/os_windows.cpp

Print this page




1403 
1404 static int _locate_module_by_addr(int pid, char * mod_fname, address base_addr,
1405                                   unsigned size, void * param) {
1406    struct _modinfo *pmod = (struct _modinfo *)param;
1407    if (!pmod) return -1;
1408 
1409    if (base_addr     <= pmod->addr &&
1410        base_addr+size > pmod->addr) {
1411      // if a buffer is provided, copy path name to the buffer
1412      if (pmod->full_path) {
1413        jio_snprintf(pmod->full_path, pmod->buflen, "%s", mod_fname);
1414      }
1415      pmod->base_addr = base_addr;
1416      return 1;
1417    }
1418    return 0;
1419 }
1420 
1421 bool os::dll_address_to_library_name(address addr, char* buf,
1422                                      int buflen, int* offset) {



1423 // NOTE: the reason we don't use SymGetModuleInfo() is it doesn't always
1424 //       return the full path to the DLL file, sometimes it returns path
1425 //       to the corresponding PDB file (debug info); sometimes it only
1426 //       returns partial path, which makes life painful.
1427 
1428    struct _modinfo mi;
1429    mi.addr      = addr;
1430    mi.full_path = buf;
1431    mi.buflen    = buflen;
1432    int pid = os::current_process_id();
1433    if (enumerate_modules(pid, _locate_module_by_addr, (void *)&mi)) {
1434       // buf already contains path name
1435       if (offset) *offset = addr - mi.base_addr;
1436       return true;
1437    } else {
1438       if (buf) buf[0] = '\0';
1439       if (offset) *offset = -1;
1440       return false;
1441    }
1442 }
1443 
1444 bool os::dll_address_to_function_name(address addr, char *buf,
1445                                       int buflen, int *offset) {



1446   if (Decoder::decode(addr, buf, buflen, offset)) {
1447     return true;
1448   }
1449   if (offset != NULL)  *offset  = -1;
1450   if (buf != NULL) buf[0] = '\0';
1451   return false;
1452 }
1453 
1454 // save the start and end address of jvm.dll into param[0] and param[1]
1455 static int _locate_jvm_dll(int pid, char* mod_fname, address base_addr,
1456                     unsigned size, void * param) {
1457    if (!param) return -1;
1458 
1459    if (base_addr     <= (address)_locate_jvm_dll &&
1460        base_addr+size > (address)_locate_jvm_dll) {
1461          ((address*)param)[0] = base_addr;
1462          ((address*)param)[1] = base_addr + size;
1463          return 1;
1464    }
1465    return 0;
1466 }
1467 
1468 address vm_lib_location[2];    // start and end address of jvm.dll
1469 
1470 // check if addr is inside jvm.dll




1403 
1404 static int _locate_module_by_addr(int pid, char * mod_fname, address base_addr,
1405                                   unsigned size, void * param) {
1406    struct _modinfo *pmod = (struct _modinfo *)param;
1407    if (!pmod) return -1;
1408 
1409    if (base_addr     <= pmod->addr &&
1410        base_addr+size > pmod->addr) {
1411      // if a buffer is provided, copy path name to the buffer
1412      if (pmod->full_path) {
1413        jio_snprintf(pmod->full_path, pmod->buflen, "%s", mod_fname);
1414      }
1415      pmod->base_addr = base_addr;
1416      return 1;
1417    }
1418    return 0;
1419 }
1420 
1421 bool os::dll_address_to_library_name(address addr, char* buf,
1422                                      int buflen, int* offset) {
1423   // buf is not optional, but offset is optional
1424   assert(buf != NULL, "sanity check");
1425 
1426 // NOTE: the reason we don't use SymGetModuleInfo() is it doesn't always
1427 //       return the full path to the DLL file, sometimes it returns path
1428 //       to the corresponding PDB file (debug info); sometimes it only
1429 //       returns partial path, which makes life painful.
1430 
1431    struct _modinfo mi;
1432    mi.addr      = addr;
1433    mi.full_path = buf;
1434    mi.buflen    = buflen;
1435    int pid = os::current_process_id();
1436    if (enumerate_modules(pid, _locate_module_by_addr, (void *)&mi)) {
1437       // buf already contains path name
1438       if (offset) *offset = addr - mi.base_addr;
1439       return true;
1440    } else {
1441       buf[0] = '\0';
1442       if (offset) *offset = -1;
1443       return false;
1444    }
1445 }
1446 
1447 bool os::dll_address_to_function_name(address addr, char *buf,
1448                                       int buflen, int *offset) {
1449   // buf is not optional, but offset is optional
1450   assert(buf != NULL, "sanity check");
1451 
1452   if (Decoder::decode(addr, buf, buflen, offset)) {
1453     return true;
1454   }
1455   if (offset != NULL)  *offset  = -1;
1456   buf[0] = '\0';
1457   return false;
1458 }
1459 
1460 // save the start and end address of jvm.dll into param[0] and param[1]
1461 static int _locate_jvm_dll(int pid, char* mod_fname, address base_addr,
1462                     unsigned size, void * param) {
1463    if (!param) return -1;
1464 
1465    if (base_addr     <= (address)_locate_jvm_dll &&
1466        base_addr+size > (address)_locate_jvm_dll) {
1467          ((address*)param)[0] = base_addr;
1468          ((address*)param)[1] = base_addr + size;
1469          return 1;
1470    }
1471    return 0;
1472 }
1473 
1474 address vm_lib_location[2];    // start and end address of jvm.dll
1475 
1476 // check if addr is inside jvm.dll