Skip to content

Commit

Permalink
src: move ParseInspectOptions out of CommandBase
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joyeecheung committed Jun 25, 2018
1 parent 8045d77 commit c907d4e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 59 deletions.
57 changes: 0 additions & 57 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,63 +28,6 @@ using lldb::SBValue;
using lldb::eReturnStatusFailed;
using lldb::eReturnStatusSuccessFinishResult;

char** CommandBase::ParseInspectOptions(char** cmd,
v8::Value::InspectOptions* options) {
static struct option opts[] = {
{"full-string", no_argument, nullptr, 'F'},
{"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'},
{"verbose", no_argument, nullptr, 'v'},
{"detailed", no_argument, nullptr, 'd'},
{nullptr, 0, nullptr, 0}};

int argc = 1;
for (char** p = cmd; p != nullptr && *p != nullptr; p++) argc++;

char* args[argc];

// Make this look like a command line, we need a valid element at index 0
// for getopt_long to use in its error messages.
char name[] = "llnode";
args[0] = name;
for (int i = 0; i < argc - 1; i++) args[i + 1] = cmd[i];

// Reset getopts.
optind = 0;
opterr = 1;
do {
int arg = getopt_long(argc, args, "Fmsdvl:", opts, nullptr);
if (arg == -1) break;

switch (arg) {
case 'F':
options->length = 0;
break;
case 'm':
options->print_map = true;
break;
case 'l':
options->length = strtol(optarg, nullptr, 10);
break;
case 's':
options->print_source = true;
break;
case 'd':
case 'v':
options->detailed = true;
break;
default:
continue;
}
} while (true);

// Use the original cmd array for our return value.
return &cmd[optind - 1];
}


bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
Expand Down
2 changes: 0 additions & 2 deletions src/llnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
namespace llnode {

class CommandBase : public lldb::SBCommandPluginInterface {
public:
char** ParseInspectOptions(char** cmd, v8::Value::InspectOptions* options);
};

class BacktraceCmd : public CommandBase {
Expand Down
56 changes: 56 additions & 0 deletions src/llscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,62 @@ const char* const
const char* const FindReferencesCmd::StringScanner::array_reference_template =
"0x%" PRIx64 ": %s[%" PRId64 "]=0x%" PRIx64 " '%s'\n";

char** ParseInspectOptions(char** cmd, v8::Value::InspectOptions* options) {
static struct option opts[] = {
{"full-string", no_argument, nullptr, 'F'},
{"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'},
{"verbose", no_argument, nullptr, 'v'},
{"detailed", no_argument, nullptr, 'd'},
{nullptr, 0, nullptr, 0}};

int argc = 1;
for (char** p = cmd; p != nullptr && *p != nullptr; p++) argc++;

char* args[argc];

// Make this look like a command line, we need a valid element at index 0
// for getopt_long to use in its error messages.
char name[] = "llnode";
args[0] = name;
for (int i = 0; i < argc - 1; i++) args[i + 1] = cmd[i];

// Reset getopts.
optind = 0;
opterr = 1;
do {
int arg = getopt_long(argc, args, "Fmsdvl:", opts, nullptr);
if (arg == -1) break;

switch (arg) {
case 'F':
options->length = 0;
break;
case 'm':
options->print_map = true;
break;
case 'l':
options->length = strtol(optarg, nullptr, 10);
break;
case 's':
options->print_source = true;
break;
case 'd':
case 'v':
options->detailed = true;
break;
default:
continue;
}
} while (true);

// Use the original cmd array for our return value.
return &cmd[optind - 1];
}

bool FindObjectsCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
SBTarget target = d.GetSelectedTarget();
Expand Down
1 change: 1 addition & 0 deletions src/llscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ typedef std::map<uint64_t, ReferencesVector*> ReferencesByValueMap;
typedef std::map<std::string, ReferencesVector*> ReferencesByPropertyMap;
typedef std::map<std::string, ReferencesVector*> ReferencesByStringMap;

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

class FindObjectsCmd : public CommandBase {
public:
Expand Down

0 comments on commit c907d4e

Please sign in to comment.