Skip to content

Commit

Permalink
src: fix findrefs for context locals
Browse files Browse the repository at this point in the history
Previous code was too strict when hitting a context which it was unable
to read Locals information: it would stop looping through the contexts
even if we still had valid contexts in the queue. Changing it to loop
through all context and all Locals in a context should give us a more
reliable results.

Also, if a given object was found in a context Locals but we're unable
to read the Local name, we'll show it as ??? to indicate it's being
referenced but we couldn't read its name (in case of corrupted memory,
for example).

Fixes: #278

PR-URL: #295
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
mmarchini committed Sep 25, 2019
1 parent 84eefb4 commit 0dbfad0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/llscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -788,17 +788,25 @@ void FindReferencesCmd::ReferenceScanner::PrintContextRefs(
v8::Context c(context_obj);

v8::Context::Locals locals(&c, err);
if (err.Fail()) return;
// If we can't read locals in this context, just go to the next.
if (err.Fail()) continue;

for (v8::Context::Locals::Iterator it = locals.begin(); it != locals.end();
it++) {
if ((*it).raw() == search_value_.raw()) {
std::string name = "???";
v8::String _name = it.LocalName(err);
if (err.Fail()) return;

std::string name = _name.ToString(err);
if (err.Fail()) return;

// TODO(mmarchini): use Check once #294 gets merged
if (err.Success()) {
std::string maybe_name = _name.ToString(err);
if (err.Success())
name = maybe_name;
else
Error::PrintInDebugMode(
"Couldn't get the variable name for 0x%" PRIx64
" in context 0x%" PRIx64,
search_value_.raw(), c.raw());
}

std::stringstream ss;
ss << rang::fg::cyan << "0x%" PRIx64 << rang::fg::reset << ": "
Expand Down

0 comments on commit 0dbfad0

Please sign in to comment.