1 // natBreakpoint.cc - C++ side of Breakpoint
2 
3 /* Copyright (C) 2006, 2007  Free Software Foundation
4 
5    This file is part of libgcj.
6 
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10 
11 #include <config.h>
12 #include <gcj/cni.h>
13 #include <gcj/method.h>
14 #include <java-interp.h>
15 #include <java-insns.h>
16 #include <java-assert.h>
17 #include <jvmti.h>
18 
19 #include <gnu/gcj/jvmti/Breakpoint.h>
20 #include <gnu/gcj/jvmti/BreakpointManager.h>
21 
22 static _Jv_InterpMethod *
get_interp_method(jlong method)23 get_interp_method (jlong method)
24 {
25   jmethodID id = reinterpret_cast<jmethodID> (method);
26   jclass klass = _Jv_GetMethodDeclaringClass (id);
27   JvAssert (_Jv_IsInterpretedClass (klass));
28   _Jv_MethodBase *base
29     = _Jv_FindInterpreterMethod (klass, id);
30   JvAssert (base != NULL);
31   return reinterpret_cast<_Jv_InterpMethod *> (base);
32 }
33 
34 void
_save_insn()35 gnu::gcj::jvmti::Breakpoint::_save_insn ()
36 {
37   _Jv_InterpMethod *imeth = get_interp_method (method);
38 
39   // copy contents of insn at location into data
40   pc_t code = imeth->get_insn (location);
41   data = (RawDataManaged *) JvAllocBytes (sizeof (*code));
42   memcpy (data, code, sizeof (*code));
43 }
44 
45 void
install()46 gnu::gcj::jvmti::Breakpoint::install ()
47 {
48   _save_insn ();
49   _Jv_InterpMethod *imeth = get_interp_method (method);
50   imeth->install_break (location);
51 }
52 
53 void
remove()54 gnu::gcj::jvmti::Breakpoint::remove ()
55 {
56   _Jv_InterpMethod *imeth = get_interp_method (method);
57   imeth->set_insn (location, reinterpret_cast<pc_t> (data));
58 }
59 
60 #ifdef DIRECT_THREADED
61 void
_Jv_RewriteBreakpointInsn(jmethodID mid,jlocation loc,pc_t new_insn)62 _Jv_RewriteBreakpointInsn (jmethodID mid, jlocation loc, pc_t new_insn)
63 {
64   using namespace ::gnu::gcj::jvmti;
65   Breakpoint *bp
66     = BreakpointManager::getBreakpoint (reinterpret_cast<jlong> (mid), loc);
67   if (bp != NULL)
68     {
69       pc_t old_insn = (pc_t) bp->data;
70       old_insn->insn = new_insn;
71     }
72 }
73 #endif // DIRECT_THREADED
74