natBreakpoint.cc 1.8 KB

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