1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_TOOLING_BASE_PT_EVENTS_H 17 #define ECMASCRIPT_TOOLING_BASE_PT_EVENTS_H 18 19 #include <memory> 20 #include <optional> 21 22 #include "ecmascript/dfx/tracing/tracing.h" 23 #include "tooling/dynamic/base/pt_script.h" 24 #include "tooling/dynamic/base/pt_types.h" 25 #include "dispatcher.h" 26 27 #include "libpandabase/macros.h" 28 29 namespace panda::ecmascript::tooling { 30 class PtBaseEvents : public PtBaseTypes { 31 public: 32 PtBaseEvents() = default; 33 ~PtBaseEvents() override = default; 34 virtual std::string GetName() const = 0; 35 36 private: 37 NO_COPY_SEMANTIC(PtBaseEvents); 38 NO_MOVE_SEMANTIC(PtBaseEvents); 39 }; 40 41 class BreakpointResolved final : public PtBaseEvents { 42 public: 43 BreakpointResolved() = default; 44 ~BreakpointResolved() override = default; 45 std::unique_ptr<PtJson> ToJson() const override; 46 GetName()47 std::string GetName() const override 48 { 49 return "Debugger.breakpointResolved"; 50 } 51 GetBreakpointId()52 BreakpointId GetBreakpointId() const 53 { 54 return breakpointId_; 55 } 56 SetBreakpointId(const BreakpointId & breakpointId)57 BreakpointResolved &SetBreakpointId(const BreakpointId &breakpointId) 58 { 59 breakpointId_ = breakpointId; 60 return *this; 61 } 62 GetLocation()63 Location *GetLocation() const 64 { 65 return location_.get(); 66 } 67 SetLocation(std::unique_ptr<Location> location)68 BreakpointResolved &SetLocation(std::unique_ptr<Location> location) 69 { 70 location_ = std::move(location); 71 return *this; 72 } 73 74 private: 75 NO_COPY_SEMANTIC(BreakpointResolved); 76 NO_MOVE_SEMANTIC(BreakpointResolved); 77 78 BreakpointId breakpointId_ {}; 79 std::unique_ptr<Location> location_ {nullptr}; 80 }; 81 82 class Paused final : public PtBaseEvents { 83 public: 84 Paused() = default; 85 ~Paused() override = default; 86 std::unique_ptr<PtJson> ToJson() const override; 87 std::unique_ptr<PtJson> ToJson(StackFrame stackFrame) const; 88 std::unique_ptr<PtJson> ToJson(AsyncStack asyncStack, int32_t asyncCallChainDepth) const; 89 GetName()90 std::string GetName() const override 91 { 92 return "Debugger.paused"; 93 } 94 GetCallFrames()95 const std::vector<std::unique_ptr<CallFrame>> *GetCallFrames() const 96 { 97 return &callFrames_; 98 } 99 GetAsyncStack()100 const std::shared_ptr<AsyncStack> *GetAsyncStack() const 101 { 102 return &asyncStack_; 103 } 104 SetAysncStack(std::shared_ptr<AsyncStack> AsyncStack)105 Paused &SetAysncStack(std::shared_ptr<AsyncStack> AsyncStack) 106 { 107 asyncStack_ = std::move(AsyncStack); 108 return *this; 109 } 110 SetCallFrames(std::vector<std::unique_ptr<CallFrame>> callFrames)111 Paused &SetCallFrames(std::vector<std::unique_ptr<CallFrame>> callFrames) 112 { 113 callFrames_ = std::move(callFrames); 114 return *this; 115 } 116 GetReason()117 const std::string &GetReason() const 118 { 119 return reason_; 120 } 121 SetReason(PauseReason reason)122 Paused &SetReason(PauseReason reason) 123 { 124 reason_ = GetReasonString(reason); 125 return *this; 126 } 127 GetReasonString(PauseReason reason)128 static std::string GetReasonString(PauseReason reason) 129 { 130 switch (reason) { 131 case AMBIGUOUS: { 132 return "ambiguous"; 133 } 134 case ASSERT: { 135 return "assert"; 136 } 137 case DEBUGCOMMAND: { 138 return "debugCommand"; 139 } 140 case DOM: { 141 return "DOM"; 142 } 143 case EVENTLISTENER: { 144 return "EventListener"; 145 } 146 case EXCEPTION: { 147 return "exception"; 148 } 149 case INSTRUMENTATION: { 150 return "instrumentation"; 151 } 152 case OOM: { 153 return "OOM"; 154 } 155 case OTHER: { 156 return "other"; 157 } 158 case PROMISEREJECTION: { 159 return "promiseRejection"; 160 } 161 case XHR: { 162 return "XHR"; 163 } 164 case BREAK_ON_START: { 165 return "Break on start"; 166 } 167 case DEBUGGERSTMT: { 168 return "Debugger statement"; 169 } 170 case STEP: { 171 return "Step"; 172 } 173 case NATIVE_OUT: { 174 return "Native out"; 175 } 176 case SYMBOL: { 177 return "Symbol"; 178 } 179 default: { 180 LOG_DEBUGGER(ERROR) << "Unknown paused reason: " << reason; 181 } 182 } 183 return ""; 184 } 185 GetData()186 RemoteObject *GetData() const 187 { 188 if (data_) { 189 return data_->get(); 190 } 191 return nullptr; 192 } 193 SetData(std::unique_ptr<RemoteObject> data)194 Paused &SetData(std::unique_ptr<RemoteObject> data) 195 { 196 data_ = std::move(data); 197 return *this; 198 } 199 HasData()200 bool HasData() const 201 { 202 return data_.has_value(); 203 } 204 SetAsyncCallChainDepth(int32_t asyncCallChainDepth)205 Paused &SetAsyncCallChainDepth(int32_t asyncCallChainDepth) 206 { 207 asyncCallChainDepth_ = asyncCallChainDepth; 208 return *this; 209 } 210 GetAsyncCallChainDepth()211 int32_t GetAsyncCallChainDepth() const 212 { 213 return asyncCallChainDepth_; 214 } 215 GetHitBreakpoints()216 std::vector<BreakpointId> GetHitBreakpoints() const 217 { 218 return hitBreakpoints_.value_or(std::vector<BreakpointId>()); 219 } 220 SetHitBreakpoints(std::vector<BreakpointId> hitBreakpoints)221 Paused &SetHitBreakpoints(std::vector<BreakpointId> hitBreakpoints) 222 { 223 hitBreakpoints_ = std::move(hitBreakpoints); 224 return *this; 225 } 226 HasHitBreakpoints()227 bool HasHitBreakpoints() const 228 { 229 return hitBreakpoints_.has_value(); 230 } 231 232 private: 233 NO_COPY_SEMANTIC(Paused); 234 NO_MOVE_SEMANTIC(Paused); 235 236 std::vector<std::unique_ptr<CallFrame>> callFrames_ {}; 237 std::shared_ptr<AsyncStack> asyncStack_ {}; 238 std::string reason_ {}; 239 std::optional<std::unique_ptr<RemoteObject>> data_ {}; 240 std::optional<std::vector<BreakpointId>> hitBreakpoints_ {}; 241 int32_t asyncCallChainDepth_ {0}; 242 }; 243 244 class Resumed final : public PtBaseEvents { 245 public: 246 Resumed() = default; 247 ~Resumed() override = default; 248 std::unique_ptr<PtJson> ToJson() const override; 249 GetName()250 std::string GetName() const override 251 { 252 return "Debugger.resumed"; 253 } 254 255 private: 256 NO_COPY_SEMANTIC(Resumed); 257 NO_MOVE_SEMANTIC(Resumed); 258 }; 259 260 class NativeCalling final : public PtBaseEvents { 261 public: 262 NativeCalling() = default; 263 ~NativeCalling() override = default; 264 std::unique_ptr<PtJson> ToJson() const override; 265 GetName()266 std::string GetName() const override 267 { 268 return "Debugger.nativeCalling"; 269 } 270 GetNativeAddress()271 const void *GetNativeAddress() const 272 { 273 return nativeAddress_; 274 } 275 GetIntoStatus()276 bool GetIntoStatus() const 277 { 278 return isStepInto_.value_or(false); 279 } 280 SetNativeAddress(const void * nativeAddress)281 NativeCalling &SetNativeAddress(const void *nativeAddress) 282 { 283 nativeAddress_ = nativeAddress; 284 return *this; 285 } 286 SetIntoStatus(bool isStepInto)287 NativeCalling &SetIntoStatus(bool isStepInto) 288 { 289 isStepInto_ = isStepInto; 290 return *this; 291 } 292 293 private: 294 NO_COPY_SEMANTIC(NativeCalling); 295 NO_MOVE_SEMANTIC(NativeCalling); 296 297 const void *nativeAddress_ {nullptr}; 298 std::optional<bool> isStepInto_ {}; 299 }; 300 301 class MixedStack final : public PtBaseEvents { 302 public: 303 MixedStack() = default; 304 ~MixedStack() override = default; 305 std::unique_ptr<PtJson> ToJson() const override; 306 GetName()307 std::string GetName() const override 308 { 309 return "Debugger.mixedStack"; 310 } 311 GetCallFrames()312 const std::vector<std::unique_ptr<CallFrame>> *GetCallFrames() const 313 { 314 return &callFrames_; 315 } 316 GetNativePointers()317 const std::vector<void *> *GetNativePointers() const 318 { 319 return &nativePointer_; 320 } 321 SetCallFrames(std::vector<std::unique_ptr<CallFrame>> callFrames)322 MixedStack &SetCallFrames(std::vector<std::unique_ptr<CallFrame>> callFrames) 323 { 324 callFrames_ = std::move(callFrames); 325 return *this; 326 } 327 SetNativePointers(std::vector<void * > nativePointer)328 MixedStack &SetNativePointers(std::vector<void *> nativePointer) 329 { 330 nativePointer_ = std::move(nativePointer); 331 return *this; 332 } 333 334 private: 335 NO_COPY_SEMANTIC(MixedStack); 336 NO_MOVE_SEMANTIC(MixedStack); 337 338 std::vector<void *> nativePointer_ {}; 339 std::vector<std::unique_ptr<CallFrame>> callFrames_ {}; 340 }; 341 342 class ScriptFailedToParse final : public PtBaseEvents { 343 public: 344 ScriptFailedToParse() = default; 345 ~ScriptFailedToParse() override = default; 346 std::unique_ptr<PtJson> ToJson() const override; 347 GetName()348 std::string GetName() const override 349 { 350 return "Debugger.scriptFailedToParse"; 351 } 352 GetScriptId()353 ScriptId GetScriptId() const 354 { 355 return scriptId_; 356 } 357 SetScriptId(ScriptId scriptId)358 ScriptFailedToParse &SetScriptId(ScriptId scriptId) 359 { 360 scriptId_ = scriptId; 361 return *this; 362 } 363 GetUrl()364 const std::string &GetUrl() const 365 { 366 return url_; 367 } 368 SetUrl(const std::string & url)369 ScriptFailedToParse &SetUrl(const std::string &url) 370 { 371 url_ = url; 372 return *this; 373 } 374 GetStartLine()375 int32_t GetStartLine() const 376 { 377 return startLine_; 378 } 379 SetStartLine(int32_t startLine)380 ScriptFailedToParse &SetStartLine(int32_t startLine) 381 { 382 startLine_ = startLine; 383 return *this; 384 } 385 GetStartColumn()386 int32_t GetStartColumn() const 387 { 388 return startColumn_; 389 } 390 SetStartColumn(int32_t startColumn)391 ScriptFailedToParse &SetStartColumn(int32_t startColumn) 392 { 393 startColumn_ = startColumn; 394 return *this; 395 } 396 GetEndLine()397 int32_t GetEndLine() const 398 { 399 return endLine_; 400 } 401 SetEndLine(int32_t endLine)402 ScriptFailedToParse &SetEndLine(int32_t endLine) 403 { 404 endLine_ = endLine; 405 return *this; 406 } 407 GetEndColumn()408 int32_t GetEndColumn() const 409 { 410 return endColumn_; 411 } 412 SetEndColumn(int32_t endColumn)413 ScriptFailedToParse &SetEndColumn(int32_t endColumn) 414 { 415 endColumn_ = endColumn; 416 return *this; 417 } 418 GetExecutionContextId()419 int32_t GetExecutionContextId() const 420 { 421 return executionContextId_; 422 } 423 SetExecutionContextId(int32_t executionContextId)424 ScriptFailedToParse &SetExecutionContextId(int32_t executionContextId) 425 { 426 executionContextId_ = executionContextId; 427 return *this; 428 } 429 GetHash()430 const std::string &GetHash() const 431 { 432 return hash_; 433 } 434 SetHash(const std::string & hash)435 ScriptFailedToParse &SetHash(const std::string &hash) 436 { 437 hash_ = hash; 438 return *this; 439 } 440 GetExecutionContextAuxData()441 Local<ObjectRef> GetExecutionContextAuxData() const 442 { 443 return execContextAuxData_.value_or(Local<ObjectRef>()); 444 } 445 SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData)446 ScriptFailedToParse &SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData) 447 { 448 execContextAuxData_ = execContextAuxData; 449 return *this; 450 } 451 HasExecutionContextAuxData()452 bool HasExecutionContextAuxData() const 453 { 454 return execContextAuxData_.has_value(); 455 } 456 GetSourceMapURL()457 const std::string &GetSourceMapURL() const 458 { 459 ASSERT(HasSourceMapUrl()); 460 return sourceMapUrl_.value(); 461 } 462 SetSourceMapURL(const std::string & sourceMapUrl)463 ScriptFailedToParse &SetSourceMapURL(const std::string &sourceMapUrl) 464 { 465 sourceMapUrl_ = sourceMapUrl; 466 return *this; 467 } 468 HasSourceMapUrl()469 bool HasSourceMapUrl() const 470 { 471 return sourceMapUrl_.has_value(); 472 } 473 GetHasSourceURL()474 bool GetHasSourceURL() const 475 { 476 return hasSourceUrl_.value_or(false); 477 } 478 SetHasSourceURL(bool hasSourceUrl)479 ScriptFailedToParse &SetHasSourceURL(bool hasSourceUrl) 480 { 481 hasSourceUrl_ = hasSourceUrl; 482 return *this; 483 } 484 HasHasSourceURL()485 bool HasHasSourceURL() const 486 { 487 return hasSourceUrl_.has_value(); 488 } 489 GetIsModule()490 bool GetIsModule() const 491 { 492 return isModule_.value_or(false); 493 } 494 SetIsModule(bool isModule)495 ScriptFailedToParse &SetIsModule(bool isModule) 496 { 497 isModule_ = isModule; 498 return *this; 499 } 500 HasIsModule()501 bool HasIsModule() const 502 { 503 return isModule_.has_value(); 504 } 505 GetLength()506 int32_t GetLength() const 507 { 508 return length_.value_or(0); 509 } 510 SetLength(int32_t length)511 ScriptFailedToParse &SetLength(int32_t length) 512 { 513 length_ = length; 514 return *this; 515 } 516 HasLength()517 bool HasLength() const 518 { 519 return length_.has_value(); 520 } 521 GetCodeOffset()522 int32_t GetCodeOffset() const 523 { 524 return codeOffset_.value_or(0); 525 } 526 SetCodeOffset(int32_t codeOffset)527 ScriptFailedToParse &SetCodeOffset(int32_t codeOffset) 528 { 529 codeOffset_ = codeOffset; 530 return *this; 531 } 532 HasCodeOffset()533 bool HasCodeOffset() const 534 { 535 return codeOffset_.has_value(); 536 } 537 GetScriptLanguage()538 const std::string &GetScriptLanguage() const 539 { 540 ASSERT(HasScriptLanguage()); 541 return scriptLanguage_.value(); 542 } 543 SetScriptLanguage(const std::string & scriptLanguage)544 ScriptFailedToParse &SetScriptLanguage(const std::string &scriptLanguage) 545 { 546 scriptLanguage_ = scriptLanguage; 547 return *this; 548 } 549 HasScriptLanguage()550 bool HasScriptLanguage() const 551 { 552 return scriptLanguage_.has_value(); 553 } 554 GetEmbedderName()555 const std::string &GetEmbedderName() const 556 { 557 ASSERT(HasEmbedderName()); 558 return embedderName_.value(); 559 } 560 SetEmbedderName(const std::string & embedderName)561 ScriptFailedToParse &SetEmbedderName(const std::string &embedderName) 562 { 563 embedderName_ = embedderName; 564 return *this; 565 } 566 HasEmbedderName()567 bool HasEmbedderName() const 568 { 569 return embedderName_.has_value(); 570 } 571 572 private: 573 NO_COPY_SEMANTIC(ScriptFailedToParse); 574 NO_MOVE_SEMANTIC(ScriptFailedToParse); 575 576 ScriptId scriptId_ {0}; 577 std::string url_ {}; 578 int32_t startLine_ {0}; 579 int32_t startColumn_ {0}; 580 int32_t endLine_ {0}; 581 int32_t endColumn_ {0}; 582 ExecutionContextId executionContextId_ {0}; 583 std::string hash_ {}; 584 std::optional<Local<ObjectRef>> execContextAuxData_ {}; 585 std::optional<std::string> sourceMapUrl_ {}; 586 std::optional<bool> hasSourceUrl_ {}; 587 std::optional<bool> isModule_ {}; 588 std::optional<int32_t> length_ {}; 589 std::optional<int32_t> codeOffset_ {}; 590 std::optional<std::string> scriptLanguage_ {}; 591 std::optional<std::string> embedderName_ {}; 592 }; 593 594 class ScriptParsed final : public PtBaseEvents { 595 public: 596 ScriptParsed() = default; 597 ~ScriptParsed() override = default; 598 std::unique_ptr<PtJson> ToJson() const override; 599 GetName()600 std::string GetName() const override 601 { 602 return "Debugger.scriptParsed"; 603 } 604 GetScriptId()605 ScriptId GetScriptId() const 606 { 607 return scriptId_; 608 } 609 SetScriptId(ScriptId scriptId)610 ScriptParsed &SetScriptId(ScriptId scriptId) 611 { 612 scriptId_ = scriptId; 613 return *this; 614 } 615 GetUrl()616 const std::string &GetUrl() const 617 { 618 return url_; 619 } 620 SetUrl(const std::string & url)621 ScriptParsed &SetUrl(const std::string &url) 622 { 623 url_ = url; 624 return *this; 625 } 626 GetStartLine()627 int32_t GetStartLine() const 628 { 629 return startLine_; 630 } 631 SetStartLine(int32_t startLine)632 ScriptParsed &SetStartLine(int32_t startLine) 633 { 634 startLine_ = startLine; 635 return *this; 636 } 637 GetStartColumn()638 int32_t GetStartColumn() const 639 { 640 return startColumn_; 641 } 642 SetStartColumn(int32_t startColumn)643 ScriptParsed &SetStartColumn(int32_t startColumn) 644 { 645 startColumn_ = startColumn; 646 return *this; 647 } 648 GetEndLine()649 int32_t GetEndLine() const 650 { 651 return endLine_; 652 } 653 SetEndLine(int32_t endLine)654 ScriptParsed &SetEndLine(int32_t endLine) 655 { 656 endLine_ = endLine; 657 return *this; 658 } 659 GetEndColumn()660 int32_t GetEndColumn() const 661 { 662 return endColumn_; 663 } 664 SetEndColumn(int32_t endColumn)665 ScriptParsed &SetEndColumn(int32_t endColumn) 666 { 667 endColumn_ = endColumn; 668 return *this; 669 } 670 GetExecutionContextId()671 int32_t GetExecutionContextId() const 672 { 673 return executionContextId_; 674 } 675 SetExecutionContextId(int32_t executionContextId)676 ScriptParsed &SetExecutionContextId(int32_t executionContextId) 677 { 678 executionContextId_ = executionContextId; 679 return *this; 680 } 681 GetHash()682 const std::string &GetHash() const 683 { 684 return hash_; 685 } 686 SetHash(const std::string & hash)687 ScriptParsed &SetHash(const std::string &hash) 688 { 689 hash_ = hash; 690 return *this; 691 } 692 GetIsLiveEdit()693 bool GetIsLiveEdit() const 694 { 695 return isLiveEdit_.value_or(false); 696 } 697 SetIsLiveEdit(bool isLiveEdit)698 ScriptParsed &SetIsLiveEdit(bool isLiveEdit) 699 { 700 isLiveEdit_ = isLiveEdit; 701 return *this; 702 } 703 HasIsLiveEdit()704 bool HasIsLiveEdit() const 705 { 706 return isLiveEdit_.has_value(); 707 } 708 GetExecutionContextAuxData()709 Local<ObjectRef> GetExecutionContextAuxData() const 710 { 711 return execContextAuxData_.value_or(Local<ObjectRef>()); 712 } 713 SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData)714 ScriptParsed &SetExecutionContextAuxData(Local<ObjectRef> execContextAuxData) 715 { 716 execContextAuxData_ = execContextAuxData; 717 return *this; 718 } 719 HasExecutionContextAuxData()720 bool HasExecutionContextAuxData() const 721 { 722 return execContextAuxData_.has_value(); 723 } 724 GetSourceMapURL()725 const std::string &GetSourceMapURL() const 726 { 727 ASSERT(HasSourceMapUrl()); 728 return sourceMapUrl_.value(); 729 } 730 SetSourceMapURL(const std::string & sourceMapUrl)731 ScriptParsed &SetSourceMapURL(const std::string &sourceMapUrl) 732 { 733 sourceMapUrl_ = sourceMapUrl; 734 return *this; 735 } 736 HasSourceMapUrl()737 bool HasSourceMapUrl() const 738 { 739 return sourceMapUrl_.has_value(); 740 } 741 GetHasSourceURL()742 bool GetHasSourceURL() const 743 { 744 return hasSourceUrl_.value_or(false); 745 } 746 SetHasSourceURL(bool hasSourceUrl)747 ScriptParsed &SetHasSourceURL(bool hasSourceUrl) 748 { 749 hasSourceUrl_ = hasSourceUrl; 750 return *this; 751 } 752 HasHasSourceURL()753 bool HasHasSourceURL() const 754 { 755 return hasSourceUrl_.has_value(); 756 } 757 GetIsModule()758 bool GetIsModule() const 759 { 760 return isModule_.value_or(false); 761 } 762 SetIsModule(bool isModule)763 ScriptParsed &SetIsModule(bool isModule) 764 { 765 isModule_ = isModule; 766 return *this; 767 } 768 HasIsModule()769 bool HasIsModule() const 770 { 771 return isModule_.has_value(); 772 } 773 GetLength()774 int32_t GetLength() const 775 { 776 return length_.value_or(0); 777 } 778 SetLength(int32_t length)779 ScriptParsed &SetLength(int32_t length) 780 { 781 length_ = length; 782 return *this; 783 } 784 HasLength()785 bool HasLength() const 786 { 787 return length_.has_value(); 788 } 789 GetCodeOffset()790 int32_t GetCodeOffset() const 791 { 792 return codeOffset_.value_or(0); 793 } 794 SetCodeOffset(int32_t codeOffset)795 ScriptParsed &SetCodeOffset(int32_t codeOffset) 796 { 797 codeOffset_ = codeOffset; 798 return *this; 799 } 800 HasCodeOffset()801 bool HasCodeOffset() const 802 { 803 return codeOffset_.has_value(); 804 } 805 GetScriptLanguage()806 const std::string &GetScriptLanguage() const 807 { 808 ASSERT(HasScriptLanguage()); 809 return scriptLanguage_.value(); 810 } 811 SetScriptLanguage(const std::string & scriptLanguage)812 ScriptParsed &SetScriptLanguage(const std::string &scriptLanguage) 813 { 814 scriptLanguage_ = scriptLanguage; 815 return *this; 816 } 817 HasScriptLanguage()818 bool HasScriptLanguage() const 819 { 820 return scriptLanguage_.has_value(); 821 } 822 GetEmbedderName()823 const std::string &GetEmbedderName() const 824 { 825 ASSERT(HasEmbedderName()); 826 return embedderName_.value(); 827 } 828 SetEmbedderName(const std::string & embedderName)829 ScriptParsed &SetEmbedderName(const std::string &embedderName) 830 { 831 embedderName_ = embedderName; 832 return *this; 833 } 834 HasEmbedderName()835 bool HasEmbedderName() const 836 { 837 return embedderName_.has_value(); 838 } 839 SetLocations(std::vector<std::shared_ptr<BreakpointReturnInfo>> locations)840 ScriptParsed &SetLocations(std::vector<std::shared_ptr<BreakpointReturnInfo>> locations) 841 { 842 locations_ = locations; 843 return *this; 844 } 845 846 private: 847 NO_COPY_SEMANTIC(ScriptParsed); 848 NO_MOVE_SEMANTIC(ScriptParsed); 849 850 ScriptId scriptId_ {0}; 851 std::string url_ {}; 852 int32_t startLine_ {0}; 853 int32_t startColumn_ {0}; 854 int32_t endLine_ {0}; 855 int32_t endColumn_ {0}; 856 ExecutionContextId executionContextId_ {0}; 857 std::string hash_ {}; 858 std::optional<Local<ObjectRef>> execContextAuxData_ {}; 859 std::optional<bool> isLiveEdit_ {}; 860 std::optional<std::string> sourceMapUrl_ {}; 861 std::optional<bool> hasSourceUrl_ {}; 862 std::optional<bool> isModule_ {}; 863 std::optional<int32_t> length_ {}; 864 std::optional<int32_t> codeOffset_ {}; 865 std::optional<std::string> scriptLanguage_ {}; 866 std::optional<std::string> embedderName_ {}; 867 std::vector<std::shared_ptr<BreakpointReturnInfo>> locations_ {}; 868 }; 869 870 class AddHeapSnapshotChunk final : public PtBaseEvents { 871 public: 872 AddHeapSnapshotChunk() = default; 873 ~AddHeapSnapshotChunk() override = default; 874 std::unique_ptr<PtJson> ToJson() const override; 875 GetName()876 std::string GetName() const override 877 { 878 return "HeapProfiler.addHeapSnapshotChunk"; 879 } 880 SetChunk(const std::string & chunk)881 AddHeapSnapshotChunk &SetChunk(const std::string &chunk) 882 { 883 chunk_ = chunk; 884 return *this; 885 } 886 GetChunk()887 std::string &GetChunk() 888 { 889 return chunk_; 890 } 891 892 private: 893 NO_COPY_SEMANTIC(AddHeapSnapshotChunk); 894 NO_MOVE_SEMANTIC(AddHeapSnapshotChunk); 895 896 std::string chunk_ {}; 897 }; 898 899 class ConsoleProfileFinished final : public PtBaseEvents { 900 public: 901 ConsoleProfileFinished() = default; 902 ~ConsoleProfileFinished() override = default; 903 std::unique_ptr<PtJson> ToJson() const override; GetName()904 std::string GetName() const override 905 { 906 return "Profile.ConsoleProfileFinished"; 907 } 908 GetId()909 const std::string &GetId() const 910 { 911 return id_; 912 } 913 SetId(const std::string & id)914 ConsoleProfileFinished &SetId(const std::string &id) 915 { 916 id_ = id; 917 return *this; 918 } 919 GetLocation()920 Location *GetLocation() const 921 { 922 return location_.get(); 923 } 924 SetLocation(std::unique_ptr<Location> location)925 ConsoleProfileFinished &SetLocation(std::unique_ptr<Location> location) 926 { 927 location_ = std::move(location); 928 return *this; 929 } 930 GetProfile()931 Profile *GetProfile() const 932 { 933 return profile_.get(); 934 } 935 SetProfile(std::unique_ptr<Profile> profile)936 ConsoleProfileFinished &SetProfile(std::unique_ptr<Profile> profile) 937 { 938 profile_ = std::move(profile); 939 return *this; 940 } 941 GetTitle()942 const std::string &GetTitle() const 943 { 944 ASSERT(HasTitle()); 945 return title_.value(); 946 } 947 SetTitle(const std::string & title)948 ConsoleProfileFinished &SetTitle(const std::string &title) 949 { 950 title_ = title; 951 return *this; 952 } 953 HasTitle()954 bool HasTitle() const 955 { 956 return title_.has_value(); 957 } 958 959 private: 960 NO_COPY_SEMANTIC(ConsoleProfileFinished); 961 NO_MOVE_SEMANTIC(ConsoleProfileFinished); 962 963 std::string id_ {}; 964 std::unique_ptr<Location> location_ {nullptr}; 965 std::unique_ptr<Profile> profile_ {nullptr}; 966 std::optional<std::string> title_ {}; 967 }; 968 969 class ConsoleProfileStarted final : public PtBaseEvents { 970 public: 971 ConsoleProfileStarted() = default; 972 ~ConsoleProfileStarted() override = default; 973 std::unique_ptr<PtJson> ToJson() const override; GetName()974 std::string GetName() const override 975 { 976 return "Profile.ConsoleProfileStarted"; 977 } 978 GetId()979 const std::string &GetId() const 980 { 981 return id_; 982 } 983 SetId(const std::string & id)984 ConsoleProfileStarted &SetId(const std::string &id) 985 { 986 id_ = id; 987 return *this; 988 } 989 GetLocation()990 Location *GetLocation() const 991 { 992 return location_.get(); 993 } 994 SetLocation(std::unique_ptr<Location> location)995 ConsoleProfileStarted &SetLocation(std::unique_ptr<Location> location) 996 { 997 location_ = std::move(location); 998 return *this; 999 } 1000 GetTitle()1001 const std::string &GetTitle() const 1002 { 1003 ASSERT(HasTitle()); 1004 return title_.value(); 1005 } 1006 SetTitle(const std::string & title)1007 ConsoleProfileStarted &SetTitle(const std::string &title) 1008 { 1009 title_ = title; 1010 return *this; 1011 } 1012 HasTitle()1013 bool HasTitle() const 1014 { 1015 return title_.has_value(); 1016 } 1017 1018 private: 1019 NO_COPY_SEMANTIC(ConsoleProfileStarted); 1020 NO_MOVE_SEMANTIC(ConsoleProfileStarted); 1021 1022 std::string id_ {}; 1023 std::unique_ptr<Location> location_ {nullptr}; 1024 std::optional<std::string> title_ {}; 1025 }; 1026 1027 class PreciseCoverageDeltaUpdate final : public PtBaseEvents { 1028 public: 1029 PreciseCoverageDeltaUpdate() = default; 1030 ~PreciseCoverageDeltaUpdate() override = default; 1031 std::unique_ptr<PtJson> ToJson() const override; GetName()1032 std::string GetName() const override 1033 { 1034 return "Profile.PreciseCoverageDeltaUpdate"; 1035 } 1036 GetTimestamp()1037 int64_t GetTimestamp() const 1038 { 1039 return timestamp_; 1040 } 1041 SetTimestamp(int64_t timestamp)1042 PreciseCoverageDeltaUpdate &SetTimestamp(int64_t timestamp) 1043 { 1044 timestamp_ = timestamp; 1045 return *this; 1046 } 1047 GetOccasion()1048 const std::string &GetOccasion() const 1049 { 1050 return occasion_; 1051 } 1052 SetOccasion(const std::string & occasion)1053 PreciseCoverageDeltaUpdate &SetOccasion(const std::string &occasion) 1054 { 1055 occasion_ = occasion; 1056 return *this; 1057 } 1058 GetResult()1059 const std::vector<std::unique_ptr<ScriptCoverage>> *GetResult() const 1060 { 1061 return &result_; 1062 } 1063 SetResult(std::vector<std::unique_ptr<ScriptCoverage>> result)1064 PreciseCoverageDeltaUpdate &SetResult(std::vector<std::unique_ptr<ScriptCoverage>> result) 1065 { 1066 result_ = std::move(result); 1067 return *this; 1068 } 1069 1070 private: 1071 NO_COPY_SEMANTIC(PreciseCoverageDeltaUpdate); 1072 NO_MOVE_SEMANTIC(PreciseCoverageDeltaUpdate); 1073 1074 int64_t timestamp_ {0}; 1075 std::string occasion_ {}; 1076 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 1077 }; 1078 1079 class HeapStatsUpdate final : public PtBaseEvents { 1080 public: 1081 HeapStatsUpdate() = default; 1082 ~HeapStatsUpdate() override = default; 1083 std::unique_ptr<PtJson> ToJson() const override; 1084 GetName()1085 std::string GetName() const override 1086 { 1087 return "HeapProfiler.heapStatsUpdate"; 1088 } 1089 GetStatsUpdate()1090 const std::vector<int32_t> *GetStatsUpdate() const 1091 { 1092 return &statsUpdate_; 1093 } 1094 SetStatsUpdate(std::vector<int32_t> statsUpdate)1095 HeapStatsUpdate &SetStatsUpdate(std::vector<int32_t> statsUpdate) 1096 { 1097 statsUpdate_ = std::move(statsUpdate); 1098 return *this; 1099 } 1100 1101 private: 1102 NO_COPY_SEMANTIC(HeapStatsUpdate); 1103 NO_MOVE_SEMANTIC(HeapStatsUpdate); 1104 1105 std::vector<int32_t> statsUpdate_ {}; 1106 }; 1107 1108 class LastSeenObjectId final : public PtBaseEvents { 1109 public: 1110 LastSeenObjectId() = default; 1111 ~LastSeenObjectId() override = default; 1112 std::unique_ptr<PtJson> ToJson() const override; 1113 GetName()1114 std::string GetName() const override 1115 { 1116 return "HeapProfiler.lastSeenObjectId"; 1117 } 1118 GetLastSeenObjectId()1119 int32_t GetLastSeenObjectId() const 1120 { 1121 return lastSeenObjectId_; 1122 } 1123 SetLastSeenObjectId(int32_t lastSeenObjectId)1124 LastSeenObjectId &SetLastSeenObjectId(int32_t lastSeenObjectId) 1125 { 1126 lastSeenObjectId_ = lastSeenObjectId; 1127 return *this; 1128 } 1129 GetTimestamp()1130 double GetTimestamp() const 1131 { 1132 return timestamp_; 1133 } 1134 SetTimestamp(double timestamp)1135 LastSeenObjectId &SetTimestamp(double timestamp) 1136 { 1137 timestamp_ = timestamp; 1138 return *this; 1139 } 1140 1141 private: 1142 NO_COPY_SEMANTIC(LastSeenObjectId); 1143 NO_MOVE_SEMANTIC(LastSeenObjectId); 1144 1145 int32_t lastSeenObjectId_ {}; 1146 double timestamp_ {}; 1147 }; 1148 1149 class ReportHeapSnapshotProgress final : public PtBaseEvents { 1150 public: 1151 ReportHeapSnapshotProgress() = default; 1152 ~ReportHeapSnapshotProgress() override = default; 1153 std::unique_ptr<PtJson> ToJson() const override; 1154 GetName()1155 std::string GetName() const override 1156 { 1157 return "HeapProfiler.reportHeapSnapshotProgress"; 1158 } 1159 GetDone()1160 int32_t GetDone() const 1161 { 1162 return done_; 1163 } 1164 SetDone(int32_t done)1165 ReportHeapSnapshotProgress &SetDone(int32_t done) 1166 { 1167 done_ = done; 1168 return *this; 1169 } 1170 GetTotal()1171 int32_t GetTotal() const 1172 { 1173 return total_; 1174 } 1175 SetTotal(int32_t total)1176 ReportHeapSnapshotProgress &SetTotal(int32_t total) 1177 { 1178 total_ = total; 1179 return *this; 1180 } 1181 GetFinished()1182 bool GetFinished() const 1183 { 1184 return finished_.value_or(false); 1185 } 1186 SetFinished(bool finished)1187 ReportHeapSnapshotProgress &SetFinished(bool finished) 1188 { 1189 finished_ = finished; 1190 return *this; 1191 } 1192 1193 private: 1194 NO_COPY_SEMANTIC(ReportHeapSnapshotProgress); 1195 NO_MOVE_SEMANTIC(ReportHeapSnapshotProgress); 1196 1197 int32_t done_ {}; 1198 int32_t total_ {}; 1199 std::optional<bool> finished_ {}; 1200 }; 1201 1202 class BufferUsage final : public PtBaseEvents { 1203 public: 1204 BufferUsage() = default; 1205 ~BufferUsage() override = default; 1206 std::unique_ptr<PtJson> ToJson() const override; 1207 GetName()1208 std::string GetName() const override 1209 { 1210 return "Tracing.bufferUsage"; 1211 } 1212 GetPercentFull()1213 double GetPercentFull() const 1214 { 1215 return percentFull_.value(); 1216 } 1217 SetPercentFull(double percentFull)1218 BufferUsage &SetPercentFull(double percentFull) 1219 { 1220 percentFull_ = percentFull; 1221 return *this; 1222 } 1223 HasPercentFull()1224 bool HasPercentFull() const 1225 { 1226 return percentFull_.has_value(); 1227 } 1228 GetEventCount()1229 int32_t GetEventCount() const 1230 { 1231 return eventCount_.value(); 1232 } 1233 SetEventCount(int32_t eventCount)1234 BufferUsage &SetEventCount(int32_t eventCount) 1235 { 1236 eventCount_ = eventCount; 1237 return *this; 1238 } 1239 HasEventCount()1240 bool HasEventCount() const 1241 { 1242 return eventCount_.has_value(); 1243 } 1244 GetValue()1245 double GetValue() const 1246 { 1247 return value_.value(); 1248 } 1249 SetValue(double value)1250 BufferUsage &SetValue(double value) 1251 { 1252 value_ = value; 1253 return *this; 1254 } 1255 HasValue()1256 bool HasValue() const 1257 { 1258 return value_.has_value(); 1259 } 1260 1261 private: 1262 NO_COPY_SEMANTIC(BufferUsage); 1263 NO_MOVE_SEMANTIC(BufferUsage); 1264 1265 std::optional<double> percentFull_ {0}; 1266 std::optional<int32_t> eventCount_ {0}; 1267 std::optional<double> value_ {0}; 1268 }; 1269 1270 class DataCollected final : public PtBaseEvents { 1271 public: 1272 DataCollected() = default; 1273 ~DataCollected() override = default; 1274 std::unique_ptr<PtJson> ToJson() const override; 1275 std::unique_ptr<PtJson> TraceEventToJson(TraceEvent &traceEvent) const; 1276 GetName()1277 std::string GetName() const override 1278 { 1279 return "Tracing.dataCollected"; 1280 } 1281 SetTraceEvents(std::unique_ptr<std::vector<TraceEvent>> traceEvents)1282 DataCollected &SetTraceEvents(std::unique_ptr<std::vector<TraceEvent>> traceEvents) 1283 { 1284 traceEvents_ = std::move(traceEvents); 1285 return *this; 1286 } 1287 1288 private: 1289 NO_COPY_SEMANTIC(DataCollected); 1290 NO_MOVE_SEMANTIC(DataCollected); 1291 1292 std::unique_ptr<std::vector<TraceEvent>> traceEvents_; 1293 }; 1294 1295 class TracingComplete final : public PtBaseEvents { 1296 public: 1297 TracingComplete() = default; 1298 ~TracingComplete() override = default; 1299 std::unique_ptr<PtJson> ToJson() const override; 1300 GetName()1301 std::string GetName() const override 1302 { 1303 return "Tracing.tracingComplete"; 1304 } 1305 GetDataLossOccurred()1306 bool GetDataLossOccurred() const 1307 { 1308 return dataLossOccurred_; 1309 } 1310 SetDataLossOccurred(bool dataLossOccurred)1311 TracingComplete &SetDataLossOccurred(bool dataLossOccurred) 1312 { 1313 dataLossOccurred_ = dataLossOccurred; 1314 return *this; 1315 } 1316 GetTraceFormat()1317 StreamFormat *GetTraceFormat() const 1318 { 1319 if (traceFormat_) { 1320 return traceFormat_->get(); 1321 } 1322 return nullptr; 1323 } 1324 SetTraceFormat(std::unique_ptr<StreamFormat> traceFormat)1325 TracingComplete &SetTraceFormat(std::unique_ptr<StreamFormat> traceFormat) 1326 { 1327 traceFormat_ = std::move(traceFormat); 1328 return *this; 1329 } 1330 HasTraceFormat()1331 bool HasTraceFormat() const 1332 { 1333 return traceFormat_.has_value(); 1334 } 1335 GetStreamCompression()1336 StreamCompression *GetStreamCompression() const 1337 { 1338 if (streamCompression_) { 1339 return streamCompression_->get(); 1340 } 1341 return nullptr; 1342 } 1343 SetStreamCompression(std::unique_ptr<StreamCompression> streamCompression)1344 TracingComplete &SetStreamCompression(std::unique_ptr<StreamCompression> streamCompression) 1345 { 1346 streamCompression_ = std::move(streamCompression); 1347 return *this; 1348 } 1349 HasStreamCompression()1350 bool HasStreamCompression() const 1351 { 1352 return streamCompression_.has_value(); 1353 } 1354 1355 private: 1356 NO_COPY_SEMANTIC(TracingComplete); 1357 NO_MOVE_SEMANTIC(TracingComplete); 1358 1359 bool dataLossOccurred_ {}; 1360 /* 1361 * { TracingComplete.stream } IO is currently not supported; 1362 */ 1363 std::optional<std::unique_ptr<StreamFormat>> traceFormat_ {}; 1364 std::optional<std::unique_ptr<StreamCompression>> streamCompression_ {}; 1365 }; 1366 } // namespace panda::ecmascript::tooling 1367 #endif 1368