Skip to content

Commit 362b36a

Browse files
committed
src: do not create global llscan or global llv8
- Eliminates all references to the global llscan in the commands, only instantiate one LLScan instance in llnode.cc and pass it down to all commands. - Eliminates all references to the global llv8, store it inside the LLScan instead, because LLScan must need a valid llv8 (with postmortem metadata loaded) to function. - Only instantiate a static LLScan and a static LLV8 during plugin initialization.
1 parent 98f22d8 commit 362b36a

File tree

4 files changed

+120
-85
lines changed

4 files changed

+120
-85
lines changed

src/llnode.cc

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ using lldb::SBValue;
2727
using lldb::eReturnStatusFailed;
2828
using lldb::eReturnStatusSuccessFinishResult;
2929

30-
v8::LLV8 llv8;
31-
3230
char** CommandBase::ParseInspectOptions(char** cmd,
3331
v8::Value::InspectOptions* options) {
3432
static struct option opts[] = {
@@ -105,7 +103,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
105103
}
106104

107105
// Load V8 constants from postmortem data
108-
llv8.Load(target);
106+
llv8_->Load(target);
109107

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

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

198196
// Load V8 constants from postmortem data
199-
llv8.Load(target);
197+
llv8_->Load(target);
200198

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

257255
// Load V8 constants from postmortem data
258-
llv8.Load(target);
256+
llv8_->Load(target);
259257
SBFrame frame = thread.GetSelectedFrame();
260258
SBSymbol symbol = frame.GetSymbol();
261259

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

280278
// V8 frame
281279
v8::Error err;
282-
v8::JSFrame v8_frame(&llv8, static_cast<int64_t>(frame.GetFP()));
280+
v8::JSFrame v8_frame(llv8_, static_cast<int64_t>(frame.GetFP()));
283281

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

320+
static llnode::v8::LLV8 llv8;
321+
static llnode::LLScan llscan = llnode::LLScan(&llv8);
322+
322323
SBCommandInterpreter interpreter = d.GetCommandInterpreter();
323324

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

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

336-
v8.AddCommand("print", new llnode::PrintCmd(false),
337+
v8.AddCommand("print", new llnode::PrintCmd(&llv8, false),
337338
"Print short description of the JavaScript value.\n\n"
338339
"Syntax: v8 print expr\n");
339340

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

354355
SBCommand source =
355356
v8.AddMultiwordCommand("source", "Source code information");
356-
source.AddCommand("list", new llnode::ListCmd(),
357+
source.AddCommand("list", new llnode::ListCmd(&llv8),
357358
"Print source lines around a selected JavaScript frame.\n\n"
358359
"Syntax: v8 source list\n");
359-
interpreter.AddCommand("jssource", new llnode::ListCmd(),
360+
interpreter.AddCommand("jssource", new llnode::ListCmd(&llv8),
360361
"Alias for `v8 source list`");
361362

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

376-
interpreter.AddCommand("findjsobjects", new llnode::FindObjectsCmd(),
377+
interpreter.AddCommand("findjsobjects", new llnode::FindObjectsCmd(&llscan),
377378
"Alias for `v8 findjsobjects`");
378379

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

385-
interpreter.AddCommand("findjsinstances", new llnode::FindInstancesCmd(),
386+
interpreter.AddCommand("findjsinstances",
387+
new llnode::FindInstancesCmd(&llscan, false),
386388
"List all objects which share the specified map.\n");
387389

388-
v8.AddCommand("nodeinfo", new llnode::NodeInfoCmd(),
390+
v8.AddCommand("nodeinfo", new llnode::NodeInfoCmd(&llscan),
389391
"Print information about Node.js\n");
390392

391393
v8.AddCommand(
392-
"findrefs", new llnode::FindReferencesCmd(),
394+
"findrefs", new llnode::FindReferencesCmd(&llscan),
393395
"Finds all the object properties which meet the search criteria.\n"
394396
"The default is to list all the object properties that reference the "
395397
"specified value.\n"

src/llnode.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,40 @@ class CommandBase : public lldb::SBCommandPluginInterface {
1616

1717
class BacktraceCmd : public CommandBase {
1818
public:
19+
BacktraceCmd(v8::LLV8* llv8) : llv8_(llv8) {}
1920
~BacktraceCmd() override {}
2021

2122
bool DoExecute(lldb::SBDebugger d, char** cmd,
2223
lldb::SBCommandReturnObject& result) override;
24+
25+
private:
26+
v8::LLV8* llv8_;
2327
};
2428

2529
class PrintCmd : public CommandBase {
2630
public:
27-
PrintCmd(bool detailed) : detailed_(detailed) {}
31+
PrintCmd(v8::LLV8* llv8, bool detailed) : llv8_(llv8), detailed_(detailed) {}
2832

2933
~PrintCmd() override {}
3034

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

3438
private:
39+
v8::LLV8* llv8_;
3540
bool detailed_;
3641
};
3742

3843
class ListCmd : public CommandBase {
3944
public:
45+
ListCmd(v8::LLV8* llv8) : llv8_(llv8) {}
4046
~ListCmd() override {}
4147

4248
bool DoExecute(lldb::SBDebugger d, char** cmd,
4349
lldb::SBCommandReturnObject& result) override;
50+
51+
private:
52+
v8::LLV8* llv8_;
4453
};
4554

4655
} // namespace llnode

0 commit comments

Comments
 (0)