Skip to content

Commit c907d4e

Browse files
committed
src: move ParseInspectOptions out of CommandBase
It is referenced in both llnode.cc and llscan.cc, to make sure targets can compile by only including llscan.h, this is the minimum change required. PR-URL: #208 Refs: #206 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matheus Marchini <[email protected]>
1 parent 8045d77 commit c907d4e

File tree

4 files changed

+57
-59
lines changed

4 files changed

+57
-59
lines changed

src/llnode.cc

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,63 +28,6 @@ using lldb::SBValue;
2828
using lldb::eReturnStatusFailed;
2929
using lldb::eReturnStatusSuccessFinishResult;
3030

31-
char** CommandBase::ParseInspectOptions(char** cmd,
32-
v8::Value::InspectOptions* options) {
33-
static struct option opts[] = {
34-
{"full-string", no_argument, nullptr, 'F'},
35-
{"string-length", required_argument, nullptr, 'l'},
36-
{"array-length", required_argument, nullptr, 'l'},
37-
{"length", required_argument, nullptr, 'l'},
38-
{"print-map", no_argument, nullptr, 'm'},
39-
{"print-source", no_argument, nullptr, 's'},
40-
{"verbose", no_argument, nullptr, 'v'},
41-
{"detailed", no_argument, nullptr, 'd'},
42-
{nullptr, 0, nullptr, 0}};
43-
44-
int argc = 1;
45-
for (char** p = cmd; p != nullptr && *p != nullptr; p++) argc++;
46-
47-
char* args[argc];
48-
49-
// Make this look like a command line, we need a valid element at index 0
50-
// for getopt_long to use in its error messages.
51-
char name[] = "llnode";
52-
args[0] = name;
53-
for (int i = 0; i < argc - 1; i++) args[i + 1] = cmd[i];
54-
55-
// Reset getopts.
56-
optind = 0;
57-
opterr = 1;
58-
do {
59-
int arg = getopt_long(argc, args, "Fmsdvl:", opts, nullptr);
60-
if (arg == -1) break;
61-
62-
switch (arg) {
63-
case 'F':
64-
options->length = 0;
65-
break;
66-
case 'm':
67-
options->print_map = true;
68-
break;
69-
case 'l':
70-
options->length = strtol(optarg, nullptr, 10);
71-
break;
72-
case 's':
73-
options->print_source = true;
74-
break;
75-
case 'd':
76-
case 'v':
77-
options->detailed = true;
78-
break;
79-
default:
80-
continue;
81-
}
82-
} while (true);
83-
84-
// Use the original cmd array for our return value.
85-
return &cmd[optind - 1];
86-
}
87-
8831

8932
bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
9033
SBCommandReturnObject& result) {

src/llnode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
namespace llnode {
1111

1212
class CommandBase : public lldb::SBCommandPluginInterface {
13-
public:
14-
char** ParseInspectOptions(char** cmd, v8::Value::InspectOptions* options);
1513
};
1614

1715
class BacktraceCmd : public CommandBase {

src/llscan.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,62 @@ const char* const
4141
const char* const FindReferencesCmd::StringScanner::array_reference_template =
4242
"0x%" PRIx64 ": %s[%" PRId64 "]=0x%" PRIx64 " '%s'\n";
4343

44+
char** ParseInspectOptions(char** cmd, v8::Value::InspectOptions* options) {
45+
static struct option opts[] = {
46+
{"full-string", no_argument, nullptr, 'F'},
47+
{"string-length", required_argument, nullptr, 'l'},
48+
{"array-length", required_argument, nullptr, 'l'},
49+
{"length", required_argument, nullptr, 'l'},
50+
{"print-map", no_argument, nullptr, 'm'},
51+
{"print-source", no_argument, nullptr, 's'},
52+
{"verbose", no_argument, nullptr, 'v'},
53+
{"detailed", no_argument, nullptr, 'd'},
54+
{nullptr, 0, nullptr, 0}};
55+
56+
int argc = 1;
57+
for (char** p = cmd; p != nullptr && *p != nullptr; p++) argc++;
58+
59+
char* args[argc];
60+
61+
// Make this look like a command line, we need a valid element at index 0
62+
// for getopt_long to use in its error messages.
63+
char name[] = "llnode";
64+
args[0] = name;
65+
for (int i = 0; i < argc - 1; i++) args[i + 1] = cmd[i];
66+
67+
// Reset getopts.
68+
optind = 0;
69+
opterr = 1;
70+
do {
71+
int arg = getopt_long(argc, args, "Fmsdvl:", opts, nullptr);
72+
if (arg == -1) break;
73+
74+
switch (arg) {
75+
case 'F':
76+
options->length = 0;
77+
break;
78+
case 'm':
79+
options->print_map = true;
80+
break;
81+
case 'l':
82+
options->length = strtol(optarg, nullptr, 10);
83+
break;
84+
case 's':
85+
options->print_source = true;
86+
break;
87+
case 'd':
88+
case 'v':
89+
options->detailed = true;
90+
break;
91+
default:
92+
continue;
93+
}
94+
} while (true);
95+
96+
// Use the original cmd array for our return value.
97+
return &cmd[optind - 1];
98+
}
99+
44100
bool FindObjectsCmd::DoExecute(SBDebugger d, char** cmd,
45101
SBCommandReturnObject& result) {
46102
SBTarget target = d.GetSelectedTarget();

src/llscan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef std::map<uint64_t, ReferencesVector*> ReferencesByValueMap;
1818
typedef std::map<std::string, ReferencesVector*> ReferencesByPropertyMap;
1919
typedef std::map<std::string, ReferencesVector*> ReferencesByStringMap;
2020

21+
char** ParseInspectOptions(char** cmd, v8::Value::InspectOptions* options);
2122

2223
class FindObjectsCmd : public CommandBase {
2324
public:

0 commit comments

Comments
 (0)