Skip to content

Commit f85f8fc

Browse files
authored
llnode.cc: Combine array-length and string-length arguments
PR-URL: #124 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2 parents 58d2c1a + 67cbdb5 commit f85f8fc

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ v8 bt command. See the [Commands](#commands) section below for more commands.
212212
### Commands
213213

214214
```
215-
(lldb) v8 help
215+
(llnode) v8 help
216216
Node.js helpers
217217
218218
Syntax: v8
@@ -226,7 +226,7 @@ The following subcommands are supported:
226226
Syntax: v8 bt [number]
227227
findjsinstances -- List all objects which share the specified map.
228228
Accepts the same options as `v8 inspect`
229-
findjsobjects -- List all object types and instance counts grouped by map and sorted by instance count.
229+
findjsobjects -- List all object types and instance counts grouped by typename and sorted by instance count.
230230
Requires `LLNODE_RANGESFILE` environment variable to be set to a file containing memory ranges for the
231231
core file being debugged.
232232
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:
238238
* -v, --value expr - all properties that refer to the specified JavaScript object (default)
239239
* -n, --name name - all properties with the specified name
240240
* -s, --string string - all properties that refer to the specified JavaScript string value
241-
* --array-length num - print maximum of `num` elements in array
242241
243242
inspect -- Print detailed description and contents of the JavaScript value.
244243
@@ -247,7 +246,7 @@ The following subcommands are supported:
247246
* -F, --full-string - print whole string without adding ellipsis
248247
* -m, --print-map - print object's map address
249248
* -s, --print-source - print source code for function objects
250-
* --string-length num - print maximum of `num` characters in string
249+
* -l num, --length num - print maximum of `num` elements from string/array
251250
252251
Syntax: v8 inspect [flags] expr
253252
nodeinfo -- Print information about Node.js

src/llnode.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ char** CommandBase::ParseInspectOptions(char** cmd,
3333
v8::Value::InspectOptions* options) {
3434
static struct option opts[] = {
3535
{"full-string", no_argument, nullptr, 'F'},
36-
{"string-length", required_argument, nullptr, 0x1001},
37-
{"array-length", required_argument, nullptr, 0x1002},
36+
{"string-length", required_argument, nullptr, 'l'},
37+
{"array-length", required_argument, nullptr, 'l'},
38+
{"length", required_argument, nullptr, 'l'},
3839
{"print-map", no_argument, nullptr, 'm'},
3940
{"print-source", no_argument, nullptr, 's'},
4041
{nullptr, 0, nullptr, 0}};
@@ -54,21 +55,18 @@ char** CommandBase::ParseInspectOptions(char** cmd,
5455
optind = 0;
5556
opterr = 1;
5657
do {
57-
int arg = getopt_long(argc, args, "Fms", opts, nullptr);
58+
int arg = getopt_long(argc, args, "Fmsl:", opts, nullptr);
5859
if (arg == -1) break;
5960

6061
switch (arg) {
6162
case 'F':
62-
options->string_length = 0;
63+
options->length = 0;
6364
break;
6465
case 'm':
6566
options->print_map = true;
6667
break;
67-
case 0x1001:
68-
options->string_length = strtol(optarg, nullptr, 10);
69-
break;
70-
case 0x1002:
71-
options->array_length = strtol(optarg, nullptr, 10);
68+
case 'l':
69+
options->length = strtol(optarg, nullptr, 10);
7270
break;
7371
case 's':
7472
options->print_source = true;
@@ -327,8 +325,8 @@ bool PluginInitialize(SBDebugger d) {
327325
" * -F, --full-string - print whole string without adding ellipsis\n"
328326
" * -m, --print-map - print object's map address\n"
329327
" * -s, --print-source - print source code for function objects\n"
330-
" * --string-length num - print maximum of `num` characters in string\n"
331-
" * --array-length num - print maximum of `num` elements in array\n"
328+
" * -l num, --length num - print maximum of `num` elements from "
329+
"string/array\n"
332330
"\n"
333331
"Syntax: v8 inspect [flags] expr\n");
334332
interpreter.AddCommand("jsprint", new llnode::PrintCmd(true),
@@ -343,8 +341,8 @@ bool PluginInitialize(SBDebugger d) {
343341
"Alias for `v8 source list`");
344342

345343
v8.AddCommand("findjsobjects", new llnode::FindObjectsCmd(),
346-
"List all object types and instance counts grouped by map and "
347-
"sorted by instance count.\n"
344+
"List all object types and instance counts grouped by type"
345+
"name and sorted by instance count.\n"
348346
#ifndef LLDB_SBMemoryRegionInfoList_h_
349347
"Requires `LLNODE_RANGESFILE` environment variable to be set "
350348
"to a file containing memory ranges for the core file being "

src/llv8.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ std::string String::Inspect(InspectOptions* options, Error& err) {
972972
std::string val = ToString(err);
973973
if (err.Fail()) return std::string();
974974

975-
unsigned int len = options->string_length;
975+
unsigned int len = options->length;
976976

977977
if (len != 0 && val.length() > len) val = val.substr(0, len) + "...";
978978

@@ -1125,7 +1125,7 @@ std::string JSArrayBuffer::Inspect(InspectOptions* options, Error& err) {
11251125
if (options->detailed) {
11261126
res += ": [\n ";
11271127

1128-
int display_length = std::min<int>(byte_length, options->array_length);
1128+
int display_length = std::min<int>(byte_length, options->length);
11291129
res += v8()->LoadBytes(display_length, data, err);
11301130

11311131
if (display_length < byte_length) {
@@ -1171,7 +1171,7 @@ std::string JSArrayBufferView::Inspect(InspectOptions* options, Error& err) {
11711171
if (options->detailed) {
11721172
res += ": [\n ";
11731173

1174-
int display_length = std::min<int>(byte_length, options->array_length);
1174+
int display_length = std::min<int>(byte_length, options->length);
11751175
res += v8()->LoadBytes(display_length, data + byte_offset, err);
11761176

11771177
if (display_length < byte_length) {
@@ -1921,7 +1921,7 @@ std::string JSArray::Inspect(InspectOptions* options, Error& err) {
19211921

19221922
std::string res = "<Array: length=" + std::to_string(length);
19231923
if (options->detailed) {
1924-
int64_t display_length = std::min<int64_t>(length, options->array_length);
1924+
int64_t display_length = std::min<int64_t>(length, options->length);
19251925
std::string elems = InspectElements(display_length, err);
19261926
if (err.Fail()) return std::string();
19271927

src/llv8.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ class Value {
5151
: detailed(false),
5252
print_map(false),
5353
print_source(false),
54-
string_length(kStringLength),
55-
array_length(kArrayLength) {}
54+
length(kLength) {}
5655

57-
static const unsigned int kStringLength = 16;
58-
static const unsigned int kArrayLength = 16;
56+
static const unsigned int kLength = 16;
5957

6058
bool detailed;
6159
bool print_map;
6260
bool print_source;
63-
unsigned int string_length;
64-
unsigned int array_length;
61+
unsigned int length;
6562
};
6663

6764
Value(const Value& v) = default;

0 commit comments

Comments
 (0)