You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by od...@apache.org on 2009/07/16 17:57:41 UTC
svn commit: r794726 [6/15] - in
/harmony/enhanced/jdktools/branches/java6/modules/jpda: ./
src/main/native/include/ src/main/native/jdwp/common/agent/commands/
src/main/native/jdwp/common/agent/core/
src/main/native/jdwp/common/generic/ src/main/native...
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/Agent.cpp Thu Jul 16 15:57:37 2009
@@ -15,25 +15,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifndef USING_VMI
+#define USING_VMI
+#endif
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.25 $
- */
-// Agent.cpp
-
-#include <string.h>
-#include <cstdlib>
-#include <cstdio>
-
-#include "jvmti.h"
+#include "AgentBase.h"
#include "AgentEnv.h"
-#include "AgentBase.h"
#include "MemoryManager.h"
#include "AgentException.h"
#include "LogManager.h"
#include "Log.h"
+#include "jvmti.h"
+
+#include "jdwpcfg.h"
#include "ClassManager.h"
#include "ObjectManager.h"
@@ -44,10 +39,17 @@
#include "PacketDispatcher.h"
#include "EventDispatcher.h"
#include "AgentManager.h"
+#include "ExceptionManager.h"
+
+#include <stdlib.h>
+#include <string.h>
using namespace jdwp;
AgentEnv *AgentBase::m_agentEnv = 0;
+char* AgentBase::m_defaultStratum = 0;
+bool isLoaded = false;
+bool disableOnUnload = false;
static const char* const AGENT_OPTIONS_ENVNAME = "JDWP_AGENT_OPTIONS";
static const char* const AGENT_OPTIONS_PROPERTY = "jdwp.agent.options";
@@ -64,31 +66,35 @@
// static internal functions
//-----------------------------------------------------------------------------
+static void ShowJDWPVersion() {
+ const char *buildLevel = BUILD_LEVEL;
+ const char *versionString = "JDWP version:";
+
+ PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+ hytty_printf(privatePortLibrary, "%s %s\n\n", versionString, buildLevel);
+}
+
static void Usage()
{
- std::fprintf(stdout,
- "\nUsage: java -agentlib:agent=[help] |"
+ const char* usage =
+ "\nUsage: java -agentlib:agent=[help] | [version] |"
"\n\t[suspend=y|n][,transport=name][,address=addr]"
"\n\t[,server=y|n][,timeout=n]"
-#ifndef NDEBUG
"\n\t[,trace=none|all|log_kinds][,src=all|sources][,log=filepath]\n"
-#endif//NDEBUG
"\nWhere:"
"\n\thelp\t\tOutput this message"
+ "\n\tversion\t\tDisplay the JDWP build version"
"\n\tsuspend=y|n\tSuspend on start (default: y)"
"\n\ttransport=name\tName of transport to use for connection"
"\n\taddress=addr\tTransport address for connection"
"\n\tserver=y|n\tListen for or attach to debugger (default: n)"
"\n\ttimeout=n\tTime in ms to wait for connection (0-forever)"
-#ifndef NDEBUG
"\n\ttrace=log_kinds\tApplies filtering to log message kind (default: none)"
"\n\tsrc=sources\tApplies filtering to __FILE__ (default: all)"
"\n\tlog=filepath\tRedirect output into filepath\n"
-#endif//NDEBUG
"\nExample:"
"\n\tjava -agentlib:agent=transport=dt_socket,"
"address=localhost:7777,server=y\n"
-#ifndef NDEBUG
"\nExamples of tracing parameters:\n"
"\ttrace=all,log=jdwp.log\n"
"\t - traces all kinds of messages\n"
@@ -110,8 +116,10 @@
"\tLOG - debug messages\n"
"\tINFO - information and warning messages\n"
"\tERROR - error messages\n\n"
-#endif//NDEBUG
- );
+ ;
+
+ PORT_ACCESS_FROM_JAVAVM(AgentBase::GetJavaVM());
+ hytty_printf(privatePortLibrary, "%s", usage);
}
//-----------------------------------------------------------------------------
@@ -121,45 +129,50 @@
static void JNICALL
VMInit(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread)
{
- try {
- JDWP_TRACE_ENTRY("VMInit(" << jvmti << ',' << jni << ',' << thread << ')');
- jint ver = jni->GetVersion();
- JDWP_LOG("JNI version: 0x" << hex << ver);
-
- // initialize agent
- AgentBase::GetAgentManager().Init(jvmti, jni);
-
- // if options onthrow or onuncaught are set, defer starting agent and enable notification of EXCEPTION event
- if (AgentBase::GetOptionParser().GetOnthrow() || AgentBase::GetOptionParser().GetOnuncaught()) {
- AgentBase::GetAgentManager().EnableInitialExceptionCatch(jvmti, jni);
- } else {
- AgentBase::GetAgentManager().Start(jvmti, jni);
- RequestManager::HandleVMInit(jvmti, jni, thread);
- }
- } catch (TransportException& e) {
- JDWP_DIE("JDWP transport error in VM_INIT: " << e.TransportErrorMessage() << " [" << e.ErrCode() << "]");
- } catch (AgentException& e) {
- JDWP_DIE("JDWP error in VM_INIT: " << e.what() << " [" << e.ErrCode() << "]");
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "VMInit(%p,%p,%p)", jvmti, jni, thread));
+ jint ver = jni->GetVersion();
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "JNI version: 0x%x", ver));
+
+ // initialize agent
+ int ret = AgentBase::GetAgentManager().Init(jvmti, jni);
+ if (ret != JDWP_ERROR_NONE) {
+ goto handleException;
+ }
+
+ // if options onthrow or onuncaught are set, defer starting agent and enable notification of EXCEPTION event
+ if (AgentBase::GetOptionParser().GetOnthrow() || AgentBase::GetOptionParser().GetOnuncaught()) {
+ ret = AgentBase::GetAgentManager().EnableInitialExceptionCatch(jvmti, jni);
+ if (ret != JDWP_ERROR_NONE) {
+ goto handleException;
+ }
+ } else {
+ ret = AgentBase::GetAgentManager().Start(jvmti, jni);
+ if (ret != JDWP_ERROR_NONE) {
+ goto handleException;
+ }
+ RequestManager::HandleVMInit(jvmti, jni, thread);
}
+ return;
+
+handleException:
+ AgentException aex = AgentBase::GetExceptionManager().GetLastException();
+ JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "JDWP error in VM_INIT: %s", aex.GetExceptionMessage(jni)));
+ ::exit(1);
}
static void JNICALL
VMDeath(jvmtiEnv *jvmti, JNIEnv *jni)
{
- try {
- if (AgentBase::GetAgentManager().IsStarted()) {
- // don't print entry trace message after cleaning agent
- JDWP_TRACE_ENTRY("VMDeath(" << jvmti << ',' << jni << ')');
-
- RequestManager::HandleVMDeath(jvmti, jni);
- AgentBase::SetIsDead(true);
-
- AgentBase::GetAgentManager().Stop(jni);
- }
- AgentBase::GetAgentManager().Clean(jni);
- } catch (AgentException& e) {
- JDWP_INFO("JDWP error in VM_DEATH: " << e.what() << " [" << e.ErrCode() << "]");
+ if (AgentBase::GetAgentManager().IsStarted()) {
+ // don't print entry trace message after cleaning agent
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "VMDeath(%p, %p)", jvmti, jni));
+
+ RequestManager::HandleVMDeath(jvmti, jni);
+ AgentBase::SetIsDead(true);
+
+ AgentBase::GetAgentManager().Stop(jni);
}
+ AgentBase::GetAgentManager().Clean(jni);
}
//-----------------------------------------------------------------------------
@@ -169,6 +182,14 @@
JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
{
+ if (isLoaded) {
+ // We are already loaded - exit with an error message
+ PORT_ACCESS_FROM_JAVAVM(vm);
+ hyfile_printf(privatePortLibrary, HYPORT_TTY_ERR, "Error: JDWP agent already loaded - please check java command line options\n");
+ disableOnUnload = true; // If we're already loaded, dont call unload as it may cause a crash
+ return JNI_ERR;
+ }
+ isLoaded = true;
// static STDMemoryManager mm;
static VMMemoryManager mm;
@@ -183,163 +204,162 @@
env.extensionEventClassUnload = 0;
env.isDead = false;
AgentBase::SetAgentEnv(&env);
+ AgentBase::SetDefaultStratum(NULL);
jvmtiEnv *jvmti = 0;
jvmtiError err;
- JDWP_TRACE_ENTRY("Agent_OnLoad(" << vm << "," << (void*)options << "," << reserved << ")");
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Agent_OnLoad(%p,%p,%p)", vm, (void*)options, reserved));
// get JVMTI environment
{
jint ret =
(vm)->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_0);
if (ret != JNI_OK || jvmti == 0) {
- JDWP_INFO("Unable to get JMVTI environment, return code = " << ret);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to get JMVTI environment, return code = %d", ret));
return JNI_ERR;
}
env.jvmti = jvmti;
jint version;
- JVMTI_TRACE(err, jvmti->GetVersionNumber(&version));
- JDWP_LOG("JVMTI version: 0x" << hex << version);
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->GetVersionNumber(&version));
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "JVMTI version: 0x%x", version));
}
+ // inital ExceptionManager before first try block
+ env.exceptionManager = new ExceptionManager();
+ env.exceptionManager->Init(AgentBase::GetJniEnv());
+
// parse agent options
- try {
- env.optionParser = new OptionParser();
+ env.optionParser = new OptionParser();
- // add options from environment variable and/or system property
- {
- char* envOptions = getenv(AGENT_OPTIONS_ENVNAME);
- char* propOptions = 0;
- jvmtiError err;
+ // add options from environment variable and/or system property
+ {
+ char* envOptions = getenv(AGENT_OPTIONS_ENVNAME);
+ char* propOptions = 0;
+ jvmtiError err;
- JVMTI_TRACE(err,
- jvmti->GetSystemProperty(AGENT_OPTIONS_PROPERTY, &propOptions));
- if (err != JVMTI_ERROR_NONE) {
- JDWP_LOG("No system property: "
- << AGENT_OPTIONS_PROPERTY << ", err=" << err);
- propOptions = 0;
- }
- JvmtiAutoFree af(propOptions);
+ JVMTI_TRACE(LOG_DEBUG, err,
+ jvmti->GetSystemProperty(AGENT_OPTIONS_PROPERTY, &propOptions));
+ if (err != JVMTI_ERROR_NONE) {
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "No system property: %s, err=%d", AGENT_OPTIONS_PROPERTY, err));
+ propOptions = 0;
+ }
+ JvmtiAutoFree af(propOptions);
- if (envOptions != 0 || propOptions != 0) {
- JDWP_INFO("Add options from: "
- << endl << "\tcommand line: " << JDWP_CHECK_NULL(options)
- << endl << "\tenvironment " << AGENT_OPTIONS_ENVNAME
- << ": " << JDWP_CHECK_NULL(envOptions)
- << endl << "\tproperty " << AGENT_OPTIONS_PROPERTY
- << ": " << JDWP_CHECK_NULL(propOptions)
- );
-
- size_t fullLength = ((options == 0) ? 0 : strlen(options) + 1)
- + ((propOptions == 0) ? 0 : strlen(propOptions) + 1)
- + ((envOptions == 0) ? 0 : strlen(envOptions) + 1);
- char* fullOptions = static_cast<char*>
- (AgentBase::GetMemoryManager().Allocate(fullLength JDWP_FILE_LINE));
- fullOptions[0] = '\0';
- if (options != 0) {
- strcat(fullOptions, options);
- }
- if (envOptions != 0) {
- if (fullOptions[0] != '\0') {
- strcat(fullOptions, ",");
- }
- strcat(fullOptions, envOptions);
+ if (envOptions != 0 || propOptions != 0) {
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Add options from: \n\tcommand line: %s\n\tenvironment %s: %s\n\tproperty %s: %s",
+ JDWP_CHECK_NULL(options), AGENT_OPTIONS_ENVNAME, JDWP_CHECK_NULL(envOptions), AGENT_OPTIONS_PROPERTY, JDWP_CHECK_NULL(propOptions)));
+
+ size_t fullLength = ((options == 0) ? 0 : strlen(options) + 1)
+ + ((propOptions == 0) ? 0 : strlen(propOptions) + 1)
+ + ((envOptions == 0) ? 0 : strlen(envOptions) + 1);
+ char* fullOptions = static_cast<char*>
+ (AgentBase::GetMemoryManager().Allocate(fullLength JDWP_FILE_LINE));
+ fullOptions[0] = '\0';
+ if (options != 0) {
+ strcat(fullOptions, options);
+ }
+ if (envOptions != 0) {
+ if (fullOptions[0] != '\0') {
+ strcat(fullOptions, ",");
}
- if (propOptions != 0) {
- if (fullOptions[0] != '\0') {
- strcat(fullOptions, ",");
- }
- strcat(fullOptions, propOptions);
+ strcat(fullOptions, envOptions);
+ }
+ if (propOptions != 0) {
+ if (fullOptions[0] != '\0') {
+ strcat(fullOptions, ",");
}
- options = fullOptions;
- JDWP_INFO("Full options: " << JDWP_CHECK_NULL(options));
+ strcat(fullOptions, propOptions);
}
-
- AgentBase::GetOptionParser().Parse(options);
+ options = fullOptions;
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Full options: %s", JDWP_CHECK_NULL(options)));
}
- // initialize LogManager module first
- AgentBase::GetLogManager().Init(
- AgentBase::GetOptionParser().GetLog(),
- AgentBase::GetOptionParser().GetTraceKindFilter(),
- AgentBase::GetOptionParser().GetTraceSrcFilter()
- );
-
- #ifndef NDEBUG
- if (JDWP_TRACE_ENABLED(LOG_KIND_LOG)) {
- int optCount = AgentBase::GetOptionParser().GetOptionCount();
- JDWP_LOG("parsed " << optCount << " options:");
- for (int k = 0; k < optCount; k++) {
- const char *name, *value;
- AgentBase::GetOptionParser().GetOptionByIndex(k, name, value);
- JDWP_LOG("[" << k << "]: " << JDWP_CHECK_NULL(name) << " = "
- << JDWP_CHECK_NULL(value));
- }
- }
- #endif // NDEBUG
-
- // exit if help option specified
- if (AgentBase::GetOptionParser().GetHelp()) {
- Usage();
- JDWP_LOG("exit" << endl);
+ if (AgentBase::GetOptionParser().Parse(options) != JDWP_ERROR_NONE) {
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "JDWP error: Bad agent options: %s", options));
delete env.optionParser;
- std::exit(0);
- }
-
- // check for required options
- if (AgentBase::GetOptionParser().GetTransport() == 0) {
- JDWP_INFO("JDWP error: No agent option specified: " << "transport");
- return JNI_ERR;
- }
- if (!AgentBase::GetOptionParser().GetServer()
- && AgentBase::GetOptionParser().GetAddress() == 0) {
- JDWP_INFO("JDWP error: No agent option specified: " << "address");
return JNI_ERR;
}
+ }
+
+ // initialize LogManager module first
+ AgentBase::GetLogManager().Init(
+ AgentBase::GetOptionParser().GetLog(),
+ AgentBase::GetOptionParser().GetTraceKindFilter(),
+ AgentBase::GetOptionParser().GetTraceSrcFilter()
+ );
+
+ #ifndef NDEBUG
+ if (JDWP_TRACE_ENABLED(LOG_KIND_LOG)) {
+ int optCount = AgentBase::GetOptionParser().GetOptionCount();
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "parsed %d options:", optCount));
+ for (int k = 0; k < optCount; k++) {
+ const char *name, *value;
+ AgentBase::GetOptionParser().GetOptionByIndex(k, name, value);
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "[%d]: %s=%s", k, JDWP_CHECK_NULL(name), JDWP_CHECK_NULL(value)));
+ }
+ }
+ #endif // NDEBUG
+
+ // exit if help option specified
+ if (AgentBase::GetOptionParser().GetHelp()) {
+ Usage();
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "exit"));
+ delete env.optionParser;
+ exit(0);
+ }
- // create all other modules
- env.classManager = new ClassManager();
- env.objectManager = new ObjectManager();
- env.threadManager = new ThreadManager();
- env.requestManager = new RequestManager();
- env.transportManager = new TransportManager();
- env.packetDispatcher = new PacketDispatcher();
- env.eventDispatcher = new EventDispatcher();
- env.agentManager = new AgentManager();
- } catch (IllegalArgumentException&) {
- JDWP_INFO("JDWP error: Bad agent options: " << options);
+ // exit if version option specified
+ if (AgentBase::GetOptionParser().GetVersion()) {
+ ShowJDWPVersion();
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "exit"));
delete env.optionParser;
+ exit(0);
+ }
+
+ // check for required options
+ if (AgentBase::GetOptionParser().GetTransport() == 0) {
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "JDWP error: No agent option specified: transport"));
return JNI_ERR;
- } catch (AgentException& e) {
- JDWP_INFO("JDWP error: " << e.what() << " [" << e.ErrCode() << "]");
+ }
+ if (!AgentBase::GetOptionParser().GetServer()
+ && AgentBase::GetOptionParser().GetAddress() == 0) {
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "JDWP error: No agent option specified: address"));
return JNI_ERR;
}
+ // create all other modules
+ env.classManager = new ClassManager();
+ env.objectManager = new ObjectManager();
+ env.threadManager = new ThreadManager();
+ env.requestManager = new RequestManager();
+ env.transportManager = new TransportManager();
+ env.packetDispatcher = new PacketDispatcher();
+ env.eventDispatcher = new EventDispatcher();
+ env.agentManager = new AgentManager();
+
#ifndef NDEBUG
// display system properties
if (JDWP_TRACE_ENABLED(LOG_KIND_LOG)) {
jint pCount;
char **properties = 0;
- JVMTI_TRACE(err, jvmti->GetSystemProperties(&pCount, &properties));
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->GetSystemProperties(&pCount, &properties));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to get system properties: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to get system properties: %d", err));
}
JvmtiAutoFree afp(properties);
- JDWP_LOG("System properties:");
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "System properties:"));
for (jint j = 0; j < pCount; j++) {
char *value = 0;
JvmtiAutoFree afj(properties[j]);
- JVMTI_TRACE(err, jvmti->GetSystemProperty(properties[j], &value));
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->GetSystemProperty(properties[j], &value));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to get system property: "
- << JDWP_CHECK_NULL(properties[j]));
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to get system property: %s", JDWP_CHECK_NULL(properties[j])));
}
JvmtiAutoFree afv(value);
- JDWP_LOG(" " << j << ": " << JDWP_CHECK_NULL(properties[j])
- << " = " << JDWP_CHECK_NULL(value));
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, " %d: %s=%s", j, JDWP_CHECK_NULL(properties[j]), JDWP_CHECK_NULL(value)));
}
}
#endif // NDEBUG
@@ -349,42 +369,37 @@
jvmtiCapabilities caps;
memset(&caps, 0, sizeof(caps));
- JVMTI_TRACE(err, jvmti->GetPotentialCapabilities(&caps));
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->GetPotentialCapabilities(&caps));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to get potential capabilities: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to get potential capabilities: %d", err));
return JNI_ERR;
}
- // map directly into JDWP caps
- env.caps.canWatchFieldModification =
- caps.can_generate_field_modification_events;
+ // Map JVMTI capabilities onto JDWP capabilities
+ env.caps.canWatchFieldModification = caps.can_generate_field_modification_events;
env.caps.canWatchFieldAccess = caps.can_generate_field_access_events;
env.caps.canGetBytecodes = caps.can_get_bytecodes;
env.caps.canGetSyntheticAttribute = caps.can_get_synthetic_attribute;
env.caps.canGetOwnedMonitorInfo = caps.can_get_owned_monitor_info;
- env.caps.canGetCurrentContendedMonitor =
- caps.can_get_current_contended_monitor;
+ env.caps.canGetCurrentContendedMonitor = caps.can_get_current_contended_monitor;
env.caps.canGetMonitorInfo = caps.can_get_monitor_info;
- env.caps.canPopFrames = caps.can_pop_frame;
env.caps.canRedefineClasses = caps.can_redefine_classes;
- env.caps.canGetSourceDebugExtension =
- caps.can_get_source_debug_extension;
-
env.caps.canAddMethod = 0;
env.caps.canUnrestrictedlyRedefineClasses = 0;
+ env.caps.canPopFrames = caps.can_pop_frame;
env.caps.canUseInstanceFilters = 1;
+ env.caps.canGetSourceDebugExtension = caps.can_get_source_debug_extension;
env.caps.canRequestVMDeathEvent = 1;
- env.caps.canSetDefaultStratum = 0;
-
- //New capabilities for Java 6
+ env.caps.canSetDefaultStratum = 1;
+ // New JDWP capabilities for Java 6
env.caps.canGetInstanceInfo = 1;
env.caps.canRequestMonitorEvents = 1;
env.caps.canGetMonitorFrameInfo = 1;
- env.caps.canUseSourceNameFilters = 1;
- env.caps.canGetConstantPool =
- caps.can_get_constant_pool;
- env.caps.canForceEarlyReturn =
- caps.can_force_early_return;
+ env.caps.canUseSourceNameFilters = 0;
+ env.caps.canGetConstantPool = caps.can_get_constant_pool;
+ env.caps.canForceEarlyReturn = caps.can_force_early_return;
+
+ // Request JVMTI capabilities are made available
caps.can_tag_objects = 1;
caps.can_generate_monitor_events = 1;
@@ -394,7 +409,7 @@
// caps.can_get_source_file_name = 1;
// caps.can_get_line_numbers = 1;
// caps.can_access_local_variables = 1;
- // caps.can_generate_single_step_events = 1;
+ caps.can_generate_single_step_events = 1;
// caps.can_generate_exception_events = 1;
// caps.can_generate_frame_pop_events = 1;
// caps.can_generate_breakpoint_events = 1;
@@ -414,9 +429,9 @@
caps.can_generate_garbage_collection_events = 0;
caps.can_generate_object_free_events = 0;
- JVMTI_TRACE(err, jvmti->AddCapabilities(&caps));
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->AddCapabilities(&caps));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to add capabilities: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to add capabilities: %d", err));
return JNI_ERR;
}
}
@@ -448,23 +463,23 @@
ecbs.MonitorWait = &RequestManager::HandleMonitorWait;
ecbs.MonitorWaited = &RequestManager::HandleMonitorWaited;
- JVMTI_TRACE(err,
+ JVMTI_TRACE(LOG_DEBUG, err,
jvmti->SetEventCallbacks(&ecbs, static_cast<jint>(sizeof(ecbs))));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to set event callbacks: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to set event callbacks: %d", err));
return JNI_ERR;
}
- JVMTI_TRACE(err, jvmti->SetEventNotificationMode(JVMTI_ENABLE,
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->SetEventNotificationMode(JVMTI_ENABLE,
JVMTI_EVENT_VM_INIT, 0));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to enable VM_INIT event: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to enable VM_INIT event: %d", err));
return JNI_ERR;
}
- JVMTI_TRACE(err, jvmti->SetEventNotificationMode(JVMTI_ENABLE,
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->SetEventNotificationMode(JVMTI_ENABLE,
JVMTI_EVENT_VM_DEATH, 0));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to enable VM_DEATH event: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to enable VM_DEATH event: %d", err));
return JNI_ERR;
}
}
@@ -475,37 +490,34 @@
jvmtiExtensionEventInfo* extensionEvents = 0;
jvmtiError err;
- JVMTI_TRACE(err, jvmti->GetExtensionEvents(&extensionEventsCount, &extensionEvents));
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->GetExtensionEvents(&extensionEventsCount, &extensionEvents));
JvmtiAutoFree afv(extensionEvents);
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to get JVMTI extension events: " << err);
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to get JVMTI extension events: %d", err));
return JNI_ERR;
}
if (extensionEvents != 0 && extensionEventsCount > 0) {
for (int i = 0; i < extensionEventsCount; i++) {
if (strcmp(extensionEvents[i].id, JVMTI_EXTENSION_EVENT_ID_CLASS_UNLOAD) == 0) {
- JDWP_LOG("CLASS_UNLOAD extension event: "
- << " index=" << extensionEvents[i].extension_event_index
- << " id=" << extensionEvents[i].id
- << " param_count=" << extensionEvents[i].param_count
- << " descr=" << extensionEvents[i].short_description);
+ JDWP_TRACE(LOG_RELEASE, (LOG_LOG_FL, "CLASS_UNLOAD extension event: index=%d id=%d param_count=%d descr=%s",
+ extensionEvents[i].extension_event_index, extensionEvents[i].id, extensionEvents[i].param_count, extensionEvents[i].short_description));
// store info about found extension event
env.extensionEventClassUnload = static_cast<jvmtiExtensionEventInfo*>
(AgentBase::GetMemoryManager().Allocate(sizeof(jvmtiExtensionEventInfo) JDWP_FILE_LINE));
*(env.extensionEventClassUnload) = extensionEvents[i];
} else {
// free allocated memory for not used extension events
- JVMTI_TRACE(err, jvmti->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->Deallocate(
reinterpret_cast<unsigned char*>(extensionEvents[i].id)));
- JVMTI_TRACE(err, jvmti->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->Deallocate(
reinterpret_cast<unsigned char*>(extensionEvents[i].short_description)));
if (extensionEvents[i].params != 0) {
for (int j = 0; j < extensionEvents[i].param_count; j++) {
- JVMTI_TRACE(err, jvmti->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->Deallocate(
reinterpret_cast<unsigned char*>(extensionEvents[i].params[j].name)));
}
- JVMTI_TRACE(err, jvmti->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->Deallocate(
reinterpret_cast<unsigned char*>(extensionEvents[i].params)));
}
}
@@ -518,8 +530,10 @@
JNIEXPORT void JNICALL
Agent_OnUnload(JavaVM *vm)
{
-// JDWP_TRACE_ENTRY("Agent_OnUnload(" << vm << ")");
-
+ if (disableOnUnload) {
+ return;
+ }
+
if (AgentBase::GetAgentEnv() != 0) {
delete &AgentBase::GetEventDispatcher();
delete &AgentBase::GetPacketDispatcher();
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentAllocator.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentAllocator.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentAllocator.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentAllocator.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.5.2.1 $
- */
-
/**
* @file
* AgentAllocator.h
@@ -30,8 +24,6 @@
#ifndef _AGENT_ALLOCATOR_H_
#define _AGENT_ALLOCATOR_H_
-#include <memory>
-
namespace jdwp {
/**
@@ -61,13 +53,13 @@
/**
* A constructor.
*/
- AgentAllocator() throw() { }
+ AgentAllocator() { }
/**
* A copy constructor.
*/
template <class U>
- AgentAllocator(const AgentAllocator<U> ©) throw() { }
+ AgentAllocator(const AgentAllocator<U> ©) { }
pointer allocate(size_t n, const void* = 0) {
return reinterpret_cast<pointer>(
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentBase.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentBase.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentBase.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentBase.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.8.2.1 $
- */
-
/**
* @file
* AgentBase.h
@@ -30,10 +24,10 @@
#ifndef _AGENT_BASE_H_
#define _AGENT_BASE_H_
-#include <cstdio>
-#include <cstdlib>
-#include <sstream>
-
+#include <vector>
+#include <queue>
+#include <stdarg.h>
+#include <stdlib.h>
#include "AgentEnv.h"
#include "MemoryManager.h"
#include "Log.h"
@@ -43,9 +37,8 @@
#else
#define CHECK_ENV(env) { \
if (env == 0) { \
- std::fprintf(stderr, \
- "Bad environment: "# env"=%p\n", env); \
- std::exit(1); \
+ JDWP_TRACE(LOG_DEBUG, (LOG_ERROR_FL, "Bad environment: env=%p", env)); \
+ ::exit(1); \
} \
}
#endif // NDEBUG
@@ -55,9 +48,8 @@
#else
#define CHECK_ENV_PTR(env, ptr) { \
if (env == 0 || env->ptr == 0) { \
- std::fprintf(stderr, \
- "Bad environment: "# env"=%p, "# ptr"=%p\n", env, env->ptr); \
- std::exit(1); \
+ JDWP_TRACE(LOG_DEBUG, (LOG_ERROR_FL, "Bad environment: env=%p, ptr=%p", env, env->ptr)); \
+ ::exit(1); \
} \
}
#endif // NDEBUG
@@ -125,28 +117,42 @@
/**
* A constructor.
*/
- AgentBase() throw() {}
+ AgentBase() {}
/**
* Stores agent environment in the agent base.
*
* @param env - the pointer to the agent environment
*/
- static void SetAgentEnv(AgentEnv *env) throw() {
+ static void SetAgentEnv(AgentEnv *env) {
m_agentEnv = env;
}
/**
* Gets agent environment from the agent base.
*/
- static AgentEnv* GetAgentEnv() throw() {
+ static AgentEnv* GetAgentEnv() {
return m_agentEnv;
}
/**
+ * Sets the default stratum.
+ */
+ static void SetDefaultStratum(char *stratum) {
+ m_defaultStratum = stratum;
+ }
+
+ /**
+ * Gets the default stratum.
+ */
+ static char* GetDefaultStratum() {
+ return m_defaultStratum;
+ }
+
+ /**
* Gets the memory manager reference from the agent base.
*/
- static MemoryManager& GetMemoryManager() throw() {
+ static MemoryManager& GetMemoryManager() {
CHECK_ENV_PTR(m_agentEnv, memoryManager);
return *m_agentEnv->memoryManager;
}
@@ -154,7 +160,7 @@
/**
* Gets a log manager reference from the agent base.
*/
- static LogManager& GetLogManager() throw() {
+ static LogManager& GetLogManager() {
CHECK_ENV_PTR(m_agentEnv, logManager);
return *m_agentEnv->logManager;
}
@@ -162,7 +168,7 @@
/**
* Gets the option-parser reference from the agent base.
*/
- static OptionParser& GetOptionParser() throw() {
+ static OptionParser& GetOptionParser() {
CHECK_ENV_PTR(m_agentEnv, optionParser);
return *m_agentEnv->optionParser;
}
@@ -170,7 +176,7 @@
/**
* Gets the thread-manager reference from the agent base.
*/
- static ThreadManager& GetThreadManager() throw() {
+ static ThreadManager& GetThreadManager() {
CHECK_ENV_PTR(m_agentEnv, threadManager);
return *m_agentEnv->threadManager;
}
@@ -178,7 +184,7 @@
/**
* Gets the transport-manager reference from the agent base.
*/
- static TransportManager& GetTransportManager() throw() {
+ static TransportManager& GetTransportManager() {
CHECK_ENV_PTR(m_agentEnv, transportManager);
return *m_agentEnv->transportManager;
}
@@ -186,7 +192,7 @@
/**
* Gets the object-manager reference from the agent base.
*/
- static ObjectManager& GetObjectManager() throw() {
+ static ObjectManager& GetObjectManager() {
CHECK_ENV_PTR(m_agentEnv, objectManager);
return *m_agentEnv->objectManager;
}
@@ -194,7 +200,7 @@
/**
* Gets the class-manager reference from the agent base.
*/
- static ClassManager& GetClassManager() throw() {
+ static ClassManager& GetClassManager() {
CHECK_ENV_PTR(m_agentEnv, classManager);
return *m_agentEnv->classManager;
}
@@ -202,7 +208,7 @@
/**
* Gets the packet-dispatcher reference from the agent base.
*/
- static PacketDispatcher& GetPacketDispatcher() throw() {
+ static PacketDispatcher& GetPacketDispatcher() {
CHECK_ENV_PTR(m_agentEnv, packetDispatcher);
return *m_agentEnv->packetDispatcher;
}
@@ -210,7 +216,7 @@
/**
* Gets the event-dispatcher reference from the agent base.
*/
- static EventDispatcher& GetEventDispatcher() throw() {
+ static EventDispatcher& GetEventDispatcher() {
CHECK_ENV_PTR(m_agentEnv, eventDispatcher);
return *m_agentEnv->eventDispatcher;
}
@@ -218,7 +224,7 @@
/**
* Gets the request-manager reference from the agent base.
*/
- static RequestManager& GetRequestManager() throw() {
+ static RequestManager& GetRequestManager() {
CHECK_ENV_PTR(m_agentEnv, requestManager);
return *m_agentEnv->requestManager;
}
@@ -226,15 +232,24 @@
/**
* Gets the agent-manager reference from the agent base.
*/
- static AgentManager& GetAgentManager() throw() {
+ static AgentManager& GetAgentManager() {
CHECK_ENV_PTR(m_agentEnv, agentManager);
return *m_agentEnv->agentManager;
}
+
+ /**
+ * Gets the exception-manager reference from the agent base.
+ */
+ static ExceptionManager& GetExceptionManager() {
+ CHECK_ENV_PTR(m_agentEnv, exceptionManager);
+ return *m_agentEnv->exceptionManager;
+ }
+
/**
* Gets the pointer to JVMTI environment from the agent base.
*/
- static jvmtiEnv* GetJvmtiEnv() throw() {
+ static jvmtiEnv* GetJvmtiEnv() {
CHECK_ENV_PTR(m_agentEnv, jvmti);
return m_agentEnv->jvmti;
}
@@ -242,7 +257,7 @@
/**
* Gets the pointer to the target VM from the agent base.
*/
- static JavaVM* GetJavaVM() throw() {
+ static JavaVM* GetJavaVM() {
CHECK_ENV_PTR(m_agentEnv, jvm);
return m_agentEnv->jvm;
}
@@ -250,7 +265,7 @@
/**
* Gets the pointer to JNI environment from the agent base.
*/
- static JNIEnv* GetJniEnv() throw() {
+ static JNIEnv* GetJniEnv() {
JNIEnv *jniEnv = 0;
CHECK_ENV_PTR(m_agentEnv, jvm);
(m_agentEnv->jvm)->GetEnv((void **)&jniEnv, JNI_VERSION_1_4);
@@ -260,7 +275,7 @@
/**
* Gets JDWP capabilities from the agent base.
*/
- static jdwpCapabilities& GetCapabilities() throw() {
+ static jdwpCapabilities& GetCapabilities() {
CHECK_ENV(m_agentEnv);
return m_agentEnv->caps;
}
@@ -268,7 +283,7 @@
/**
* Gets a dead status of the agent.
*/
- static bool IsDead() throw() {
+ static bool IsDead() {
CHECK_ENV(m_agentEnv);
return m_agentEnv->isDead;
}
@@ -276,7 +291,7 @@
/**
* Sets a dead status to the agent.
*/
- static void SetIsDead(bool isDead) throw() {
+ static void SetIsDead(bool isDead) {
CHECK_ENV(m_agentEnv);
m_agentEnv->isDead = isDead;
}
@@ -290,6 +305,7 @@
}
static AgentEnv *m_agentEnv;
+ static char *m_defaultStratum;
};
inline void* Allocatable::operator new(size_t size) {
@@ -322,17 +338,16 @@
* A constructor.
* A pointer to the JVMTI memory is saved here.
*/
- JvmtiAutoFree(void* ptr) throw() : m_ptr(ptr) { }
+ JvmtiAutoFree(void* ptr) : m_ptr(ptr) { }
/**
* A destructor.
* The saved pointer to the JVMTI memory is freed here.
*/
- ~JvmtiAutoFree() throw() {
+ ~JvmtiAutoFree() {
if (m_ptr != 0) {
- jvmtiError err;
- JVMTI_TRACE(err, AgentBase::GetJvmtiEnv()->
- Deallocate(reinterpret_cast<unsigned char*>(m_ptr)));
+ jvmtiError err = AgentBase::GetJvmtiEnv()->
+ Deallocate(reinterpret_cast<unsigned char*>(m_ptr));
JDWP_ASSERT(err==JVMTI_ERROR_NONE);
}
}
@@ -360,13 +375,13 @@
* A constructor.
* A pointer to the agent memory is saved here.
*/
- AgentAutoFree(void* ptr JDWP_FILE_LINE_PAR) throw() : m_ptr(ptr) JDWP_FILE_LINE_INI { }
+ AgentAutoFree(void* ptr JDWP_FILE_LINE_PAR) : m_ptr(ptr) JDWP_FILE_LINE_INI { }
/**
* A destructor.
* The saved pointer to the agent memory is freed here.
*/
- ~AgentAutoFree() throw() {
+ ~AgentAutoFree() {
if (m_ptr != 0) {
AgentBase::GetMemoryManager().Free(m_ptr JDWP_FILE_LINE_MPAR);
}
@@ -383,8 +398,6 @@
void* m_ptr;
};
-#ifndef NDEBUG
-
/**
* The given class is used in the debug mode only for tracing entry/exit of
* agent functions.
@@ -397,9 +410,13 @@
* A constructor.
* Traces method entry in the log.
*/
- JdwpTraceEntry(std::ostringstream& os, const char* file, int line, int kind)
- : m_stream(os), m_file(file), m_line(line), m_kind(kind) {
- AgentBase::GetLogManager().Trace(">> " + m_stream.str(), m_file, m_line, m_kind);
+ JdwpTraceEntry(int kind, const char* file, int line, const char* format, ...)
+ : m_file(file), m_line(line), m_kind(kind), m_format(format) {
+ if (JDWP_TRACE_ENABLED_VAARGS((m_kind, m_file, m_line, m_format))) {
+ va_start(m_args, format);
+ AgentBase::GetLogManager().TraceEnterv(kind, file, line, format, m_args);
+ va_end(m_args);
+ }
}
/**
@@ -407,17 +424,18 @@
* Traces method exit in the log.
*/
~JdwpTraceEntry() {
- AgentBase::GetLogManager().Trace("<< " + m_stream.str(), m_file, m_line, m_kind);
+ if (JDWP_TRACE_ENABLED_VAARGS((m_kind, m_file, m_line, m_format))) {
+ AgentBase::GetLogManager().TraceExit(m_kind, m_file, m_line, m_format);
+ }
}
private:
- std::ostringstream& m_stream;
const char* m_file;
int m_line;
int m_kind;
+ const char* m_format;
+ va_list m_args;
};
-#endif // NDEBUG
-
} // namespace jdwp
#endif // _AGENT_BASE_H_
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEnv.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEnv.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEnv.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEnv.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.4.2.1 $
- */
-
/**
* @file
* AgentEnv.h
@@ -47,6 +41,7 @@
class EventDispatcher;
class RequestManager;
class AgentManager;
+ class ExceptionManager;
/**
* Agent-environment structure containing all objects participating in
@@ -65,6 +60,7 @@
PacketDispatcher *packetDispatcher;
EventDispatcher *eventDispatcher;
RequestManager *requestManager;
+ ExceptionManager *exceptionManager;
jvmtiEnv *jvmti;
JavaVM *jvm;
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.cpp?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.cpp Thu Jul 16 15:57:37 2009
@@ -15,23 +15,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.10 $
- */
-// AgentEventRequest.cpp
-
-#include <string.h>
#include "AgentEventRequest.h"
#include "RequestManager.h"
#include "Log.h"
+#include <string.h>
+
+#if defined(ZOS)
+#define _XOPEN_SOURCE 500
+#include <unistd.h>
+#endif
+
using namespace jdwp;
AgentEventRequest::AgentEventRequest(jdwpEventKind kind,
jdwpSuspendPolicy suspend, jint modCount)
- throw(AgentException)
{
m_requestId = 0;
m_eventKind = kind;
@@ -46,7 +44,7 @@
}
}
-AgentEventRequest::~AgentEventRequest() throw()
+AgentEventRequest::~AgentEventRequest()
{
for (jint i = 0; i < m_modifierCount; i++) {
delete m_modifiers[i];
@@ -57,9 +55,12 @@
}
bool AgentEventRequest::ApplyModifiers(JNIEnv *jni, EventInfo &eInfo)
- throw(AgentException)
+
{
+ JDWP_TRACE_ENTRY(LOG_DEBUG, (LOG_FUNC_FL, "ApplyModifiers(%p, ...)", jni));
+
for (jint i = 0; i < m_modifierCount; i++) {
+ JDWP_TRACE(LOG_DEBUG, (LOG_EVENT_FL, "ApplyModifiers: index=%d, modifier_kind=%d", i, (m_modifiers[i])->GetKind()));
if (!m_modifiers[i]->Apply(jni, eInfo)) {
return false;
}
@@ -71,7 +72,7 @@
return true;
}
-jthread AgentEventRequest::GetThread() const throw()
+jthread AgentEventRequest::GetThread() const
{
for (jint i = 0; i < m_modifierCount; i++) {
if ((m_modifiers[i])->GetKind() == JDWP_MODIFIER_THREAD_ONLY) {
@@ -82,7 +83,7 @@
return 0;
}
-FieldOnlyModifier* AgentEventRequest::GetField() const throw()
+FieldOnlyModifier* AgentEventRequest::GetField() const
{
for (jint i = 0; i < m_modifierCount; i++) {
if ((m_modifiers[i])->GetKind() == JDWP_MODIFIER_FIELD_ONLY) {
@@ -92,7 +93,7 @@
return 0;
}
-LocationOnlyModifier* AgentEventRequest::GetLocation() const throw()
+LocationOnlyModifier* AgentEventRequest::GetLocation() const
{
for (jint i = 0; i < m_modifierCount; i++) {
if ((m_modifiers[i])->GetKind() == JDWP_MODIFIER_LOCATION_ONLY) {
@@ -107,7 +108,7 @@
// StepRequest
//-----------------------------------------------------------------------------
-StepRequest::~StepRequest() throw()
+StepRequest::~StepRequest()
{
ControlSingleStep(false);
JNIEnv *jni = GetJniEnv();
@@ -120,56 +121,170 @@
jni->DeleteGlobalRef(m_thread);
}
-jint StepRequest::GetCurrentLine() throw()
+jint StepRequest::GetCurrentLine()
{
jint lineNumber = -1;
- if (m_size == JDWP_STEP_LINE) {
- jmethodID method;
- jlocation location;
- jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->GetFrameLocation(m_thread, 0,
- &method, &location));
- if (err == JVMTI_ERROR_NONE && location != -1) {
- jint cnt;
- jvmtiLineNumberEntry* table = 0;
- JVMTI_TRACE(err, GetJvmtiEnv()->GetLineNumberTable(method,
- &cnt, &table));
- JvmtiAutoFree jafTable(table);
- if (err == JVMTI_ERROR_NONE && cnt > 0) {
- jint i = 1;
- while (i < cnt && location >= table[i].start_location) {
- i++;
+ char* sourceDebugExtension = 0;
+ char* default_stratum;
+ char* stratum;
+ jmethodID method;
+ jlocation location;
+ jvmtiError err;
+
+ if (m_size != JDWP_STEP_LINE)
+ return -1;
+
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetFrameLocation(m_thread, 0,
+ &method, &location));
+ if (err == JVMTI_ERROR_NONE && location != -1) {
+ jint cnt;
+ jvmtiLineNumberEntry* table = 0;
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetLineNumberTable(method,
+ &cnt, &table));
+ JvmtiAutoFree jafTable(table);
+ if (err == JVMTI_ERROR_NONE && cnt > 0) {
+ jint i = 1;
+ while (i < cnt && location >= table[i].start_location) {
+ i++;
+ }
+ lineNumber = table[i-1].line_number;
+ }
+ } else {
+ return -1;
+ }
+
+ default_stratum = AgentBase::GetDefaultStratum();
+ if (default_stratum != NULL && strcmp(default_stratum, "Java") == 0 )
+ return lineNumber;
+
+ jclass jvmClass;
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetMethodDeclaringClass(method, &jvmClass));
+ if (err != JVMTI_ERROR_NONE)
+ return -1;
+
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetSourceDebugExtension(jvmClass,
+ &sourceDebugExtension));
+ if (err != JVMTI_ERROR_NONE)
+ return lineNumber;
+
+ JvmtiAutoFree autoFreeDebugExtension(sourceDebugExtension);
+
+#ifdef ZOS
+ /* Fix for 143846 - make sure we pass EBCDIC strings to zOS system functions */
+ __atoe(sourceDebugExtension);
+#pragma convlit(suspend)
+#endif /* ZOS */
+
+ char *tok = strtok(sourceDebugExtension, "\n");
+ if (tok == NULL) return -1;
+ tok = strtok(NULL, "\n");
+ if (tok == NULL) return -1;
+ tok = strtok(NULL, "\n"); /* This is the preferred stratum for this class */
+ if (tok == NULL) return -1;
+ if ( ( default_stratum == NULL || strlen(default_stratum) == 0 ) &&
+ strcmp(tok, "Java") == 0)
+ return lineNumber;
+
+ stratum = ( default_stratum == NULL || strlen(default_stratum) == 0 ) ?
+ tok : default_stratum;
+
+ // printf("Looking for equivalent of java line %d in stratum %s\n",
+ // lineNumber, stratum);
+ while( ( tok = strtok(NULL, "\n") ) ) {
+ if (strlen(tok) >= 2) {
+ while (tok[0] == '*' && tok[1] == 'S' && tok[2] == ' ') {
+ tok++; tok++;
+ while (tok[0] == ' ' && tok[0] != 0) tok++; // skip spaces
+ // printf("stratum = '%s'\n", tok);
+ if (strcmp(stratum, tok) == 0) {
+ // this is the stratum that is required
+ tok = strtok(NULL, "\n");
+ if (tok == NULL) return -1;
+ // parse until we find another stratum section or
+ // the end token
+ while (!(tok[0] == '*' && ( tok[1] == 'S'
+ || tok[1] == 'E' ))) {
+ if (strlen(tok) >= 2 &&
+ tok[0] == '*' && tok[1] == 'L' && tok[2] == '\0') {
+ // parse line info section
+ do {
+ tok = strtok(NULL, "\n");
+ if (tok == NULL) return -1;
+ if (tok[0] >= '0' && tok[0] <= '9') {
+ long int in_start = strtol(tok, &tok, 10);
+ long int in_len = 1;
+ long int out_start;
+ long int out_len = 1;
+ if (tok[0] == '#') {
+ tok++;
+ // ignore file id
+ (void)strtol(tok, &tok, 10);
+ }
+ if (tok[0] == ',') {
+ tok++;
+ in_len = strtol(tok, &tok, 10);
+ }
+ if (tok[0] != ':') {
+ continue;
+ }
+ tok++;
+ out_start = strtol(tok, &tok, 10);
+ if (tok[0] == ',') {
+ tok++;
+ out_len = strtol(tok, &tok, 10);
+ }
+ if (lineNumber >= out_start
+ && lineNumber < out_start+(out_len
+ *in_len)) {
+ return in_start
+ +(lineNumber-out_start)/out_len;
+ }
+ }
+ } while (tok[0] != '*');
+ // puts("No match in stratum line table");
+ return -1;
+ }
+ tok = strtok(NULL, "\n");
+ if (tok == NULL) return -1;
+ }
}
- lineNumber = table[i-1].line_number;
}
}
}
- return lineNumber;
+
+#ifdef ZOS
+#pragma convlit(resume)
+#endif /* ZOS */
+
+ return -1;
}
-void StepRequest::ControlSingleStep(bool enable) throw()
+void StepRequest::ControlSingleStep(bool enable)
{
- JDWP_TRACE_EVENT("control Step: "<< (enable ? "on" : "off")
- << ", thread=" << m_thread);
+ JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "control Step: %s, thread=%p", (enable ? "on" : "off"), m_thread));
jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->SetEventNotificationMode(
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->SetEventNotificationMode(
(enable) ? JVMTI_ENABLE : JVMTI_DISABLE,
JVMTI_EVENT_SINGLE_STEP, m_thread));
m_isActive = enable;
}
-void StepRequest::Restore() throw(AgentException) {
- JDWP_TRACE_EVENT("Restore stepRequest: " << (m_isActive ? "on" : "off"));
+int StepRequest::Restore() {
+ JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "Restore stepRequest: %s", (m_isActive ? "on" : "off")));
jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->SetEventNotificationMode(
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->SetEventNotificationMode(
(m_isActive) ? JVMTI_ENABLE : JVMTI_DISABLE,
JVMTI_EVENT_SINGLE_STEP, m_thread));
if (err != JVMTI_ERROR_NONE) {
- throw AgentException(err);
+ AgentException ex = AgentException(err);
+ JDWP_SET_EXCEPTION(ex);
+ return err;
}
+
+ return JDWP_ERROR_NONE;
}
-bool StepRequest::IsClassApplicable(JNIEnv* jni, EventInfo &eInfo) throw()
+bool StepRequest::IsClassApplicable(JNIEnv* jni, EventInfo &eInfo)
{
for (jint i = 0; i < m_modifierCount; i++) {
switch ((m_modifiers[i])->GetKind()) {
@@ -189,32 +304,27 @@
return true;
}
-void StepRequest::OnFramePop(JNIEnv *jni)
- throw(AgentException)
+int StepRequest::OnFramePop(JNIEnv *jni)
{
JDWP_ASSERT(m_framePopRequest != 0);
- jint currentCount;
- jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->GetFrameCount(m_thread, ¤tCount));
- if (err != JVMTI_ERROR_NONE) {
- currentCount = -1;
- }
-
+ int ret;
if (m_depth == JDWP_STEP_OVER ||
- (m_depth == JDWP_STEP_OUT && currentCount <= m_frameCount) ||
- (m_methodEntryRequest != 0 && currentCount-1 <= m_frameCount))
+ m_depth == JDWP_STEP_OUT ||
+ m_methodEntryRequest != 0)
{
ControlSingleStep(true);
if (m_methodEntryRequest != 0) {
- GetRequestManager().DeleteRequest(jni, m_methodEntryRequest);
+ ret = GetRequestManager().DeleteRequest(jni, m_methodEntryRequest);
+ JDWP_CHECK_RETURN(ret);
m_methodEntryRequest = 0;
}
}
+
+ return JDWP_ERROR_NONE;
}
void StepRequest::OnMethodEntry(JNIEnv *jni, EventInfo &eInfo)
- throw(AgentException)
{
JDWP_ASSERT(m_methodEntryRequest != 0);
JDWP_ASSERT(m_depth == JDWP_STEP_INTO);
@@ -228,19 +338,20 @@
}
}
-void StepRequest::Init(JNIEnv *jni, jthread thread, jint size, jint depth)
- throw(AgentException)
+int StepRequest::Init(JNIEnv *jni, jthread thread, jint size, jint depth)
{
m_thread = jni->NewGlobalRef(thread);
if (m_thread == 0) {
- throw OutOfMemoryException();
+ AgentException ex(JDWP_ERROR_OUT_OF_MEMORY);
+ JDWP_SET_EXCEPTION(ex);
+ return JDWP_ERROR_OUT_OF_MEMORY;
}
m_size = size;
m_depth = depth;
if (m_depth != JDWP_STEP_INTO || m_size != JDWP_STEP_MIN) {
jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->GetFrameCount(m_thread, &m_frameCount));
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetFrameCount(m_thread, &m_frameCount));
if (err != JVMTI_ERROR_NONE) {
m_frameCount = -1;
}
@@ -254,9 +365,10 @@
m_framePopRequest =
new AgentEventRequest(JDWP_EVENT_FRAME_POP, JDWP_SUSPEND_NONE, 1);
m_framePopRequest->AddModifier(new ThreadOnlyModifier(jni, thread), 0);
- GetRequestManager().AddInternalRequest(jni, m_framePopRequest);
+ int ret = GetRequestManager().AddInternalRequest(jni, m_framePopRequest);
+ JDWP_CHECK_RETURN(ret);
jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->NotifyFramePop(m_thread, 0));
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->NotifyFramePop(m_thread, 0));
if (err == JVMTI_ERROR_OPAQUE_FRAME) {
m_isNative = true;
}
@@ -270,12 +382,11 @@
ControlSingleStep(true);
}
- JDWP_TRACE_EVENT("step start: size=" << m_size << ", depth=" << m_depth
- << ", frame=" << m_frameCount << ", line=" << m_lineNumber);
+ JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "step start: size=%d, depth=%d, frame=%d, line=%d", m_size, m_depth, m_frameCount, m_lineNumber));
+ return JDWP_ERROR_NONE;
}
bool StepRequest::ApplyModifiers(JNIEnv *jni, EventInfo &eInfo)
- throw(AgentException)
{
JDWP_ASSERT(eInfo.thread != 0);
@@ -285,7 +396,7 @@
jint currentCount = 0;
jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->GetFrameCount(m_thread, ¤tCount));
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->GetFrameCount(m_thread, ¤tCount));
if (err != JVMTI_ERROR_NONE) {
return false;
}
@@ -297,6 +408,7 @@
if (currentCount < m_frameCount) {
// method exit
+ m_frameCount = currentCount;
} else if (currentCount > m_frameCount) {
// method entry
if (m_depth != JDWP_STEP_INTO || !IsClassApplicable(jni, eInfo)) {
@@ -307,10 +419,14 @@
JDWP_EVENT_METHOD_ENTRY, JDWP_SUSPEND_NONE, 1);
m_methodEntryRequest->AddModifier(
new ThreadOnlyModifier(jni, m_thread), 0);
- GetRequestManager().AddInternalRequest(
- jni, m_methodEntryRequest);
+ int ret = GetRequestManager().AddInternalRequest(
+ jni, m_methodEntryRequest);
+ if (ret != JDWP_ERROR_NONE) {
+ AgentException aex = AgentBase::GetExceptionManager().GetLastException();
+ JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "Error adding internal request: %s", aex.GetExceptionMessage(jni)));
+ }
}
- JVMTI_TRACE(err, GetJvmtiEnv()->NotifyFramePop(m_thread, 0));
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->NotifyFramePop(m_thread, 0));
if (err == JVMTI_ERROR_OPAQUE_FRAME) {
m_isNative = true;
}
@@ -318,14 +434,18 @@
}
} else { // currentCount == m_frameCount
// check against line
- if (m_size == JDWP_STEP_LINE && currentLine == m_lineNumber && currentLine != -1) {
+ if (m_size == JDWP_STEP_LINE && currentLine == m_lineNumber) {
return false;
}
}
+
+ if (currentLine == -1) {
+ return false;
+ }
m_frameCount = currentCount;
m_lineNumber = currentLine;
- JDWP_TRACE_EVENT("step: frame=" << m_frameCount << ", line=" << m_lineNumber);
+ JDWP_TRACE(LOG_RELEASE, (LOG_EVENT_FL, "step: frame=%d, line=%d", m_frameCount, m_lineNumber));
return AgentEventRequest::ApplyModifiers(jni, eInfo);
}
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentEventRequest.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.7.2.1 $
- */
-
/**
* @file
* AgentEventRequest.h
@@ -30,8 +24,10 @@
#ifndef _AGENT_EVENT_REQUEST_H_
#define _AGENT_EVENT_REQUEST_H_
+#include "memory.h"
#include "AgentBase.h"
#include "RequestModifier.h"
+#include "ExceptionManager.h"
namespace jdwp {
@@ -55,26 +51,26 @@
jdwpEventKind kind,
jdwpSuspendPolicy suspend,
jint modCount = 0
- ) throw(AgentException);
+ );
/**
* A destructor.
*/
- virtual ~AgentEventRequest() throw();
+ virtual ~AgentEventRequest();
/**
* Assigns request ID.
*
* @param id - request ID
*/
- void SetRequestId(RequestID id) throw() { m_requestId = id; }
+ void SetRequestId(RequestID id) { m_requestId = id; }
/**
* Assigns expiration flag of the event request.
*
* @param flag - expire flag
*/
- void SetExpired(bool flag) throw() { m_isExpired = flag; }
+ void SetExpired(bool flag) { m_isExpired = flag; }
/**
* Assigns a new modifier at the given location in the list of modifiers.
@@ -82,7 +78,7 @@
* @param modifier - pointer to modifier
* @param i - index of place in the array of modifiers
*/
- virtual void AddModifier(RequestModifier* modifier, jint i) throw() {
+ virtual void AddModifier(RequestModifier* modifier, jint i) {
JDWP_ASSERT(i < m_modifierCount);
m_modifiers[i] = modifier;
}
@@ -90,35 +86,35 @@
/**
* Returns request ID.
*/
- RequestID GetRequestId() const throw() {
+ RequestID GetRequestId() const {
return m_requestId;
}
/**
* Returns event kind of this request.
*/
- jdwpEventKind GetEventKind() const throw() {
+ jdwpEventKind GetEventKind() const {
return m_eventKind;
}
/**
* Returns suspend policy of this request.
*/
- jdwpSuspendPolicy GetSuspendPolicy() const throw() {
+ jdwpSuspendPolicy GetSuspendPolicy() const {
return m_suspendPolicy;
}
/**
* Returns number of modifiers of this event request.
*/
- jint GetModifierCount() const throw() {
+ jint GetModifierCount() const {
return m_modifierCount;
}
/**
* Returns whether this event request is expired.
*/
- bool IsExpired() const throw() {
+ bool IsExpired() const {
return m_isExpired;
}
@@ -137,23 +133,22 @@
* @param jni - the JNI interface pointer
* @param eInfo - event information
*/
- virtual bool ApplyModifiers(JNIEnv* jni, EventInfo &eInfo)
- throw(AgentException);
+ virtual bool ApplyModifiers(JNIEnv* jni, EventInfo &eInfo);
/**
* Gets the Java thread from the corresponding ThreadOnly modifier.
*/
- virtual jthread GetThread() const throw();
+ virtual jthread GetThread() const;
/**
* Gets the FieldOnly modifier from the saved list of modifiers.
*/
- FieldOnlyModifier* GetField() const throw();
+ FieldOnlyModifier* GetField() const;
/**
* Gets the LocationOnly modifier from the saved list of modifiers.
*/
- LocationOnlyModifier* GetLocation() const throw();
+ LocationOnlyModifier* GetLocation() const;
protected:
@@ -184,7 +179,7 @@
* @param modCount - number of modifiers
*/
StepRequest(jdwpSuspendPolicy suspend, jint modCount)
- throw(AgentException) :
+ :
AgentEventRequest(JDWP_EVENT_SINGLE_STEP, suspend, modCount),
m_thread(0),
m_size(0),
@@ -200,14 +195,14 @@
/**
* A destructor.
*/
- ~StepRequest() throw();
+ ~StepRequest();
/**
* Handles step on frame pop event.
*
* @param jni - the JNI interface pointer
*/
- void OnFramePop(JNIEnv *jni) throw(AgentException);
+ int OnFramePop(JNIEnv *jni);
/**
* Handles step on method-entry event.
@@ -215,8 +210,7 @@
* @param jni - the JNI interface pointer
* @param eInfo - event information
*/
- void OnMethodEntry(JNIEnv *jni, EventInfo &eInfo)
- throw(AgentException);
+ void OnMethodEntry(JNIEnv *jni, EventInfo &eInfo);
/**
* Initializes step event request.
@@ -225,19 +219,19 @@
* @param size - step size
* @param depth - step depth
*/
- void Init(JNIEnv* jni, jthread thread, jint size, jint depth)
- throw(AgentException);
+ int Init(JNIEnv* jni, jthread thread, jint size, jint depth)
+ ;
/**
* Applies accompanied modifiers for filtering the given event.
*/
bool ApplyModifiers(JNIEnv* jni, EventInfo &eInfo)
- throw(AgentException);
+ ;
/**
* Gets the associated Java thread.
*/
- jthread GetThread() const throw() {
+ jthread GetThread() const {
return m_thread;
}
@@ -246,7 +240,7 @@
*
* @exception AgentException is thrown, if any error occurs.
*/
- void Restore() throw(AgentException);
+ int Restore();
private:
@@ -255,14 +249,14 @@
*
* @return Java integer (jint).
*/
- jint GetCurrentLine() throw();
+ jint GetCurrentLine();
/**
* Enables or disables single step event generation in the target VM.
*
* @param enable - boolean value for the step event notification mode
*/
- void ControlSingleStep(bool enable) throw();
+ void ControlSingleStep(bool enable);
/**
* Checks whether at least one modifier can be applied.
@@ -270,7 +264,7 @@
* @param jni - the JNI interface pointer
* @param eInfo - event-request descriptor
*/
- bool IsClassApplicable(JNIEnv* jni, EventInfo &eInfo) throw();
+ bool IsClassApplicable(JNIEnv* jni, EventInfo &eInfo);
jthread m_thread;
jint m_size;
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentException.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentException.h?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentException.h (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentException.h Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Pavel N. Vyssotski
- * @version $Revision: 1.5.2.1 $
- */
-
/**
* @file
* AgentException.h
@@ -30,31 +24,68 @@
#ifndef _AGENT_EXCEPTION_H_
#define _AGENT_EXCEPTION_H_
-#include <exception>
-#include <sstream>
-
+#include <string.h>
+#include <stdlib.h>
#include "jdwp.h"
-#include "jvmti.h"
#include "jdwpTransport.h"
+#include "jvmti.h"
+#include "vmi.h"
namespace jdwp {
- using namespace std;
+ typedef enum exceptions {
+ ENUM_AgentException = 0,
+ ENUM_OutOfMemoryException = 1,
+ ENUM_InternalErrorException = 2,
+ ENUM_NotImplementedException = 3,
+ ENUM_IllegalArgumentException = 4,
+ ENUM_InvalidStackFrameException = 5,
+ ENUM_InvalidIndexException = 6,
+ ENUM_TransportException = 7
+ } exceptions;
/**
* The base of all agent exceptions.
*/
- class AgentException : public exception {
+ class AgentException {
public:
+ AgentException() { }
+
/**
* A constructor.
*
* @param err - JDWP error code
*/
- AgentException(jdwpError err) throw() {
+ AgentException(jdwpError err, const char *message = NULL) {
m_error = err;
+ m_transportError = JDWPTRANSPORT_ERROR_NONE;
+ m_message = message;
+ m_mustFree = false;
+
+ switch(m_error) {
+ case JDWP_ERROR_OUT_OF_MEMORY:
+ m_exception = ENUM_OutOfMemoryException;
+ break;
+ case JDWP_ERROR_INTERNAL:
+ m_exception = ENUM_InternalErrorException;
+ break;
+ case JDWP_ERROR_NOT_IMPLEMENTED:
+ m_exception = ENUM_NotImplementedException;
+ break;
+ case JDWP_ERROR_ILLEGAL_ARGUMENT:
+ m_exception = ENUM_IllegalArgumentException;
+ break;
+ case JDWP_ERROR_OPAQUE_FRAME:
+ m_exception = ENUM_InvalidStackFrameException;
+ break;
+ case JDWP_ERROR_INVALID_INDEX:
+ m_exception = ENUM_InvalidIndexException;
+ break;
+ default:
+ m_exception = ENUM_AgentException;
+ }
}
/**
@@ -62,181 +93,164 @@
*
* @param err - JVMTI error code
*/
- AgentException(jvmtiError err) throw() {
+ AgentException(jvmtiError err, const char *message = NULL) {
m_error = (jdwpError)err;
+ m_transportError = JDWPTRANSPORT_ERROR_NONE;
+ m_exception = ENUM_AgentException;
+ m_message = message;
+ m_mustFree = false;
}
- /**
- * Returns the exception name.
- */
- virtual const char* what() const throw() { return "AgentException"; }
-
- /**
- * Returns JDWP error code.
- */
- jdwpError ErrCode() const throw() {
- return m_error;
+ AgentException(jdwpTransportError err, const char *message = NULL) {
+ m_transportError = err;
+ m_error = JDWP_ERROR_NONE;
+ m_exception = ENUM_TransportException;
+ m_message = message;
+ m_mustFree = false;
}
- private:
- jdwpError m_error;
- };
-
- /**
- * Out of memory exception thrown in case of JVMTI failures
- * of memory or reference allocation.
- */
- class OutOfMemoryException : public AgentException {
-
- public:
-
- /**
- * A constructor.
- */
- OutOfMemoryException() throw() :
- AgentException(JDWP_ERROR_OUT_OF_MEMORY) { }
-
- /**
- * Returns the given exception name.
- */
- const char* what() const throw() {
- return "JDWP_ERROR_OUT_OF_MEMORY";
+ AgentException(jdwpError err, jdwpTransportError terr, const char *message = NULL) {
+ m_error = err;
+ m_transportError = terr;
+ m_exception = ENUM_TransportException;
+ m_message = message;
+ m_mustFree = false;
}
- };
-
- /**
- * Exception caused by invalid internal state, checking or parameter
- * validation.
- */
- class InternalErrorException : public AgentException {
-
- public:
/**
- * A constructor.
+ * A copy constructor.
*/
- InternalErrorException() throw() :
- AgentException(JDWP_ERROR_INTERNAL) { }
+ AgentException(const AgentException& ex) {
+ if (&ex == NULL) {
+ m_mustFree = false;
+ return;
+ }
- /**
- * Returns the given exception name.
- */
- const char* what() const throw() {
- return "JDWP_ERROR_INTERNAL";
- }
- };
-
- /**
- * Exception thrown by unrealized method or function.
- */
- class NotImplementedException : public AgentException {
+ m_error = ex.m_error;
+ m_transportError = ex.m_transportError;
+ m_exception = ex.m_exception;
- public:
+ if (ex.m_message == NULL) {
+ m_message = NULL;
+ m_mustFree = false;
+ } else {
+ char *temp = (char *)malloc(strlen(ex.m_message) + 1);
+ strcpy(temp, ex.m_message);
+ m_message = (const char*)temp;
+ m_mustFree = true;
+ }
+ }
/**
- * A constructor.
+ * A destructor.
*/
- NotImplementedException() throw() :
- AgentException(JDWP_ERROR_NOT_IMPLEMENTED) { }
+ virtual ~AgentException() {
+ if (m_mustFree) {
+ free((void*)m_message);
+ }
+ }
/**
- * Returns the given exception name.
+ * Returns if the exception type is expected type.
*/
- const char* what() const throw() {
- return "JDWP_ERROR_NOT_IMPLEMENTED";
+ bool Compare(exceptions ex) {
+ return (ex == ENUM_AgentException)?true:(m_exception == ex);
}
- };
-
- /**
- * Exception caused by the parameter validation failure.
- */
- class IllegalArgumentException : public AgentException {
-
- public:
/**
- * A constructor.
+ * Returns the exception name.
*/
- IllegalArgumentException() throw() :
- AgentException(JDWP_ERROR_ILLEGAL_ARGUMENT) { }
+ virtual const char* what() const {
+ switch(m_exception) {
+ case ENUM_OutOfMemoryException:
+ return "OutOfMemoryException";
+ case ENUM_InternalErrorException:
+ return "InternalException";
+ case ENUM_NotImplementedException:
+ return "NotImplementedException";
+ case ENUM_IllegalArgumentException:
+ return "IllegalArgumentException";
+ case ENUM_InvalidStackFrameException:
+ return "InvalidStackFrameException";
+ case ENUM_InvalidIndexException:
+ return "InvalidIndexException";
+ case ENUM_TransportException:
+ return "TransportException";
+ default:
+ return "AgentException";
+ }
+ }
/**
- * Returns the given exception name.
+ * Returns JDWP error code.
*/
- const char* what() const throw() {
- return "JDWP_ERROR_ILLEGAL_ARGUMENT";
+ jdwpError ErrCode() const {
+ return m_error;
}
- };
-
- /**
- * Exception caused by invalid index value or out-of-range index.
- */
- class InvalidIndexException : public AgentException {
-
- public:
/**
- * A constructor.
+ * Returns JDWP transport error code.
*/
- InvalidIndexException() throw() :
- AgentException(JDWP_ERROR_INVALID_INDEX) { }
+ jdwpTransportError TransportErrCode() const {
+ return m_transportError;
+ }
/**
- * Returns the given exception name.
- */
- const char* what() const throw() {
- return "JDWP_ERROR_INVALID_INDEX";
+ * Return exceptions
+ */
+ exceptions ExceptionType() const {
+ return m_exception;
}
- };
-
- /**
- * Exception caused by failures in agent-transport layer.
- */
- class TransportException : public AgentException {
-
- public:
/**
- * A constructor.
- *
- * @param err - JDWP error code
- * @param transportError - transport error code
+ * Returns error message.
*/
- TransportException(jdwpError err = JDWP_ERROR_TRANSPORT_INIT,
- jdwpTransportError transportError = JDWPTRANSPORT_ERROR_NONE,
- const char* message = 0)
- throw() : AgentException(err)
- {
- this->m_transportError = transportError;
- this->m_message = message;
+ const char* ErrorMessage() const {
+ return m_message;
}
/**
- * Returns transport error code.
+ * Returns a formatted error message for this Exception
*/
- jdwpTransportError TransportErrorCode() const throw() {
- return m_transportError;
+ const char* GetExceptionMessage(JNIEnv* jni) {
+ PORT_ACCESS_FROM_ENV(jni);
+
+ // Create a full error message from this exception
+ int allocateSize = strlen(what()) + 16; // Gives enough space for the type and error codes to be displayed
+ const char *exMsg;
+ if (m_message != NULL) {
+ allocateSize += strlen(m_message);
+ exMsg = m_message;
+ } else {
+ exMsg = "";
+ }
+ char *message = (char*)hymem_allocate_memory(allocateSize);
+ if (m_exception == ENUM_TransportException) {
+ // If this is a TransportException, give transport error code
+ hystr_printf(privatePortLibrary, message, (U_32)allocateSize, "%s [%d/%d] %s", what(), m_error, m_transportError, exMsg);
+ } else {
+ hystr_printf(privatePortLibrary, message, (U_32)allocateSize, "%s [%d] %s", what(), m_error, exMsg);
+ }
+
+ return message;
}
- /**
- * Returns transport error message.
- */
- const char* TransportErrorMessage() const throw() {
- return m_message;
+ inline void* operator new(size_t size) {
+ return malloc(size);
}
- /**
- * Returns the given exception info.
- */
- const char* what() const throw() {
- return (m_message == 0 ? "TransportException" : m_message);
+ inline void operator delete(void* ptr) {
+ free(ptr);
}
private:
+ exceptions m_exception;
+ jdwpError m_error;
jdwpTransportError m_transportError;
- const char* m_message;
+ const char *m_message;
+ bool m_mustFree;
};
-
};
#endif // _AGENT_EXCEPTION_H_
+
Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentManager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentManager.cpp?rev=794726&r1=794725&r2=794726&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentManager.cpp (original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/AgentManager.cpp Thu Jul 16 15:57:37 2009
@@ -15,12 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Aleksander V. Budniy
- * @version $Revision: 1.10.2.1 $
- */
-
#include "AgentManager.h"
#include "ClassManager.h"
#include "ObjectManager.h"
@@ -30,17 +24,20 @@
#include "TransportManager.h"
#include "PacketDispatcher.h"
#include "EventDispatcher.h"
+#include "ExceptionManager.h"
using namespace jdwp;
-void AgentManager::Init(jvmtiEnv *jvmti, JNIEnv *jni) throw (AgentException)
+int AgentManager::Init(jvmtiEnv *jvmti, JNIEnv *jni)
{
- JDWP_TRACE_ENTRY("Init(" << jvmti << "," << jni << ")");
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Init(%p,%p)", jvmti, jni));
- JDWP_TRACE_PROG("Init: init agent modules and load transport");
+ JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "Init: init agent modules and load transport"));
+ int ret;
AgentBase::SetIsDead(false);
- AgentBase::GetClassManager().Init(jni);
+ ret = AgentBase::GetClassManager().Init(jni);
+ JDWP_CHECK_RETURN(ret);
AgentBase::GetObjectManager().Init(jni);
AgentBase::GetThreadManager().Init(jni);
AgentBase::GetRequestManager().Init(jni);
@@ -49,65 +46,74 @@
char* javaLibraryPath = 0;
jvmtiError err;
- JVMTI_TRACE(err,
+ JVMTI_TRACE(LOG_DEBUG, err,
jvmti->GetSystemProperty("java.library.path", &javaLibraryPath));
if (err != JVMTI_ERROR_NONE) {
- JDWP_INFO("Unable to get system property: java.library.path")
+ JDWP_TRACE(LOG_RELEASE, (LOG_INFO_FL, "Unable to get system property: java.library.path"));
}
JvmtiAutoFree afv(javaLibraryPath);
- AgentBase::GetTransportManager().Init(
+ ret = AgentBase::GetTransportManager().Init(
AgentBase::GetOptionParser().GetTransport(),
javaLibraryPath);
+ JDWP_CHECK_RETURN(ret);
+ return JDWP_ERROR_NONE;
}
-void AgentManager::Start(jvmtiEnv *jvmti, JNIEnv *jni) throw (AgentException)
+int AgentManager::Start(jvmtiEnv *jvmti, JNIEnv *jni)
{
- JDWP_TRACE_ENTRY("Start(" << jvmti << "," << jni << ")");
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Start(%p,%p)", jvmti, jni));
- JDWP_TRACE_PROG("Start: prepare connection and start all agent threads");
+ JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "Start: prepare connection and start all agent threads"));
// prepare transport connection
- AgentBase::GetTransportManager().PrepareConnection(
+ int ret = AgentBase::GetTransportManager().PrepareConnection(
AgentBase::GetOptionParser().GetAddress(),
AgentBase::GetOptionParser().GetServer(),
AgentBase::GetOptionParser().GetTimeout(),
AgentBase::GetOptionParser().GetTimeout()
);
+ JDWP_CHECK_RETURN(ret);
// launch debugger if required and disable initial handling of EXCEPTION event
const char* launch = AgentBase::GetOptionParser().GetLaunch();
if (launch != 0) {
- AgentBase::GetTransportManager().Launch(launch);
- DisableInitialExceptionCatch(jvmti, jni);
+ ret = AgentBase::GetTransportManager().Launch(launch);
+ JDWP_CHECK_RETURN(ret);
+ ret = DisableInitialExceptionCatch(jvmti, jni);
+ JDWP_CHECK_RETURN(ret);
}
// start agent threads
- AgentBase::GetEventDispatcher().Start(jni);
- AgentBase::GetPacketDispatcher().Start(jni);
+ ret = AgentBase::GetEventDispatcher().Start(jni);
+ JDWP_CHECK_RETURN(ret);
+ ret = AgentBase::GetPacketDispatcher().Start(jni);
+ JDWP_CHECK_RETURN(ret);
SetStarted(true);
+
+ return JDWP_ERROR_NONE;
}
void
-AgentManager::Stop(JNIEnv *jni) throw(AgentException)
+AgentManager::Stop(JNIEnv *jni)
{
- JDWP_TRACE_ENTRY("Stop(" << jni << ")");
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Stop(%p)", jni));
// stop PacketDispatcher and EventDispatcher threads, and reset all modules
- JDWP_TRACE_PROG("Stop: stop all agent threads");
+ JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "Stop: stop all agent threads"));
GetPacketDispatcher().Stop(jni);
}
void
-AgentManager::Clean(JNIEnv *jni) throw(AgentException)
+AgentManager::Clean(JNIEnv *jni)
{
// trace entry before cleaning LogManager
{
- JDWP_TRACE_ENTRY("Clean(" << jni << ")");
+ JDWP_TRACE_ENTRY(LOG_RELEASE, (LOG_FUNC_FL, "Clean(%p)", jni));
// clean all modules
- JDWP_TRACE_PROG("Clean: clean agent modules");
+ JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "Clean: clean agent modules"));
GetPacketDispatcher().Clean(jni);
GetThreadManager().Clean(jni);
GetRequestManager().Clean(jni);
@@ -119,16 +125,16 @@
jvmtiExtensionEventInfo* ext = GetAgentEnv()->extensionEventClassUnload;
if (ext != 0) {
jvmtiError err;
- JVMTI_TRACE(err, GetJvmtiEnv()->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->Deallocate(
reinterpret_cast<unsigned char*>(ext->id)));
- JVMTI_TRACE(err, GetJvmtiEnv()->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->Deallocate(
reinterpret_cast<unsigned char*>(ext->short_description)));
if (ext->params != 0) {
for (int j = 0; j < ext->param_count; j++) {
- JVMTI_TRACE(err, GetJvmtiEnv()->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->Deallocate(
reinterpret_cast<unsigned char*>(ext->params[j].name)));
}
- JVMTI_TRACE(err, GetJvmtiEnv()->Deallocate(
+ JVMTI_TRACE(LOG_DEBUG, err, GetJvmtiEnv()->Deallocate(
reinterpret_cast<unsigned char*>(ext->params)));
}
GetMemoryManager().Free(ext JDWP_FILE_LINE);
@@ -137,28 +143,37 @@
// clean LogManager and close log
GetLogManager().Clean();
+ GetExceptionManager().Clean();
}
-void AgentManager::EnableInitialExceptionCatch(jvmtiEnv *jvmti, JNIEnv *jni) throw (AgentException)
+int AgentManager::EnableInitialExceptionCatch(jvmtiEnv *jvmti, JNIEnv *jni)
{
- JDWP_TRACE_PROG("EnableInitialExceptionCatch");
+ JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "EnableInitialExceptionCatch"));
jvmtiError err;
- JVMTI_TRACE(err, jvmti->SetEventNotificationMode(
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->SetEventNotificationMode(
JVMTI_ENABLE , JVMTI_EVENT_EXCEPTION, 0));
if (err != JVMTI_ERROR_NONE) {
- throw AgentException(err);
+ AgentException ex(err);
+ JDWP_SET_EXCEPTION(ex);
+ return err;
}
+
+ return JDWP_ERROR_NONE;
}
-void AgentManager::DisableInitialExceptionCatch(jvmtiEnv *jvmti, JNIEnv *jni) throw (AgentException)
+int AgentManager::DisableInitialExceptionCatch(jvmtiEnv *jvmti, JNIEnv *jni)
{
- JDWP_TRACE_PROG("DisableInitialExceptionCatch");
+ JDWP_TRACE(LOG_RELEASE, (LOG_PROG_FL, "DisableInitialExceptionCatch"));
jvmtiError err;
- JVMTI_TRACE(err, jvmti->SetEventNotificationMode(
+ JVMTI_TRACE(LOG_DEBUG, err, jvmti->SetEventNotificationMode(
JVMTI_DISABLE, JVMTI_EVENT_EXCEPTION, 0));
if (err != JVMTI_ERROR_NONE) {
- throw AgentException(err);
+ AgentException ex(err);
+ JDWP_SET_EXCEPTION(ex);
+ return err;
}
+
+ return JDWP_ERROR_NONE;
}