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