提交 2dc1cabf 编写于 作者: K kaddepalli

8196681: Java Access Bridge logging and debug flags dynamically controlled

Reviewed-by: serb, sveerabhadra, zgu
Contributed-by: NAlex Kashchenko <akashche@redhat.com>
上级 f956b07e
......@@ -53,17 +53,17 @@ AccessBridgeATInstance::AccessBridgeATInstance(HWND ourABWindow, HWND winABWindo
* AccessBridgeATInstance descructor
*/
AccessBridgeATInstance::~AccessBridgeATInstance() {
PrintDebugString("\r\nin AccessBridgeATInstance::~AccessBridgeATInstance");
PrintDebugString("[INFO]: in AccessBridgeATInstance::~AccessBridgeATInstance");
// if IPC memory mapped file view is valid, unmap it
if (memoryMappedView != (char *) 0) {
PrintDebugString(" unmapping memoryMappedView; view = %p", memoryMappedView);
PrintDebugString("[INFO]: unmapping memoryMappedView; view = %p", memoryMappedView);
UnmapViewOfFile(memoryMappedView);
memoryMappedView = (char *) 0;
}
// if IPC memory mapped file handle map is open, close it
if (memoryMappedFileMapHandle != (HANDLE) 0) {
PrintDebugString(" closing memoryMappedFileMapHandle; handle = %p", memoryMappedFileMapHandle);
PrintDebugString("[INFO]: closing memoryMappedFileMapHandle; handle = %p", memoryMappedFileMapHandle);
CloseHandle(memoryMappedFileMapHandle);
memoryMappedFileMapHandle = (HANDLE) 0;
}
......@@ -87,7 +87,7 @@ LRESULT
AccessBridgeATInstance::initiateIPC() {
DWORD errorCode;
PrintDebugString("\r\nIn AccessBridgeATInstance::initiateIPC()");
PrintDebugString("[INFO]: In AccessBridgeATInstance::initiateIPC()");
// open Windows-initiated IPC filemap & map it to a ptr
......@@ -95,10 +95,10 @@ AccessBridgeATInstance::initiateIPC() {
FALSE, memoryMappedFileName);
if (memoryMappedFileMapHandle == NULL) {
errorCode = GetLastError();
PrintDebugString(" Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode);
PrintDebugString("[ERROR]: Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode);
return errorCode;
} else {
PrintDebugString(" CreateFileMapping worked - filename: %s", memoryMappedFileName);
PrintDebugString("[INFO]: CreateFileMapping worked - filename: %s", memoryMappedFileName);
}
memoryMappedView = (char *) MapViewOfFile(memoryMappedFileMapHandle,
......@@ -106,20 +106,20 @@ AccessBridgeATInstance::initiateIPC() {
0, 0, 0);
if (memoryMappedView == NULL) {
errorCode = GetLastError();
PrintDebugString(" Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode);
PrintDebugString("[ERROR]: Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode);
return errorCode;
} else {
PrintDebugString(" MapViewOfFile worked - view: %p", memoryMappedView);
PrintDebugString("[INFO]: MapViewOfFile worked - view: %p", memoryMappedView);
}
// look for the JavaDLL's answer to see if it could read the file
if (strcmp(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_QUERY) != 0) {
PrintDebugString(" JavaVM failed to write to memory mapped file %s",
PrintDebugString("[ERROR]: JavaVM failed to write to memory mapped file %s",
memoryMappedFileName);
return -1;
} else {
PrintDebugString(" JavaVM successfully wrote to file!");
PrintDebugString("[INFO]: JavaVM successfully wrote to file!");
}
......@@ -213,8 +213,8 @@ static void do_event(char *buffer, int bufsize,HWND ourAccessBridgeWindow,HWND w
LRESULT
AccessBridgeATInstance::sendJavaEventPackage(char *buffer, int bufsize, long eventID) {
PrintDebugString("AccessBridgeATInstance::sendJavaEventPackage() eventID = %X", eventID);
PrintDebugString("AccessBridgeATInstance::sendJavaEventPackage() (using PostMessage) eventID = %X", eventID);
PrintDebugString("[INFO]: AccessBridgeATInstance::sendJavaEventPackage() eventID = %X", eventID);
PrintDebugString("[INFO]: AccessBridgeATInstance::sendJavaEventPackage() (using PostMessage) eventID = %X", eventID);
if (eventID & javaEventMask) {
do_event(buffer,bufsize,ourAccessBridgeWindow,winAccessBridgeWindow);
......@@ -234,7 +234,7 @@ AccessBridgeATInstance::sendJavaEventPackage(char *buffer, int bufsize, long eve
LRESULT
AccessBridgeATInstance::sendAccessibilityEventPackage(char *buffer, int bufsize, long eventID) {
PrintDebugString("AccessBridgeATInstance::sendAccessibilityEventPackage() eventID = %X", eventID);
PrintDebugString("[INFO]: AccessBridgeATInstance::sendAccessibilityEventPackage() eventID = %X", eventID);
if (eventID & accessibilityEventMask) {
do_event(buffer,bufsize,ourAccessBridgeWindow,winAccessBridgeWindow);
......
......@@ -31,17 +31,76 @@
#include <stdarg.h>
#include <stdio.h>
#include <windows.h>
#include <cstdlib>
#include <cstring>
#ifdef __cplusplus
extern "C" {
#endif
static FILE* logFP = nullptr;
void initializeFileLogger(char * suffix) {
auto var = "JAVA_ACCESSBRIDGE_LOGFILE";
const auto envfilePath = getenv(var);
if (envfilePath != nullptr) {
auto ext = const_cast<char*>(strrchr(envfilePath, '.'));
auto filePath = static_cast<char*>(nullptr);
auto len = strlen(envfilePath);
auto suffixlen = suffix != nullptr ? strlen(suffix) : (decltype(strlen(nullptr)))0;
if (ext == nullptr) {
filePath = new char[len + suffixlen + 5];
memset(filePath, 0, len + suffixlen + 5);
memcpy(filePath, envfilePath, len);
memcpy(filePath + len, suffix, suffixlen);
memcpy(filePath + len + suffixlen, ".log", 4);
} else {
auto extLen = strlen(ext);
filePath = new char[len + suffixlen + 1];
memset(filePath, 0, len + suffixlen + 1);
memcpy(filePath, envfilePath, len - extLen);
memcpy(filePath + len - extLen, suffix, suffixlen);
memcpy(filePath + len + suffixlen - extLen, ext, extLen);
}
logFP = fopen(filePath, "w");
if (logFP == nullptr) {
PrintDebugString("couldnot open file %s", filePath);
}
delete [] filePath;
}
}
void finalizeFileLogger() {
if (logFP) {
fclose(logFP);
logFP = nullptr;
}
}
auto getTimeStamp() -> long long {
LARGE_INTEGER freqLarge;
::QueryPerformanceFrequency(&freqLarge);
long long freq = freqLarge.QuadPart;
LARGE_INTEGER counterLarge;
::QueryPerformanceCounter(&counterLarge);
long long counter = counterLarge.QuadPart;
long long milliDen = 1000;
// prevent possible overflow
long long whole = (counter / freq) * milliDen;
long long part = (counter % freq) * milliDen / freq;
return whole + part;
}
/**
* Send debugging info to the appropriate place
*/
void PrintDebugString(char *msg, ...) {
#ifdef DEBUGGING_ON
char buf[1024];
char buf[1024] = {0};
va_list argprt;
va_start(argprt, msg); // set up argptr
......@@ -54,6 +113,14 @@ extern "C" {
printf("\r\n");
#endif
#endif
if (logFP) {
fprintf(logFP, "[%lldu] ", getTimeStamp());
va_list args;
va_start(args, msg);
vfprintf(logFP, msg, args);
va_end(args);
fprintf(logFP, "\r\n");
}
}
/**
......@@ -61,7 +128,7 @@ extern "C" {
*/
void PrintJavaDebugString2(char *msg, ...) {
#ifdef JAVA_DEBUGGING_ON
char buf[1024];
char buf[1024] = {0};
va_list argprt;
va_start(argprt, msg); // set up argptr
......@@ -74,13 +141,21 @@ extern "C" {
printf("\r\n");
#endif
#endif
if (logFP) {
fprintf(logFP, "[%llu] ", getTimeStamp());
va_list args;
va_start(args, msg);
vfprintf(logFP, msg, args);
va_end(args);
fprintf(logFP, "\r\n");
}
}
/**
* Wide version of the method to send debugging info to the appropriate place
*/
void wPrintDebugString(wchar_t *msg, ...) {
#ifdef DEBUGGING_ON
char buf[1024];
char buf[1024] = {0};
char charmsg[256];
va_list argprt;
......@@ -95,6 +170,14 @@ extern "C" {
printf("\r\n");
#endif
#endif
if (logFP) {
fprintf(logFP, "[%llu] ", getTimeStamp());
va_list args;
va_start(args, msg);
vfwprintf(logFP, msg, args);
va_end(args);
fprintf(logFP, "\r\n");
}
}
/**
......@@ -102,8 +185,8 @@ extern "C" {
*/
void wPrintJavaDebugString(wchar_t *msg, ...) {
#ifdef JAVA_DEBUGGING_ON
char buf[1024];
char charmsg[256];
char buf[1024] = {0};
char charmsg[256] = {0};
va_list argprt;
va_start(argprt, msg); // set up argptr
......@@ -117,6 +200,14 @@ extern "C" {
printf("\r\n");
#endif
#endif
if (logFP) {
fprintf(logFP, "[%llu] ", getTimeStamp());
va_list args;
va_start(args, msg);
vfwprintf(logFP, msg, args);
va_end(args);
fprintf(logFP, "\r\n");
}
}
#ifdef __cplusplus
}
......
......@@ -53,6 +53,8 @@ extern "C" {
void PrintJavaDebugString(char *msg, ...);
void wPrintJavaDebugString(wchar_t *msg, ...);
void wPrintDebugString(wchar_t *msg, ...);
void initializeFileLogger(char * suffix);
void finalizeFileLogger();
#ifdef __cplusplus
}
......
......@@ -170,7 +170,7 @@ AccessBridgeEventHandler::firePropertyChange(long vmID,
if (propertyChangeFP != (AccessBridge_PropertyChangeFP) 0) {
propertyChangeFP(vmID, event, source, property, oldName, newName);
} else {
DEBUG_CODE(AppendToCallInfo(" Error! propertyChangeFP == 0\r\n"));
DEBUG_CODE(AppendToCallInfo("[ERROR]: propertyChangeFP == 0"));
}
}
......@@ -186,9 +186,9 @@ AccessBridgeEventHandler::firePropertyChange(long vmID,
*
*/
#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)
const char fireEventDebugString[] = "\r\nIn AccessBridgeEventHandler::%s(%p, %p); vmID = %X\r\n";
const char fireEventDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s(%p, %p); vmID = %X\r\n";
#else // JOBJECT64 is jlong (64 bit)
const char fireEventDebugString[] = "\r\nIn AccessBridgeEventHandler::%s(%016I64X, %016I64X); vmID = %X\r\n";
const char fireEventDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s(%016I64X, %016I64X); vmID = %X\r\n";
#endif
#define FIRE_EVENT(method, FPprototype, eventFP) \
......@@ -199,18 +199,18 @@ const char fireEventDebugString[] = "\r\nIn AccessBridgeEventHandler::%s(%016I64
if (eventFP != (FPprototype) 0) { \
eventFP(vmID, event, source); \
} else { \
DEBUG_CODE(AppendToCallInfo(" Error! eventFP == 0\r\n")); \
DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0")); \
} \
}
void AccessBridgeEventHandler::fireJavaShutdown(long vmID) {
DEBUG_CODE(char debugBuf[255]);
DEBUG_CODE(sprintf(debugBuf, "\r\nCalling fireJavaShutdown; vmID = %X\r\n", vmID));
DEBUG_CODE(sprintf(debugBuf, "[INFO]: Calling fireJavaShutdown; vmID = %X\r\n", vmID));
DEBUG_CODE(AppendToCallInfo(debugBuf));
if (javaShutdownFP != (AccessBridge_JavaShutdownFP) 0) {
javaShutdownFP(vmID);
} else {
DEBUG_CODE(AppendToCallInfo(" Error! javaShutdownFP == 0\r\n"));
DEBUG_CODE(AppendToCallInfo("[ERROR]: javaShutdownFP == 0"));
}
}
......@@ -241,9 +241,9 @@ FIRE_EVENT(firePopupMenuWillBecomeVisible, AccessBridge_PopupMenuWillBecomeVisib
*
*/
#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)
const char firePropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing a no-param property change (%p, %p):\r\n";
const char firePropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a no-param property change (%p, %p):\r\n";
#else // JOBJECT64 is jlong (64 bit)
const char firePropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing a no-param property change (%016I64X, %016I64X):\r\n";
const char firePropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a no-param property change (%016I64X, %016I64X):\r\n";
#endif
#define FIRE_PROPERTY_CHANGE(method, FPprototype, eventFP) \
......@@ -254,7 +254,7 @@ const char firePropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%
if (eventFP != (FPprototype) 0) { \
eventFP(vmID, event, source); \
} else { \
DEBUG_CODE(AppendToCallInfo(" Error! eventFP == 0\r\n")); \
DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0")); \
} \
}
......@@ -269,9 +269,9 @@ const char firePropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%
*
*/
#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)
const char fireStringPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing a string property change (%p, %p, %ls, %ls):\r\n";
const char fireStringPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a string property change (%p, %p, %ls, %ls):\r\n";
#else // JOBJECT64 is jlong (64 bit)
const char fireStringPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing a string property change (%016I64X, %016I64X, %ls, %ls):\r\n";
const char fireStringPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a string property change (%016I64X, %016I64X, %ls, %ls):\r\n";
#endif
#define FIRE_STRING_PROPERTY_CHANGE(method, FPprototype, eventFP, oldValue, newValue) \
......@@ -283,7 +283,7 @@ const char fireStringPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHand
if (eventFP != (FPprototype) 0) { \
eventFP(vmID, event, source, oldValue, newValue); \
} else { \
DEBUG_CODE(AppendToCallInfo(" Error! eventFP == 0\r\n")); \
DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0\r\n")); \
} \
}
......@@ -298,9 +298,9 @@ const char fireStringPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHand
*
*/
#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)
const char fireIntPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing an int property change (%p, %p, %d, %d):\r\n";
const char fireIntPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an int property change (%p, %p, %d, %d):\r\n";
#else // JOBJECT64 is jlong (64 bit)
const char fireIntPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing an int property change (%016I64X, %016I64X, %d, %d):\r\n";
const char fireIntPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an int property change (%016I64X, %016I64X, %d, %d):\r\n";
#endif
#define FIRE_INT_PROPERTY_CHANGE(method, FPprototype, eventFP) \
......@@ -312,7 +312,7 @@ const char fireIntPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler
if (eventFP != (FPprototype) 0) { \
eventFP(vmID, event, source, oldValue, newValue); \
} else { \
DEBUG_CODE(AppendToCallInfo(" Error! eventFP == 0\r\n")); \
DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0\r\n")); \
} \
}
......@@ -327,9 +327,9 @@ const char fireIntPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler
*
*/
#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)
const char fireACPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing an AC property change (%p, %p, %p, %p):\r\n";
const char fireACPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an AC property change (%p, %p, %p, %p):\r\n";
#else // JOBJECT64 is jlong (64 bit)
const char fireACPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler::%s, Firing an AC property change (%016I64X, %016I64X, %016I64X, %016I64X):\r\n";
const char fireACPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an AC property change (%016I64X, %016I64X, %016I64X, %016I64X):\r\n";
#endif
#define FIRE_AC_PROPERTY_CHANGE(method, FPprototype, eventFP) \
......@@ -341,7 +341,7 @@ const char fireACPropertyChangeDebugString[] = "\r\nIn AccessBridgeEventHandler:
if (eventFP != (FPprototype) 0) { \
eventFP(vmID, event, source, oldValue, newValue); \
} else { \
DEBUG_CODE(AppendToCallInfo(" Error! eventFP == 0\r\n")); \
DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0\r\n")); \
} \
}
......
......@@ -198,8 +198,8 @@ AccessBridgeJavaVMInstance::sendPackage(char *buffer, long bufsize) {
toCopy.cbData = bufsize;
toCopy.lpData = buffer;
PrintDebugString("In AccessBridgeVMInstance::sendPackage");
PrintDebugString(" javaAccessBridgeWindow: %p", javaAccessBridgeWindow);
PrintDebugString("[INFO]: In AccessBridgeVMInstance::sendPackage");
PrintDebugString("[INFO]: javaAccessBridgeWindow: %p", javaAccessBridgeWindow);
/* This was SendMessage. Normally that is a blocking call. However, if
* SendMessage is sent to another process, e.g. another JVM and an incoming
* SendMessage is pending, control will be passed to the DialogProc to handle
......@@ -280,7 +280,7 @@ AccessBridgeJavaVMInstance::sendMemoryPackage(char *buffer, long bufsize) {
char *done = &memoryMappedView[bufsize];
*done = 0;
PrintDebugString(" javaAccessBridgeWindow: %p", javaAccessBridgeWindow);
PrintDebugString("[INFO]: javaAccessBridgeWindow: %p", javaAccessBridgeWindow);
// See the comment above the call to SendMessageTimeout in SendPackage method above.
UINT flags = SMTO_BLOCK | SMTO_NOTIMEOUTIFNOTHUNG;
DWORD_PTR out; // not used
......@@ -309,7 +309,7 @@ AccessBridgeJavaVMInstance::sendMemoryPackage(char *buffer, long bufsize) {
*/
HWND
AccessBridgeJavaVMInstance::findAccessBridgeWindow(long javaVMID) {
PrintDebugString("In findAccessBridgeWindow");
PrintDebugString("[INFO]: In findAccessBridgeWindow");
// no need to recurse really
if (vmID == javaVMID) {
return javaAccessBridgeWindow;
......@@ -338,7 +338,7 @@ AccessBridgeJavaVMInstance::findAccessBridgeWindow(long javaVMID) {
*/
AccessBridgeJavaVMInstance *
AccessBridgeJavaVMInstance::findABJavaVMInstanceFromJavaHWND(HWND window) {
PrintDebugString("In findABJavaInstanceFromJavaHWND");
PrintDebugString("[INFO]: In findABJavaInstanceFromJavaHWND");
// no need to recurse really
if (javaAccessBridgeWindow == window) {
return this;
......
......@@ -88,17 +88,17 @@ AccessBridgeMessageQueue::getEventsWaiting() {
*/
QueueReturns
AccessBridgeMessageQueue::add(AccessBridgeQueueElement *element) {
PrintDebugString(" in AccessBridgeMessageQueue::add()");
PrintDebugString(" queue size = %d", size);
PrintDebugString("[INFO]: in AccessBridgeMessageQueue::add()");
PrintDebugString("[INFO]: queue size = %d", size);
QueueReturns returnVal = cElementPushedOK;
if (queueLocked) {
PrintDebugString(" queue was locked; returning cQueueInUse!");
PrintDebugString("[WARN]: queue was locked; returning cQueueInUse!");
return cQueueInUse;
}
queueLocked = TRUE;
{
PrintDebugString(" adding element to queue!");
PrintDebugString("[INFO]: adding element to queue!");
if (end == (AccessBridgeQueueElement *) 0) {
if (start == (AccessBridgeQueueElement *) 0 && size == 0) {
start = element;
......@@ -118,7 +118,7 @@ AccessBridgeMessageQueue::add(AccessBridgeQueueElement *element) {
}
}
queueLocked = FALSE;
PrintDebugString(" returning from AccessBridgeMessageQueue::add()");
PrintDebugString("[INFO]: returning from AccessBridgeMessageQueue::add()");
return returnVal;
}
......@@ -129,17 +129,17 @@ AccessBridgeMessageQueue::add(AccessBridgeQueueElement *element) {
*/
QueueReturns
AccessBridgeMessageQueue::remove(AccessBridgeQueueElement **element) {
PrintDebugString(" in AccessBridgeMessageQueue::remove()");
PrintDebugString(" queue size = %d", size);
PrintDebugString("[INFO]: in AccessBridgeMessageQueue::remove()");
PrintDebugString("[INFO]: queue size = %d", size);
QueueReturns returnVal = cMoreMessages;
if (queueLocked) {
PrintDebugString(" queue was locked; returning cQueueInUse!");
PrintDebugString("[WARN]: queue was locked; returning cQueueInUse!");
return cQueueInUse;
}
queueLocked = TRUE;
{
PrintDebugString(" removing element from queue!");
PrintDebugString("[INFO]: removing element from queue!");
if (size > 0) {
if (start != (AccessBridgeQueueElement *) 0) {
*element = start;
......@@ -161,7 +161,7 @@ AccessBridgeMessageQueue::remove(AccessBridgeQueueElement **element) {
}
}
queueLocked = FALSE;
PrintDebugString(" returning from AccessBridgeMessageQueue::remove()");
PrintDebugString("[INFO]: returning from AccessBridgeMessageQueue::remove()");
return returnVal;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册