BreakpointProbe.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeDebugPch.h"
  6. #ifdef ENABLE_SCRIPT_DEBUGGING
  7. namespace Js
  8. {
  9. BreakpointProbe::BreakpointProbe(DebugDocument* debugDocument, StatementLocation& statement, int breakpointId) :
  10. debugDocument(debugDocument),
  11. functionBody(statement.function),
  12. characterOffset(statement.statement.begin),
  13. byteOffset(statement.bytecodeSpan.begin),
  14. breakpointId(breakpointId)
  15. {
  16. }
  17. bool BreakpointProbe::Install(ScriptContext* pScriptContext)
  18. {
  19. Assert(this->functionBody);
  20. return functionBody->InstallProbe(byteOffset);
  21. }
  22. bool BreakpointProbe::Uninstall(ScriptContext* pScriptContext)
  23. {
  24. Assert(this->functionBody);
  25. if (this->functionBody)
  26. {
  27. Assert(this->debugDocument);
  28. this->debugDocument->RemoveBreakpointProbe(this);
  29. return functionBody->UninstallProbe(byteOffset);
  30. }
  31. return true;
  32. }
  33. bool BreakpointProbe::CanHalt(InterpreterHaltState* pHaltState)
  34. {
  35. Assert(this->functionBody);
  36. FunctionBody* pCurrentFuncBody = pHaltState->GetFunction();
  37. int offset = pHaltState->GetCurrentOffset();
  38. if (functionBody == pCurrentFuncBody && byteOffset == offset)
  39. {
  40. return true;
  41. }
  42. return false;
  43. }
  44. void BreakpointProbe::DispatchHalt(InterpreterHaltState* pHaltState)
  45. {
  46. Assert(false);
  47. }
  48. void BreakpointProbe::CleanupHalt()
  49. {
  50. Assert(this->functionBody);
  51. // Nothing to clean here
  52. }
  53. bool BreakpointProbe::Matches(FunctionBody* _pBody, int _characterOffset)
  54. {
  55. Assert(this->functionBody);
  56. return _pBody == functionBody && _characterOffset == characterOffset;
  57. }
  58. bool BreakpointProbe::Matches(StatementLocation statement)
  59. {
  60. return (this->GetCharacterOffset() == statement.statement.begin) && (this->byteOffset == statement.bytecodeSpan.begin);
  61. }
  62. bool BreakpointProbe::Matches(FunctionBody* _pBody, DebugDocument* debugDocument, int byteOffset)
  63. {
  64. return (this->functionBody == _pBody) && (this->debugDocument == debugDocument) && (this->byteOffset == byteOffset);
  65. }
  66. void BreakpointProbe::GetStatementLocation(StatementLocation * statement)
  67. {
  68. statement->bytecodeSpan.begin = this->byteOffset;
  69. statement->function = this->functionBody;
  70. statement->statement.begin = this->characterOffset;
  71. }
  72. }
  73. #endif