Skip to content

Commit aad5414

Browse files
Driegermmarchini
authored andcommitted
src: add recursive option to findrefs command
Introduce a new command flag to `findrefs`, command --recursive allow user to transverse the whole references tree for the given object. Refs: #115 PR-URL: #244 Reviewed-By: Matheus Marchini <mat@mmarchini.me>
1 parent 85f067a commit aad5414

File tree

9 files changed

+350
-61
lines changed

9 files changed

+350
-61
lines changed

src/llnode.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@ bool SetPropertyColorCmd::DoExecute(SBDebugger d, char** cmd,
134134
return false;
135135
}
136136

137+
bool SetTreePaddingCmd::DoExecute(SBDebugger d, char** cmd,
138+
SBCommandReturnObject& result) {
139+
if (cmd == nullptr || *cmd == nullptr) {
140+
result.SetError("USAGE: v8 settings set tree-padding [1..10]");
141+
return false;
142+
}
143+
Settings* settings = Settings::GetSettings();
144+
std::stringstream option(cmd[0]);
145+
int padding;
146+
147+
// Extraction operator (>>) parses option and tries to interpret it
148+
// as an `int` value. If an error occur, an internal state flag will be
149+
// set. Not (!) operator will evaluate to true if `failbit` or `badbit`
150+
// is set
151+
if (!(option >> padding)) {
152+
result.SetError("unable to convert provided value.");
153+
return false;
154+
};
155+
156+
// This is just an opinated range limit, to avoid negative values
157+
// or big number, these values would produce a bad visualization experience
158+
if (padding < 1) padding = 1;
159+
if (padding > 10) padding = 10;
160+
padding = settings->SetTreePadding(padding);
161+
result.Printf("Tree padding set to %u\n", padding);
162+
return true;
163+
}
164+
137165

138166
bool PrintCmd::DoExecute(SBDebugger d, char** cmd,
139167
SBCommandReturnObject& result) {
@@ -451,6 +479,9 @@ bool PluginInitialize(SBDebugger d) {
451479

452480
setPropertyCmd.AddCommand("color", new llnode::SetPropertyColorCmd(),
453481
"Set color property value");
482+
setPropertyCmd.AddCommand("tree-padding",
483+
new llnode::SetTreePaddingCmd(&llv8),
484+
"Set tree-padding value");
454485

455486
interpreter.AddCommand("findjsobjects", new llnode::FindObjectsCmd(&llscan),
456487
"Alias for `v8 findjsobjects`");
@@ -485,6 +516,7 @@ bool PluginInitialize(SBDebugger d) {
485516
" * -n, --name name - all properties with the specified name\n"
486517
" * -s, --string string - all properties that refer to the specified "
487518
"JavaScript string value\n"
519+
" * -r, --recursive - walk through references tree recursively\n"
488520
"\n");
489521

490522
v8.AddCommand("getactivehandles",

src/llnode.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ class SetPropertyColorCmd : public CommandBase {
3030
lldb::SBCommandReturnObject& result) override;
3131
};
3232

33+
class SetTreePaddingCmd : public CommandBase {
34+
public:
35+
SetTreePaddingCmd(v8::LLV8* llv8) : llv8_(llv8) {}
36+
~SetTreePaddingCmd() override {}
37+
38+
bool DoExecute(lldb::SBDebugger d, char** cmd,
39+
lldb::SBCommandReturnObject& result) override;
40+
41+
private:
42+
v8::LLV8* llv8_;
43+
};
44+
3345
class PrintCmd : public CommandBase {
3446
public:
3547
PrintCmd(v8::LLV8* llv8, bool detailed) : llv8_(llv8), detailed_(detailed) {}

0 commit comments

Comments
 (0)