Skip to content

Commit e7d22b1

Browse files
author
David Pacheco
committed
#107 would like dcmd for heuristically finding back references
Reviewed by: Cody Peter Mello <[email protected]> Approved by: Cody Peter Mello <[email protected]>
1 parent 807950e commit e7d22b1

13 files changed

+1373
-185
lines changed

CHANGES.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
# mdb_v8 changelog
1212

13-
## Unreleased changes
13+
## v1.4.0 (2018-03)
1414

15+
* #107 would like dcmd for heuristically finding back references
1516
* #111 want `::v8whatis`
16-
* #112 stack corruption in jsobj_properties()
17+
* #112 stack corruption in jsobj\_properties()
1718

1819
## v1.3.0 (2018-02-09)
1920

GNUmakefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ MDBV8_SOURCES = \
5050
mdb_v8.c \
5151
mdb_v8_array.c \
5252
mdb_v8_cfg.c \
53+
mdb_v8_dbi.c \
5354
mdb_v8_function.c \
5455
mdb_v8_strbuf.c \
5556
mdb_v8_string.c \
56-
mdb_v8_subr.c
57+
mdb_v8_subr.c \
58+
mdb_v8_whatis.c
5759

5860
MDBV8_GENSOURCES = mdb_v8_version.c
5961

docs/usage.md

+103-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-->
66

77
<!--
8-
Copyright (c) 2017, Joyent, Inc.
8+
Copyright (c) 2018, Joyent, Inc.
99
-->
1010

1111
# Postmortem debugging with mdb_v8
@@ -567,6 +567,8 @@ Option summary:
567567
-r Find references to the specified and/or marked object(s)
568568
-v Provide verbose statistics
569569

570+
See also: `jsfindrefs`.
571+
570572
### jsclosure
571573

572574
addr::jsclosure
@@ -705,6 +707,106 @@ function's underlying V8 heap object address for use with `v8function`.
705707

706708
See also: `jsfunction`
707709

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+
708810
### jsframe
709811

710812
addr::jsframe [-aiv] [-f function] [-p property] [-n numlines]

0 commit comments

Comments
 (0)