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