From 072d019dfc7517723bba106766b5dc830814b44b Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Mon, 5 Feb 2007 20:56:47 +0000 Subject: [PATCH] * gnu/classpath/jdwp/natVMVirtualMachine.cc (registerEvent): Implement EVENT_BREAKPOINT. (unregisterEvent): Likewise. (get_request_location): New function. From-SVN: r121608 --- libjava/ChangeLog | 7 ++ .../gnu/classpath/jdwp/natVMVirtualMachine.cc | 95 ++++++++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index a28144266dc..f94ac741f3b 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,10 @@ +2007-02-05 Keith Seitz + + * gnu/classpath/jdwp/natVMVirtualMachine.cc + (registerEvent): Implement EVENT_BREAKPOINT. + (unregisterEvent): Likewise. + (get_request_location): New function. + 2007-02-05 Matthias Klose testsuite/Makefile.am (compile-tests): Fix typo. diff --git a/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc b/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc index 3966e852fb8..208e689b79d 100644 --- a/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc +++ b/libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc @@ -10,6 +10,7 @@ details. */ #include #include +#include #include #include @@ -21,6 +22,7 @@ details. */ #include #include #include +#include #include #include @@ -29,20 +31,28 @@ details. */ #include #include #include +#include #include #include #include #include #include +#include +#include +#include #include #include +#include #include +#include +#include using namespace java::lang; using namespace gnu::classpath::jdwp::event; using namespace gnu::classpath::jdwp::util; // Forward declarations +static Location *get_request_location (EventRequest *); static void JNICALL jdwpClassPrepareCB (jvmtiEnv *, JNIEnv *, jthread, jclass); static void JNICALL jdwpThreadEndCB (jvmtiEnv *, JNIEnv *, jthread); static void JNICALL jdwpThreadStartCB (jvmtiEnv *, JNIEnv *, jthread); @@ -189,7 +199,29 @@ gnu::classpath::jdwp::VMVirtualMachine::registerEvent (EventRequest *request) break; case EventRequest::EVENT_BREAKPOINT: - break; + { + using namespace ::gnu::gcj::jvmti; + Location *loc = get_request_location (request); + if (loc == NULL) + { + using namespace gnu::classpath::jdwp::exception; + throw new InvalidLocationException (); + } + + jlong method = loc->getMethod ()->getId (); + jlocation index = loc->getIndex (); + Breakpoint *bp = BreakpointManager::getBreakpoint (method, index); + if (bp == NULL) + { + // Breakpoint not in interpreter yet + bp = BreakpointManager::newBreakpoint (method, index); + } + else + { + // Ignore the duplicate + } + } + break; case EventRequest::EVENT_FRAME_POP: break; @@ -244,6 +276,46 @@ gnu::classpath::jdwp::VMVirtualMachine::unregisterEvent (EventRequest *request) break; case EventRequest::EVENT_BREAKPOINT: + { + using namespace gnu::gcj::jvmti; + ::java::util::Collection *breakpoints; + EventManager *em = EventManager::getDefault (); + breakpoints = em->getRequests (EventRequest::EVENT_BREAKPOINT); + + // Check for duplicates + int matches = 0; + Location *the_location = get_request_location (request); + + // This should not be possible: we REQUIRE a Location + // to install a breakpoint + JvAssert (the_location != NULL); + + ::java::util::Iterator *iter = breakpoints->iterator (); + while (iter->hasNext ()) + { + EventRequest *er + = reinterpret_cast (iter->next ()); + Location *loc = get_request_location (er); + JvAssert (loc != NULL); + if (loc->equals (the_location) && ++matches == 2) + { + // Short-circuit: already more than one breakpoint + return; + } + } + + if (matches == 0) + { + using namespace gnu::classpath::jdwp::exception; + jstring msg + = JvNewStringLatin1 ("attempt to remove unknown breakpoint"); + throw new JdwpInternalErrorException (msg); + } + + jlong methodId = the_location->getMethod ()->getId (); + BreakpointManager::deleteBreakpoint (methodId, + the_location->getIndex ()); + } break; case EventRequest::EVENT_FRAME_POP: @@ -410,6 +482,27 @@ getSourceFile (MAYBE_UNUSED jclass clazz) return NULL; } +static Location * +get_request_location (EventRequest *request) +{ + Location *loc = NULL; + ::java::util::Collection *filters = request->getFilters (); + ::java::util::Iterator *iter = filters->iterator (); + while (iter->hasNext ()) + { + using namespace gnu::classpath::jdwp::event::filters; + IEventFilter *filter = (IEventFilter *) iter->next (); + if (filter->getClass () == &LocationOnlyFilter::class$) + { + LocationOnlyFilter *lof + = reinterpret_cast (filter); + loc = lof->getLocation (); + } + } + + return loc; +} + static void throw_jvmti_error (jvmtiError err) {