Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: do not create global llscan or global llv8 #170

Merged
merged 2 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ using lldb::SBValue;
using lldb::eReturnStatusFailed;
using lldb::eReturnStatusSuccessFinishResult;

v8::LLV8 llv8;

char** CommandBase::ParseInspectOptions(char** cmd,
v8::Value::InspectOptions* options) {
static struct option opts[] = {
Expand Down Expand Up @@ -105,7 +103,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
}

// Load V8 constants from postmortem data
llv8.Load(target);
llv8_->Load(target);

{
SBStream desc;
Expand All @@ -124,7 +122,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,

if (!frame.GetSymbol().IsValid()) {
v8::Error err;
v8::JSFrame v8_frame(&llv8, static_cast<int64_t>(frame.GetFP()));
v8::JSFrame v8_frame(llv8_, static_cast<int64_t>(frame.GetFP()));
std::string res = v8_frame.Inspect(true, err);
if (err.Success()) {
result.Printf(" %c frame #%u: 0x%016" PRIx64 " %s\n", star, i, pc,
Expand Down Expand Up @@ -196,9 +194,9 @@ bool PrintCmd::DoExecute(SBDebugger d, char** cmd,
}

// Load V8 constants from postmortem data
llv8.Load(target);
llv8_->Load(target);

v8::Value v8_value(&llv8, value.GetValueAsSigned());
v8::Value v8_value(llv8_, value.GetValueAsSigned());
v8::Error err;
std::string res = v8_value.Inspect(&inspect_options, err);
if (err.Fail()) {
Expand Down Expand Up @@ -255,7 +253,7 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,
}

// Load V8 constants from postmortem data
llv8.Load(target);
llv8_->Load(target);
SBFrame frame = thread.GetSelectedFrame();
SBSymbol symbol = frame.GetSymbol();

Expand All @@ -279,7 +277,7 @@ bool ListCmd::DoExecute(SBDebugger d, char** cmd,

// V8 frame
v8::Error err;
v8::JSFrame v8_frame(&llv8, static_cast<int64_t>(frame.GetFP()));
v8::JSFrame v8_frame(llv8_, static_cast<int64_t>(frame.GetFP()));

const static uint32_t kDisplayLines = 4;
std::string* lines = new std::string[kDisplayLines];
Expand Down Expand Up @@ -319,26 +317,29 @@ namespace lldb {
bool PluginInitialize(SBDebugger d) {
llnode::InitDebugMode();

static llnode::v8::LLV8 llv8;
static llnode::LLScan llscan = llnode::LLScan(&llv8);

SBCommandInterpreter interpreter = d.GetCommandInterpreter();

SBCommand v8 = interpreter.AddMultiwordCommand("v8", "Node.js helpers");

v8.AddCommand(
"bt", new llnode::BacktraceCmd(),
"bt", new llnode::BacktraceCmd(&llv8),
"Show a backtrace with node.js JavaScript functions and their args. "
"An optional argument is accepted; if that argument is a number, it "
"specifies the number of frames to display. Otherwise all frames will "
"be dumped.\n\n"
"Syntax: v8 bt [number]\n");
interpreter.AddCommand("jsstack", new llnode::BacktraceCmd(),
interpreter.AddCommand("jsstack", new llnode::BacktraceCmd(&llv8),
"Alias for `v8 bt`");

v8.AddCommand("print", new llnode::PrintCmd(false),
v8.AddCommand("print", new llnode::PrintCmd(&llv8, false),
"Print short description of the JavaScript value.\n\n"
"Syntax: v8 print expr\n");

v8.AddCommand(
"inspect", new llnode::PrintCmd(true),
"inspect", new llnode::PrintCmd(&llv8, true),
"Print detailed description and contents of the JavaScript value.\n\n"
"Possible flags (all optional):\n\n"
" * -F, --full-string - print whole string without adding ellipsis\n"
Expand All @@ -348,18 +349,18 @@ bool PluginInitialize(SBDebugger d) {
"string/array\n"
"\n"
"Syntax: v8 inspect [flags] expr\n");
interpreter.AddCommand("jsprint", new llnode::PrintCmd(true),
interpreter.AddCommand("jsprint", new llnode::PrintCmd(&llv8, true),
"Alias for `v8 inspect`");

SBCommand source =
v8.AddMultiwordCommand("source", "Source code information");
source.AddCommand("list", new llnode::ListCmd(),
source.AddCommand("list", new llnode::ListCmd(&llv8),
"Print source lines around a selected JavaScript frame.\n\n"
"Syntax: v8 source list\n");
interpreter.AddCommand("jssource", new llnode::ListCmd(),
interpreter.AddCommand("jssource", new llnode::ListCmd(&llv8),
"Alias for `v8 source list`");

v8.AddCommand("findjsobjects", new llnode::FindObjectsCmd(),
v8.AddCommand("findjsobjects", new llnode::FindObjectsCmd(&llscan),
"List all object types and instance counts grouped by type "
"name and sorted by instance count. Use -d or --detailed to "
"get an output grouped by type name, properties, and array "
Expand All @@ -373,23 +374,24 @@ bool PluginInitialize(SBDebugger d) {
#endif // LLDB_SBMemoryRegionInfoList_h_
);

interpreter.AddCommand("findjsobjects", new llnode::FindObjectsCmd(),
interpreter.AddCommand("findjsobjects", new llnode::FindObjectsCmd(&llscan),
"Alias for `v8 findjsobjects`");

v8.AddCommand("findjsinstances", new llnode::FindInstancesCmd(),
v8.AddCommand("findjsinstances", new llnode::FindInstancesCmd(&llscan, false),
"List every object with the specified type name.\n"
"Use -v or --verbose to display detailed `v8 inspect` output "
"for each object.\n"
"Accepts the same options as `v8 inspect`");

interpreter.AddCommand("findjsinstances", new llnode::FindInstancesCmd(),
interpreter.AddCommand("findjsinstances",
new llnode::FindInstancesCmd(&llscan, false),
"List all objects which share the specified map.\n");

v8.AddCommand("nodeinfo", new llnode::NodeInfoCmd(),
v8.AddCommand("nodeinfo", new llnode::NodeInfoCmd(&llscan),
"Print information about Node.js\n");

v8.AddCommand(
"findrefs", new llnode::FindReferencesCmd(),
"findrefs", new llnode::FindReferencesCmd(&llscan),
"Finds all the object properties which meet the search criteria.\n"
"The default is to list all the object properties that reference the "
"specified value.\n"
Expand Down
11 changes: 10 additions & 1 deletion src/llnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,40 @@ class CommandBase : public lldb::SBCommandPluginInterface {

class BacktraceCmd : public CommandBase {
public:
BacktraceCmd(v8::LLV8* llv8) : llv8_(llv8) {}
~BacktraceCmd() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;

private:
v8::LLV8* llv8_;
};

class PrintCmd : public CommandBase {
public:
PrintCmd(bool detailed) : detailed_(detailed) {}
PrintCmd(v8::LLV8* llv8, bool detailed) : llv8_(llv8), detailed_(detailed) {}

~PrintCmd() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;

private:
v8::LLV8* llv8_;
bool detailed_;
};

class ListCmd : public CommandBase {
public:
ListCmd(v8::LLV8* llv8) : llv8_(llv8) {}
~ListCmd() override {}

bool DoExecute(lldb::SBDebugger d, char** cmd,
lldb::SBCommandReturnObject& result) override;

private:
v8::LLV8* llv8_;
};

} // namespace llnode
Expand Down
Loading