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 SetLocations(std::vector<std::shared_ptr<BreakpointReturnInfo>> locations)811 ScriptParsed &SetLocations(std::vector<std::shared_ptr<BreakpointReturnInfo>> locations) 812 { 813 locations_ = locations; 814 return *this; 815 } 816 817 private: 818 NO_COPY_SEMANTIC(ScriptParsed); 819 NO_MOVE_SEMANTIC(ScriptParsed); 820 821 ScriptId scriptId_ {0}; 822 std::string url_ {}; 823 int32_t startLine_ {0}; 824 int32_t startColumn_ {0}; 825 int32_t endLine_ {0}; 826 int32_t endColumn_ {0}; 827 ExecutionContextId executionContextId_ {0}; 828 std::string hash_ {}; 829 std::optional<Local<ObjectRef>> execContextAuxData_ {}; 830 std::optional<bool> isLiveEdit_ {}; 831 std::optional<std::string> sourceMapUrl_ {}; 832 std::optional<bool> hasSourceUrl_ {}; 833 std::optional<bool> isModule_ {}; 834 std::optional<int32_t> length_ {}; 835 std::optional<int32_t> codeOffset_ {}; 836 std::optional<std::string> scriptLanguage_ {}; 837 std::optional<std::string> embedderName_ {}; 838 std::vector<std::shared_ptr<BreakpointReturnInfo>> locations_ {}; 839 }; 840 841 class AddHeapSnapshotChunk final : public PtBaseEvents { 842 public: 843 AddHeapSnapshotChunk() = default; 844 ~AddHeapSnapshotChunk() override = default; 845 std::unique_ptr<PtJson> ToJson() const override; 846 GetName()847 std::string GetName() const override 848 { 849 return "HeapProfiler.addHeapSnapshotChunk"; 850 } 851 SetChunk(const std::string & chunk)852 AddHeapSnapshotChunk &SetChunk(const std::string &chunk) 853 { 854 chunk_ = chunk; 855 return *this; 856 } 857 GetChunk()858 std::string &GetChunk() 859 { 860 return chunk_; 861 } 862 863 private: 864 NO_COPY_SEMANTIC(AddHeapSnapshotChunk); 865 NO_MOVE_SEMANTIC(AddHeapSnapshotChunk); 866 867 std::string chunk_ {}; 868 }; 869 870 class ConsoleProfileFinished final : public PtBaseEvents { 871 public: 872 ConsoleProfileFinished() = default; 873 ~ConsoleProfileFinished() override = default; 874 std::unique_ptr<PtJson> ToJson() const override; GetName()875 std::string GetName() const override 876 { 877 return "Profile.ConsoleProfileFinished"; 878 } 879 GetId()880 const std::string &GetId() const 881 { 882 return id_; 883 } 884 SetId(const std::string & id)885 ConsoleProfileFinished &SetId(const std::string &id) 886 { 887 id_ = id; 888 return *this; 889 } 890 GetLocation()891 Location *GetLocation() const 892 { 893 return location_.get(); 894 } 895 SetLocation(std::unique_ptr<Location> location)896 ConsoleProfileFinished &SetLocation(std::unique_ptr<Location> location) 897 { 898 location_ = std::move(location); 899 return *this; 900 } 901 GetProfile()902 Profile *GetProfile() const 903 { 904 return profile_.get(); 905 } 906 SetProfile(std::unique_ptr<Profile> profile)907 ConsoleProfileFinished &SetProfile(std::unique_ptr<Profile> profile) 908 { 909 profile_ = std::move(profile); 910 return *this; 911 } 912 GetTitle()913 const std::string &GetTitle() const 914 { 915 ASSERT(HasTitle()); 916 return title_.value(); 917 } 918 SetTitle(const std::string & title)919 ConsoleProfileFinished &SetTitle(const std::string &title) 920 { 921 title_ = title; 922 return *this; 923 } 924 HasTitle()925 bool HasTitle() const 926 { 927 return title_.has_value(); 928 } 929 930 private: 931 NO_COPY_SEMANTIC(ConsoleProfileFinished); 932 NO_MOVE_SEMANTIC(ConsoleProfileFinished); 933 934 std::string id_ {}; 935 std::unique_ptr<Location> location_ {nullptr}; 936 std::unique_ptr<Profile> profile_ {nullptr}; 937 std::optional<std::string> title_ {}; 938 }; 939 940 class ConsoleProfileStarted final : public PtBaseEvents { 941 public: 942 ConsoleProfileStarted() = default; 943 ~ConsoleProfileStarted() override = default; 944 std::unique_ptr<PtJson> ToJson() const override; GetName()945 std::string GetName() const override 946 { 947 return "Profile.ConsoleProfileStarted"; 948 } 949 GetId()950 const std::string &GetId() const 951 { 952 return id_; 953 } 954 SetId(const std::string & id)955 ConsoleProfileStarted &SetId(const std::string &id) 956 { 957 id_ = id; 958 return *this; 959 } 960 GetLocation()961 Location *GetLocation() const 962 { 963 return location_.get(); 964 } 965 SetLocation(std::unique_ptr<Location> location)966 ConsoleProfileStarted &SetLocation(std::unique_ptr<Location> location) 967 { 968 location_ = std::move(location); 969 return *this; 970 } 971 GetTitle()972 const std::string &GetTitle() const 973 { 974 ASSERT(HasTitle()); 975 return title_.value(); 976 } 977 SetTitle(const std::string & title)978 ConsoleProfileStarted &SetTitle(const std::string &title) 979 { 980 title_ = title; 981 return *this; 982 } 983 HasTitle()984 bool HasTitle() const 985 { 986 return title_.has_value(); 987 } 988 989 private: 990 NO_COPY_SEMANTIC(ConsoleProfileStarted); 991 NO_MOVE_SEMANTIC(ConsoleProfileStarted); 992 993 std::string id_ {}; 994 std::unique_ptr<Location> location_ {nullptr}; 995 std::optional<std::string> title_ {}; 996 }; 997 998 class PreciseCoverageDeltaUpdate final : public PtBaseEvents { 999 public: 1000 PreciseCoverageDeltaUpdate() = default; 1001 ~PreciseCoverageDeltaUpdate() override = default; 1002 std::unique_ptr<PtJson> ToJson() const override; GetName()1003 std::string GetName() const override 1004 { 1005 return "Profile.PreciseCoverageDeltaUpdate"; 1006 } 1007 GetTimestamp()1008 int64_t GetTimestamp() const 1009 { 1010 return timestamp_; 1011 } 1012 SetTimestamp(int64_t timestamp)1013 PreciseCoverageDeltaUpdate &SetTimestamp(int64_t timestamp) 1014 { 1015 timestamp_ = timestamp; 1016 return *this; 1017 } 1018 GetOccasion()1019 const std::string &GetOccasion() const 1020 { 1021 return occasion_; 1022 } 1023 SetOccasion(const std::string & occasion)1024 PreciseCoverageDeltaUpdate &SetOccasion(const std::string &occasion) 1025 { 1026 occasion_ = occasion; 1027 return *this; 1028 } 1029 GetResult()1030 const std::vector<std::unique_ptr<ScriptCoverage>> *GetResult() const 1031 { 1032 return &result_; 1033 } 1034 SetResult(std::vector<std::unique_ptr<ScriptCoverage>> result)1035 PreciseCoverageDeltaUpdate &SetResult(std::vector<std::unique_ptr<ScriptCoverage>> result) 1036 { 1037 result_ = std::move(result); 1038 return *this; 1039 } 1040 1041 private: 1042 NO_COPY_SEMANTIC(PreciseCoverageDeltaUpdate); 1043 NO_MOVE_SEMANTIC(PreciseCoverageDeltaUpdate); 1044 1045 int64_t timestamp_ {0}; 1046 std::string occasion_ {}; 1047 std::vector<std::unique_ptr<ScriptCoverage>> result_ {}; 1048 }; 1049 1050 class HeapStatsUpdate final : public PtBaseEvents { 1051 public: 1052 HeapStatsUpdate() = default; 1053 ~HeapStatsUpdate() override = default; 1054 std::unique_ptr<PtJson> ToJson() const override; 1055 GetName()1056 std::string GetName() const override 1057 { 1058 return "HeapProfiler.heapStatsUpdate"; 1059 } 1060 GetStatsUpdate()1061 const std::vector<int32_t> *GetStatsUpdate() const 1062 { 1063 return &statsUpdate_; 1064 } 1065 SetStatsUpdate(std::vector<int32_t> statsUpdate)1066 HeapStatsUpdate &SetStatsUpdate(std::vector<int32_t> statsUpdate) 1067 { 1068 statsUpdate_ = std::move(statsUpdate); 1069 return *this; 1070 } 1071 1072 private: 1073 NO_COPY_SEMANTIC(HeapStatsUpdate); 1074 NO_MOVE_SEMANTIC(HeapStatsUpdate); 1075 1076 std::vector<int32_t> statsUpdate_ {}; 1077 }; 1078 1079 class LastSeenObjectId final : public PtBaseEvents { 1080 public: 1081 LastSeenObjectId() = default; 1082 ~LastSeenObjectId() override = default; 1083 std::unique_ptr<PtJson> ToJson() const override; 1084 GetName()1085 std::string GetName() const override 1086 { 1087 return "HeapProfiler.lastSeenObjectId"; 1088 } 1089 GetLastSeenObjectId()1090 int32_t GetLastSeenObjectId() const 1091 { 1092 return lastSeenObjectId_; 1093 } 1094 SetLastSeenObjectId(int32_t lastSeenObjectId)1095 LastSeenObjectId &SetLastSeenObjectId(int32_t lastSeenObjectId) 1096 { 1097 lastSeenObjectId_ = lastSeenObjectId; 1098 return *this; 1099 } 1100 GetTimestamp()1101 double GetTimestamp() const 1102 { 1103 return timestamp_; 1104 } 1105 SetTimestamp(double timestamp)1106 LastSeenObjectId &SetTimestamp(double timestamp) 1107 { 1108 timestamp_ = timestamp; 1109 return *this; 1110 } 1111 1112 private: 1113 NO_COPY_SEMANTIC(LastSeenObjectId); 1114 NO_MOVE_SEMANTIC(LastSeenObjectId); 1115 1116 int32_t lastSeenObjectId_ {}; 1117 double timestamp_ {}; 1118 }; 1119 1120 class ReportHeapSnapshotProgress final : public PtBaseEvents { 1121 public: 1122 ReportHeapSnapshotProgress() = default; 1123 ~ReportHeapSnapshotProgress() override = default; 1124 std::unique_ptr<PtJson> ToJson() const override; 1125 GetName()1126 std::string GetName() const override 1127 { 1128 return "HeapProfiler.reportHeapSnapshotProgress"; 1129 } 1130 GetDone()1131 int32_t GetDone() const 1132 { 1133 return done_; 1134 } 1135 SetDone(int32_t done)1136 ReportHeapSnapshotProgress &SetDone(int32_t done) 1137 { 1138 done_ = done; 1139 return *this; 1140 } 1141 GetTotal()1142 int32_t GetTotal() const 1143 { 1144 return total_; 1145 } 1146 SetTotal(int32_t total)1147 ReportHeapSnapshotProgress &SetTotal(int32_t total) 1148 { 1149 total_ = total; 1150 return *this; 1151 } 1152 GetFinished()1153 bool GetFinished() const 1154 { 1155 return finished_.value_or(false); 1156 } 1157 SetFinished(bool finished)1158 ReportHeapSnapshotProgress &SetFinished(bool finished) 1159 { 1160 finished_ = finished; 1161 return *this; 1162 } 1163 1164 private: 1165 NO_COPY_SEMANTIC(ReportHeapSnapshotProgress); 1166 NO_MOVE_SEMANTIC(ReportHeapSnapshotProgress); 1167 1168 int32_t done_ {}; 1169 int32_t total_ {}; 1170 std::optional<bool> finished_ {}; 1171 }; 1172 1173 class BufferUsage final : public PtBaseEvents { 1174 public: 1175 BufferUsage() = default; 1176 ~BufferUsage() override = default; 1177 std::unique_ptr<PtJson> ToJson() const override; 1178 GetName()1179 std::string GetName() const override 1180 { 1181 return "Tracing.bufferUsage"; 1182 } 1183 GetPercentFull()1184 double GetPercentFull() const 1185 { 1186 return percentFull_.value(); 1187 } 1188 SetPercentFull(double percentFull)1189 BufferUsage &SetPercentFull(double percentFull) 1190 { 1191 percentFull_ = percentFull; 1192 return *this; 1193 } 1194 HasPercentFull()1195 bool HasPercentFull() const 1196 { 1197 return percentFull_.has_value(); 1198 } 1199 GetEventCount()1200 int32_t GetEventCount() const 1201 { 1202 return eventCount_.value(); 1203 } 1204 SetEventCount(int32_t eventCount)1205 BufferUsage &SetEventCount(int32_t eventCount) 1206 { 1207 eventCount_ = eventCount; 1208 return *this; 1209 } 1210 HasEventCount()1211 bool HasEventCount() const 1212 { 1213 return eventCount_.has_value(); 1214 } 1215 GetValue()1216 double GetValue() const 1217 { 1218 return value_.value(); 1219 } 1220 SetValue(double value)1221 BufferUsage &SetValue(double value) 1222 { 1223 value_ = value; 1224 return *this; 1225 } 1226 HasValue()1227 bool HasValue() const 1228 { 1229 return value_.has_value(); 1230 } 1231 1232 private: 1233 NO_COPY_SEMANTIC(BufferUsage); 1234 NO_MOVE_SEMANTIC(BufferUsage); 1235 1236 std::optional<double> percentFull_ {0}; 1237 std::optional<int32_t> eventCount_ {0}; 1238 std::optional<double> value_ {0}; 1239 }; 1240 1241 class DataCollected final : public PtBaseEvents { 1242 public: 1243 DataCollected() = default; 1244 ~DataCollected() override = default; 1245 std::unique_ptr<PtJson> ToJson() const override; 1246 std::unique_ptr<PtJson> TraceEventToJson(TraceEvent &traceEvent) const; 1247 GetName()1248 std::string GetName() const override 1249 { 1250 return "Tracing.dataCollected"; 1251 } 1252 SetTraceEvents(std::unique_ptr<std::vector<TraceEvent>> traceEvents)1253 DataCollected &SetTraceEvents(std::unique_ptr<std::vector<TraceEvent>> traceEvents) 1254 { 1255 traceEvents_ = std::move(traceEvents); 1256 return *this; 1257 } 1258 1259 private: 1260 NO_COPY_SEMANTIC(DataCollected); 1261 NO_MOVE_SEMANTIC(DataCollected); 1262 1263 std::unique_ptr<std::vector<TraceEvent>> traceEvents_; 1264 }; 1265 1266 class TracingComplete final : public PtBaseEvents { 1267 public: 1268 TracingComplete() = default; 1269 ~TracingComplete() override = default; 1270 std::unique_ptr<PtJson> ToJson() const override; 1271 GetName()1272 std::string GetName() const override 1273 { 1274 return "Tracing.tracingComplete"; 1275 } 1276 GetDataLossOccurred()1277 bool GetDataLossOccurred() const 1278 { 1279 return dataLossOccurred_; 1280 } 1281 SetDataLossOccurred(bool dataLossOccurred)1282 TracingComplete &SetDataLossOccurred(bool dataLossOccurred) 1283 { 1284 dataLossOccurred_ = dataLossOccurred; 1285 return *this; 1286 } 1287 GetTraceFormat()1288 StreamFormat *GetTraceFormat() const 1289 { 1290 if (traceFormat_) { 1291 return traceFormat_->get(); 1292 } 1293 return nullptr; 1294 } 1295 SetTraceFormat(std::unique_ptr<StreamFormat> traceFormat)1296 TracingComplete &SetTraceFormat(std::unique_ptr<StreamFormat> traceFormat) 1297 { 1298 traceFormat_ = std::move(traceFormat); 1299 return *this; 1300 } 1301 HasTraceFormat()1302 bool HasTraceFormat() const 1303 { 1304 return traceFormat_.has_value(); 1305 } 1306 GetStreamCompression()1307 StreamCompression *GetStreamCompression() const 1308 { 1309 if (streamCompression_) { 1310 return streamCompression_->get(); 1311 } 1312 return nullptr; 1313 } 1314 SetStreamCompression(std::unique_ptr<StreamCompression> streamCompression)1315 TracingComplete &SetStreamCompression(std::unique_ptr<StreamCompression> streamCompression) 1316 { 1317 streamCompression_ = std::move(streamCompression); 1318 return *this; 1319 } 1320 HasStreamCompression()1321 bool HasStreamCompression() const 1322 { 1323 return streamCompression_.has_value(); 1324 } 1325 1326 private: 1327 NO_COPY_SEMANTIC(TracingComplete); 1328 NO_MOVE_SEMANTIC(TracingComplete); 1329 1330 bool dataLossOccurred_ {}; 1331 /* 1332 * { TracingComplete.stream } IO is currently not supported; 1333 */ 1334 std::optional<std::unique_ptr<StreamFormat>> traceFormat_ {}; 1335 std::optional<std::unique_ptr<StreamCompression>> streamCompression_ {}; 1336 }; 1337 } // namespace panda::ecmascript::tooling 1338 #endif 1339