|
5 | 5 | -->
|
6 | 6 |
|
7 | 7 | <!--
|
8 |
| - Copyright (c) 2017, Joyent, Inc. |
| 8 | + Copyright (c) 2018, Joyent, Inc. |
9 | 9 | -->
|
10 | 10 |
|
11 | 11 | # Postmortem debugging with mdb_v8
|
@@ -567,6 +567,8 @@ Option summary:
|
567 | 567 | -r Find references to the specified and/or marked object(s)
|
568 | 568 | -v Provide verbose statistics
|
569 | 569 |
|
| 570 | +See also: `jsfindrefs`. |
| 571 | + |
570 | 572 | ### jsclosure
|
571 | 573 |
|
572 | 574 | addr::jsclosure
|
@@ -705,6 +707,106 @@ function's underlying V8 heap object address for use with `v8function`.
|
705 | 707 |
|
706 | 708 | See also: `jsfunction`
|
707 | 709 |
|
| 710 | +### jsfindrefs |
| 711 | + |
| 712 | + addr::jsfindrefs [-dv] [-l maxdepth] |
| 713 | + |
| 714 | +Given an object identified by `addr`, attempts to find JavaScript values that |
| 715 | +appear to reference `addr`. This command attempts to find all known types of |
| 716 | +reference, including: |
| 717 | + |
| 718 | +- objects with a property whose value is `addr` |
| 719 | +- arrays with an element whose value is `addr` |
| 720 | +- closures containing a variable whose value is `addr` |
| 721 | +- functions created with `Function.bind()` where `addr` is the value of one of |
| 722 | + the bound variables |
| 723 | +- sliced strings whose underlying string is `addr` |
| 724 | +- regular expressions whose source string is `addr` |
| 725 | + |
| 726 | +and others. For example, if `addr` is a socket, you could use this command to |
| 727 | +find higher-level objects with a reference to the socket. This is useful in |
| 728 | +general debugging, and especially when debugging memory leaks in order to figure |
| 729 | +out why an object has not been garbage-collected. |
| 730 | + |
| 731 | +With no arguments, the command prints out other JavaScript values that |
| 732 | +reference the given value `addr`. For example, suppose we start with this |
| 733 | +array: |
| 734 | + |
| 735 | + > 8f912f09::jsprint -d1 |
| 736 | + [ |
| 737 | + 16, |
| 738 | + 32, |
| 739 | + 64, |
| 740 | + 96, |
| 741 | + "^regular expression!$", |
| 742 | + [...], |
| 743 | + ] |
| 744 | + |
| 745 | +We can find what other objects reference this array. In this case, there's |
| 746 | +only one: |
| 747 | + |
| 748 | + > 8f912f09::jsfindrefs |
| 749 | + 8f912df1 |
| 750 | + |
| 751 | +If we print out that value, we can see that it's an object, and that it does |
| 752 | +indeed reference our array via a property called "anArray": |
| 753 | + |
| 754 | + > 8f912df1::jsprint -a |
| 755 | + 8f912df1: { |
| 756 | + ... |
| 757 | + "anArray": 8f912f09: [ |
| 758 | + 20: 16, |
| 759 | + 40: 32, |
| 760 | + 80: 64, |
| 761 | + c0: 96, |
| 762 | + bda8ae39: "^regular expression!$", |
| 763 | + 8f912df1: [...], |
| 764 | + ], |
| 765 | + ... |
| 766 | + } |
| 767 | + |
| 768 | +In this case, the "parent" object is also an element of the array. This is a |
| 769 | +circular reference. If we print the object's references, we'll find the array |
| 770 | +among them: |
| 771 | + |
| 772 | + > 8f912df1::jsfindrefs |
| 773 | + ... |
| 774 | + 8f912f09 |
| 775 | + |
| 776 | +With the `-v` option, `jsfindrefs` prints a brief summary of each reference that |
| 777 | +it finds: |
| 778 | + |
| 779 | + > 8f912f09::jsfindrefs -v |
| 780 | + 8f912df1 (type: JSObject) |
| 781 | + |
| 782 | + > 8f912df1::jsfindrefs -v |
| 783 | + ... |
| 784 | + 8f912f09 (type: JSArray) |
| 785 | + |
| 786 | +The output format used for `-v` is subject to change. |
| 787 | + |
| 788 | +With the `-l maxdepth` option, `jsfindrefs` limits its search to at most |
| 789 | +`maxdepth` levels of indirection among the underlying V8 heap classes. In |
| 790 | +practice, it's only necessary to traverse 1 or 2 back references to find |
| 791 | +legitimate JavaScript references, so the default value for this option is quite |
| 792 | +low. |
| 793 | + |
| 794 | +With the `-d` option, `jsfindrefs` prints information as it walks back the |
| 795 | +reference graph. This is intended for debugging cases where the command |
| 796 | +misbehaves, though it's likely that familiarity with V8 internals is needed to |
| 797 | +make sense of the output. The output format for `-d` is subject to change. |
| 798 | + |
| 799 | +As with the rest of mdb_v8, this command is heuristic and may produce incorrect |
| 800 | +or incomplete output. Please file a bug if you encounter this. |
| 801 | + |
| 802 | +This command may report duplicate results. |
| 803 | + |
| 804 | +See also: `findjsobjects`. This command is similar to `::findjsobjects -r`, but |
| 805 | +it's much faster, as it does not require parsing every JavaScript object in the |
| 806 | +program. (It does scan all mappings in the address space, but this is generally |
| 807 | +quite quick.) |
| 808 | + |
| 809 | + |
708 | 810 | ### jsframe
|
709 | 811 |
|
710 | 812 | addr::jsframe [-aiv] [-f function] [-p property] [-n numlines]
|
|
0 commit comments