From bf416f1e2534804d94da14e157e53ee035ac6c0d Mon Sep 17 00:00:00 2001 From: Howard Hellyer Date: Mon, 14 Aug 2017 15:30:00 +0100 Subject: [PATCH 1/4] 1.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e60a6948..072d0edd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "llnode", - "version": "1.6.0", + "version": "1.6.1", "description": "Node.js plugin for LLDB", "main": "no-entry-sorry.js", "directories": { From 1ce2a40dbe7bd19ec59325e71a65c2afdda7bd41 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 13 Aug 2017 17:04:18 +0800 Subject: [PATCH 2/4] src: support thin strings Fixes: https://github.com/nodejs/llnode/issues/117 --- src/llnode.cc | 3 ++- src/llscan.cc | 16 ++++++++++++++++ src/llv8-constants.cc | 4 ++++ src/llv8-constants.h | 11 +++++++++++ src/llv8-inl.h | 12 ++++++++++++ src/llv8.cc | 19 ++++++++++++------- src/llv8.h | 12 +++++++++++- test/fixtures/inspect-scenario.js | 10 ++++++++++ test/inspect-test.js | 15 +++++++++++++++ 9 files changed, 93 insertions(+), 9 deletions(-) diff --git a/src/llnode.cc b/src/llnode.cc index d24fdc4c..204ac64d 100644 --- a/src/llnode.cc +++ b/src/llnode.cc @@ -136,7 +136,8 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd, lldb::SBMemoryRegionInfo info; if (target.GetProcess().GetMemoryRegionInfo(pc, info).Success() && info.IsExecutable() && info.IsWritable()) { - result.Printf(" %c frame #%u: 0x%016" PRIx64 " \n", star, i, pc); + result.Printf(" %c frame #%u: 0x%016" PRIx64 " \n", star, i, + pc); continue; } } diff --git a/src/llscan.cc b/src/llscan.cc index 9ebc3e94..63988e18 100644 --- a/src/llscan.cc +++ b/src/llscan.cc @@ -617,6 +617,14 @@ void FindReferencesCmd::ReferenceScanner::PrintRefs( result.Printf("0x%" PRIx64 ": %s.%s=0x%" PRIx64 "\n", str.raw(), type_name.c_str(), "", search_value_.raw()); } + } else if (repr == v8->string()->kThinStringTag) { + v8::ThinString thin_str(str); + v8::String actual = thin_str.Actual(err); + if (err.Success() && actual.raw() == search_value_.raw()) { + std::string type_name = thin_str.GetTypeName(err); + result.Printf("0x%" PRIx64 ": %s.%s=0x%" PRIx64 "\n", str.raw(), + type_name.c_str(), "", search_value_.raw()); + } } // Nothing to do for other kinds of string. } @@ -694,6 +702,14 @@ void FindReferencesCmd::ReferenceScanner::ScanRefs(v8::String& str, references = llscan.GetReferencesByValue(second.raw()); references->push_back(str.raw()); } + } else if (repr == v8->string()->kThinStringTag) { + v8::ThinString thin_str(str); + v8::String actual = thin_str.Actual(err); + + if (err.Success()) { + references = llscan.GetReferencesByValue(actual.raw()); + references->push_back(str.raw()); + } } // Nothing to do for other kinds of string. } diff --git a/src/llv8-constants.cc b/src/llv8-constants.cc index d36cec53..4b75b180 100644 --- a/src/llv8-constants.cc +++ b/src/llv8-constants.cc @@ -334,6 +334,7 @@ void String::Load() { kConsStringTag = LoadConstant("ConsStringTag"); kSlicedStringTag = LoadConstant("SlicedStringTag"); kExternalStringTag = LoadConstant("ExternalStringTag"); + kThinStringTag = LoadConstant("ThinStringTag"); kLengthOffset = LoadConstant("class_String__length__SMI"); } @@ -362,6 +363,9 @@ void SlicedString::Load() { kOffsetOffset = LoadConstant("class_SlicedString__offset__SMI"); } +void ThinString::Load() { + kActualOffset = LoadConstant("class_ThinString__actual__String"); +} void FixedArrayBase::Load() { kLengthOffset = LoadConstant("class_FixedArrayBase__length__SMI"); diff --git a/src/llv8-constants.h b/src/llv8-constants.h index 04a46d23..699d0c93 100644 --- a/src/llv8-constants.h +++ b/src/llv8-constants.h @@ -248,6 +248,7 @@ class String : public Module { int64_t kConsStringTag; int64_t kSlicedStringTag; int64_t kExternalStringTag; + int64_t kThinStringTag; int64_t kLengthOffset; @@ -297,6 +298,16 @@ class SlicedString : public Module { void Load(); }; +class ThinString : public Module { + public: + MODULE_DEFAULT_METHODS(ThinString); + + int64_t kActualOffset; + + protected: + void Load(); +}; + class FixedArrayBase : public Module { public: MODULE_DEFAULT_METHODS(FixedArrayBase); diff --git a/src/llv8-inl.h b/src/llv8-inl.h index 47281eea..8d4a0d51 100644 --- a/src/llv8-inl.h +++ b/src/llv8-inl.h @@ -272,6 +272,8 @@ ACCESSOR(ConsString, Second, cons_string()->kSecondOffset, String); ACCESSOR(SlicedString, Parent, sliced_string()->kParentOffset, String); ACCESSOR(SlicedString, Offset, sliced_string()->kOffsetOffset, Smi); +ACCESSOR(ThinString, Actual, thin_string()->kActualOffset, String); + ACCESSOR(FixedArrayBase, Length, fixed_array_base()->kLengthOffset, Smi); inline std::string OneByteString::ToString(Error& err) { @@ -319,6 +321,16 @@ inline std::string SlicedString::ToString(Error& err) { return tmp.substr(offset.GetValue(), length.GetValue()); } +inline std::string ThinString::ToString(Error& err) { + String actual = Actual(err); + if (err.Fail()) return std::string(); + + std::string tmp = actual.ToString(err); + if (err.Fail()) return std::string(); + + return tmp; +} + inline int64_t FixedArray::LeaData() const { return LeaField(v8()->fixed_array()->kDataOffset); } diff --git a/src/llv8.cc b/src/llv8.cc index 20ecb06d..64606e49 100644 --- a/src/llv8.cc +++ b/src/llv8.cc @@ -2,7 +2,6 @@ #include #include -#include #include "llv8-inl.h" #include "llv8.h" @@ -43,6 +42,7 @@ void LLV8::Load(SBTarget target) { two_byte_string.Assign(target, &common); cons_string.Assign(target, &common); sliced_string.Assign(target, &common); + thin_string.Assign(target, &common); fixed_array_base.Assign(target, &common); fixed_array.Assign(target, &common); oddball.Assign(target, &common); @@ -90,8 +90,7 @@ double LLV8::LoadDouble(int64_t addr, Error& err) { std::string LLV8::LoadBytes(int64_t length, int64_t addr, Error& err) { uint8_t* buf = new uint8_t[length + 1]; SBError sberr; - process_.ReadMemory(addr, buf, - static_cast(length), sberr); + process_.ReadMemory(addr, buf, static_cast(length), sberr); if (sberr.Fail()) { err = Error::Failure("Failed to load V8 raw buffer"); delete[] buf; @@ -957,6 +956,11 @@ std::string String::ToString(Error& err) { return std::string("(external)"); } + if (repr == v8()->string()->kThinStringTag) { + ThinString thin(this); + return thin.ToString(err); + } + err = Error::Failure("Unsupported string representation"); return std::string(); } @@ -1111,9 +1115,9 @@ std::string JSArrayBuffer::Inspect(InspectOptions* options, Error& err) { char tmp[128]; snprintf(tmp, sizeof(tmp), - "detailed) { @@ -1156,7 +1160,8 @@ std::string JSArrayBufferView::Inspect(InspectOptions* options, Error& err) { int byte_offset = static_cast(off.GetValue()); char tmp[128]; snprintf(tmp, sizeof(tmp), - " { let regexp = null; let cons = null; + let thin = null; let arrowFunc = null; let array = null; let longArray = null; @@ -112,6 +113,11 @@ tape('v8 inspect', (t) => { t.ok(consMatch, '.cons-string ConsString property'); cons = consMatch[1]; + const thinMatch = lines.match( + /.thin-string=(0x[0-9a-f]+):/); + t.ok(thinMatch, '.thin-string ThinString property'); + thin = thinMatch[1]; + sess.send(`v8 inspect ${regexp}`); sess.send(`v8 inspect -F ${cons}`); }); @@ -141,6 +147,15 @@ tape('v8 inspect', (t) => { -1, '--string-length truncates the string'); + sess.send(`v8 inspect ${thin}`); + }); + + sess.linesUntil(/">/, (lines) => { + lines = lines.join('\n'); + t.ok( + /0x[0-9a-f]+:/.test(lines), + 'thin string content'); + sess.send(`v8 inspect ${array}`); }); From 178882b2a090105aad48252b80b89809e2ceac5a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 15 Aug 2017 23:07:25 +0800 Subject: [PATCH 3/4] src: support stub frames --- src/llv8-constants.cc | 1 + src/llv8-constants.h | 1 + src/llv8.cc | 2 ++ test/frame-test.js | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/llv8-constants.cc b/src/llv8-constants.cc index 4b75b180..ff68c812 100644 --- a/src/llv8-constants.cc +++ b/src/llv8-constants.cc @@ -522,6 +522,7 @@ void Frame::Load() { kConstructFrame = LoadConstant("frametype_ConstructFrame"); kJSFrame = LoadConstant("frametype_JavaScriptFrame"); kOptimizedFrame = LoadConstant("frametype_OptimizedFrame"); + kStubFrame = LoadConstant("frametype_StubFrame"); } diff --git a/src/llv8-constants.h b/src/llv8-constants.h index 699d0c93..3cc4e273 100644 --- a/src/llv8-constants.h +++ b/src/llv8-constants.h @@ -452,6 +452,7 @@ class Frame : public Module { int64_t kConstructFrame; int64_t kJSFrame; int64_t kOptimizedFrame; + int64_t kStubFrame; protected: void Load(); diff --git a/src/llv8.cc b/src/llv8.cc index 64606e49..ec18c305 100644 --- a/src/llv8.cc +++ b/src/llv8.cc @@ -267,6 +267,8 @@ std::string JSFrame::Inspect(bool with_args, Error& err) { return ""; } else if (value == v8()->frame()->kConstructFrame) { return ""; + } else if (value == v8()->frame()->kStubFrame) { + return ""; } else if (value != v8()->frame()->kJSFrame && value != v8()->frame()->kOptimizedFrame) { err = Error::Failure("Unknown frame marker"); diff --git a/test/frame-test.js b/test/frame-test.js index 69861344..f4f047fc 100644 --- a/test/frame-test.js +++ b/test/frame-test.js @@ -18,7 +18,7 @@ tape('v8 stack', (t) => { // FIXME(bnoordhuis) This can fail with versions of lldb that don't // support the GetMemoryRegions() API; llnode won't be able to identify // V8 builtins stack frames, it just prints them as anonymous frames. - lines = lines.filter((s) => !//.test(s)); + lines = lines.filter((s) => !/|/.test(s)); const eyecatcher = lines[0]; const adapter = lines[1]; const crasher = lines[2]; From 67cbdb5acd2930880b38b6ab86453886725eaf88 Mon Sep 17 00:00:00 2001 From: Howard Hellyer Date: Mon, 21 Aug 2017 10:37:12 +0100 Subject: [PATCH 4/4] llnode.cc: Combine array-length and string-length arguments Merge the string and array length arguments into one option as they can never both apply at the same time. Support a short option (-l) to the the user quickly specify how many elements of either strings or arrays to display. --- README.md | 7 +++---- src/llnode.cc | 27 +++++++++++++-------------- src/llv8.cc | 8 ++++---- src/llv8.h | 9 +++------ 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 2cc4374d..a23bcd93 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ v8 bt command. See the [Commands](#commands) section below for more commands. ### Commands ``` -(lldb) v8 help +(llnode) v8 help Node.js helpers Syntax: v8 @@ -226,7 +226,7 @@ The following subcommands are supported: Syntax: v8 bt [number] findjsinstances -- List all objects which share the specified map. Accepts the same options as `v8 inspect` - findjsobjects -- List all object types and instance counts grouped by map and sorted by instance count. + findjsobjects -- List all object types and instance counts grouped by typename and sorted by instance count. Requires `LLNODE_RANGESFILE` environment variable to be set to a file containing memory ranges for the core file being debugged. There are scripts for generating this file on Linux and Mac in the scripts directory of the llnode @@ -238,7 +238,6 @@ The following subcommands are supported: * -v, --value expr - all properties that refer to the specified JavaScript object (default) * -n, --name name - all properties with the specified name * -s, --string string - all properties that refer to the specified JavaScript string value - * --array-length num - print maximum of `num` elements in array inspect -- Print detailed description and contents of the JavaScript value. @@ -247,7 +246,7 @@ The following subcommands are supported: * -F, --full-string - print whole string without adding ellipsis * -m, --print-map - print object's map address * -s, --print-source - print source code for function objects - * --string-length num - print maximum of `num` characters in string + * -l num, --length num - print maximum of `num` elements from string/array Syntax: v8 inspect [flags] expr nodeinfo -- Print information about Node.js diff --git a/src/llnode.cc b/src/llnode.cc index d24fdc4c..6e674fe3 100644 --- a/src/llnode.cc +++ b/src/llnode.cc @@ -33,8 +33,9 @@ char** CommandBase::ParseInspectOptions(char** cmd, v8::Value::InspectOptions* options) { static struct option opts[] = { {"full-string", no_argument, nullptr, 'F'}, - {"string-length", required_argument, nullptr, 0x1001}, - {"array-length", required_argument, nullptr, 0x1002}, + {"string-length", required_argument, nullptr, 'l'}, + {"array-length", required_argument, nullptr, 'l'}, + {"length", required_argument, nullptr, 'l'}, {"print-map", no_argument, nullptr, 'm'}, {"print-source", no_argument, nullptr, 's'}, {nullptr, 0, nullptr, 0}}; @@ -54,21 +55,18 @@ char** CommandBase::ParseInspectOptions(char** cmd, optind = 0; opterr = 1; do { - int arg = getopt_long(argc, args, "Fms", opts, nullptr); + int arg = getopt_long(argc, args, "Fmsl:", opts, nullptr); if (arg == -1) break; switch (arg) { case 'F': - options->string_length = 0; + options->length = 0; break; case 'm': options->print_map = true; break; - case 0x1001: - options->string_length = strtol(optarg, nullptr, 10); - break; - case 0x1002: - options->array_length = strtol(optarg, nullptr, 10); + case 'l': + options->length = strtol(optarg, nullptr, 10); break; case 's': options->print_source = true; @@ -136,7 +134,8 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd, lldb::SBMemoryRegionInfo info; if (target.GetProcess().GetMemoryRegionInfo(pc, info).Success() && info.IsExecutable() && info.IsWritable()) { - result.Printf(" %c frame #%u: 0x%016" PRIx64 " \n", star, i, pc); + result.Printf(" %c frame #%u: 0x%016" PRIx64 " \n", star, i, + pc); continue; } } @@ -326,8 +325,8 @@ bool PluginInitialize(SBDebugger d) { " * -F, --full-string - print whole string without adding ellipsis\n" " * -m, --print-map - print object's map address\n" " * -s, --print-source - print source code for function objects\n" - " * --string-length num - print maximum of `num` characters in string\n" - " * --array-length num - print maximum of `num` elements in array\n" + " * -l num, --length num - print maximum of `num` elements from " + "string/array\n" "\n" "Syntax: v8 inspect [flags] expr\n"); interpreter.AddCommand("jsprint", new llnode::PrintCmd(true), @@ -342,8 +341,8 @@ bool PluginInitialize(SBDebugger d) { "Alias for `v8 source list`"); v8.AddCommand("findjsobjects", new llnode::FindObjectsCmd(), - "List all object types and instance counts grouped by map and " - "sorted by instance count.\n" + "List all object types and instance counts grouped by type" + "name and sorted by instance count.\n" #ifndef LLDB_SBMemoryRegionInfoList_h_ "Requires `LLNODE_RANGESFILE` environment variable to be set " "to a file containing memory ranges for the core file being " diff --git a/src/llv8.cc b/src/llv8.cc index 20ecb06d..077b48ea 100644 --- a/src/llv8.cc +++ b/src/llv8.cc @@ -966,7 +966,7 @@ std::string String::Inspect(InspectOptions* options, Error& err) { std::string val = ToString(err); if (err.Fail()) return std::string(); - unsigned int len = options->string_length; + unsigned int len = options->length; if (len != 0 && val.length() > len) val = val.substr(0, len) + "..."; @@ -1119,7 +1119,7 @@ std::string JSArrayBuffer::Inspect(InspectOptions* options, Error& err) { if (options->detailed) { res += ": [\n "; - int display_length = std::min(byte_length, options->array_length); + int display_length = std::min(byte_length, options->length); res += v8()->LoadBytes(display_length, data, err); if (display_length < byte_length) { @@ -1164,7 +1164,7 @@ std::string JSArrayBufferView::Inspect(InspectOptions* options, Error& err) { if (options->detailed) { res += ": [\n "; - int display_length = std::min(byte_length, options->array_length); + int display_length = std::min(byte_length, options->length); res += v8()->LoadBytes(display_length, data + byte_offset, err); if (display_length < byte_length) { @@ -1914,7 +1914,7 @@ std::string JSArray::Inspect(InspectOptions* options, Error& err) { std::string res = "