Skip to content

Commit

Permalink
src: add recursive option to findrefs command
Browse files Browse the repository at this point in the history
Introduce a new command flag to `findrefs`, command --recursive
allow user to transverse the whole references tree for the given
object.

Refs: nodejs#115
  • Loading branch information
Drieger authored and mmarchini committed Feb 25, 2019
1 parent ea06ef5 commit 4064768
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 61 deletions.
32 changes: 32 additions & 0 deletions src/llnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,34 @@ bool SetPropertyColorCmd::DoExecute(SBDebugger d, char** cmd,
return false;
}

bool SetTreePaddingCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
if (cmd == nullptr || *cmd == nullptr) {
result.SetError("USAGE: v8 settings set tree-padding [1..10]");
return false;
}
Settings* settings = Settings::GetSettings();
std::stringstream option(cmd[0]);
int padding;

// Extraction operator (>>) parses option and tries to interpret it
// as an `int` value. If an error occur, an internal state flag will be
// set. Not (!) operator will evaluate to true if `failbit` or `badbit`
// is set
if (!(option >> padding)) {
result.SetError("unable to convert provided value.");
return false;
};

// This is just an opinated range limit, to avoid negative values
// or big number, these values would produce a bad visualization experience
if (padding < 1) padding = 1;
if (padding > 10) padding = 10;
padding = settings->SetTreePadding(padding);
result.Printf("Tree padding set to %u\n", padding);
return true;
}


bool PrintCmd::DoExecute(SBDebugger d, char** cmd,
SBCommandReturnObject& result) {
Expand Down Expand Up @@ -453,6 +481,9 @@ bool PluginInitialize(SBDebugger d) {

setPropertyCmd.AddCommand("color", new llnode::SetPropertyColorCmd(),
"Set color property value");
setPropertyCmd.AddCommand("tree-padding",
new llnode::SetTreePaddingCmd(&llv8),
"Set tree-padding value");

interpreter.AddCommand("findjsobjects", new llnode::FindObjectsCmd(&llscan),
"Alias for `v8 findjsobjects`");
Expand Down Expand Up @@ -487,6 +518,7 @@ bool PluginInitialize(SBDebugger d) {
" * -n, --name name - all properties with the specified name\n"
" * -s, --string string - all properties that refer to the specified "
"JavaScript string value\n"
" * -r, --recursive - walk through references tree recursively\n"
"\n");

v8.AddCommand("getactivehandles",
Expand Down
12 changes: 12 additions & 0 deletions src/llnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class SetPropertyColorCmd : public CommandBase {
lldb::SBCommandReturnObject& result) override;
};

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

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

private:
v8::LLV8* llv8_;
};

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

0 comments on commit 4064768

Please sign in to comment.