Skip to content

Commit 0dbfad0

Browse files
committed
src: fix findrefs for context locals
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 <[email protected]>
1 parent 84eefb4 commit 0dbfad0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/llscan.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,17 +788,25 @@ void FindReferencesCmd::ReferenceScanner::PrintContextRefs(
788788
v8::Context c(context_obj);
789789

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

793794
for (v8::Context::Locals::Iterator it = locals.begin(); it != locals.end();
794795
it++) {
795796
if ((*it).raw() == search_value_.raw()) {
797+
std::string name = "???";
796798
v8::String _name = it.LocalName(err);
797-
if (err.Fail()) return;
798-
799-
std::string name = _name.ToString(err);
800-
if (err.Fail()) return;
801-
799+
// TODO(mmarchini): use Check once #294 gets merged
800+
if (err.Success()) {
801+
std::string maybe_name = _name.ToString(err);
802+
if (err.Success())
803+
name = maybe_name;
804+
else
805+
Error::PrintInDebugMode(
806+
"Couldn't get the variable name for 0x%" PRIx64
807+
" in context 0x%" PRIx64,
808+
search_value_.raw(), c.raw());
809+
}
802810

803811
std::stringstream ss;
804812
ss << rang::fg::cyan << "0x%" PRIx64 << rang::fg::reset << ": "

0 commit comments

Comments
 (0)