Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Unified Diff: runtime/vm/service.cc

Issue 206583003: Add 'address' vm service message that finds heap objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/service.cc
===================================================================
--- runtime/vm/service.cc (revision 34144)
+++ runtime/vm/service.cc (working copy)
@@ -5,6 +5,7 @@
#include "vm/service.h"
#include "include/dart_api.h"
+#include "platform/globals.h"
#include "vm/compiler.h"
#include "vm/coverage.h"
@@ -1450,9 +1451,47 @@
}
+class ContainsAddressVisitor : public FindObjectVisitor {
+ public:
+ ContainsAddressVisitor(Isolate* isolate, uword addr)
+ : FindObjectVisitor(isolate), addr_(addr) { }
+ virtual ~ContainsAddressVisitor() { }
+
+ virtual uword filter_addr() const { return addr_; }
turnidge 2014/03/20 17:01:19 Is this accessor used?
koda 2014/03/20 20:25:37 Yes, it's called by the super class (FindObjectVis
+
+ virtual bool FindObject(RawObject* obj) const {
+ uword obj_begin = RawObject::ToAddr(obj);
+ uword obj_end = obj_begin + obj->Size();
+ return obj_begin <= addr_ && addr_ < obj_end;
+ }
+ private:
+ uword addr_;
+};
+
+
+static bool HandleAddress(Isolate* isolate, JSONStream* js) {
+ uword addr = 0;
+ if (js->num_arguments() != 2 ||
+ !GetUnsignedIntegerId(js->GetArgument(1), &addr, 16)) {
+ static const uword kExampleAddr = static_cast<uword>(kIntptrMax / 7);
+ PrintError(js, "Must specify address: address/" Px ".", kExampleAddr);
+ return true;
+ }
+ Object& object = Object::Handle(isolate);
+ {
+ NoGCScope no_gc;
+ ContainsAddressVisitor visitor(isolate, addr);
+ object = isolate->heap()->FindObject(&visitor);
+ }
+ object.PrintToJSONStream(js, true);
turnidge 2014/03/20 17:01:19 Printing the null object isn't the same as printin
turnidge 2014/03/20 17:08:25 Actually returning the null instance here would be
koda 2014/03/20 18:36:26 Note that we might find *any* heap object, not jus
turnidge 2014/03/20 20:34:54 I guess it depends on what the UI expects. We hav
koda 2014/03/20 20:44:19 For most objects, obj.PrintToJSONStream does tag t
+ return true;
+}
+
+
static IsolateMessageHandlerEntry isolate_handlers[] = {
{ "_echo", HandleIsolateEcho },
{ "", HandleIsolate },
+ { "address", HandleAddress },
{ "allocationprofile", HandleAllocationProfile },
{ "classes", HandleClasses },
{ "code", HandleCode },

Powered by Google App Engine
This is Rietveld 408576698