Merge branch 'debugtools' into ums-descriptor-debugger

Change-Id: I66c96be1353f186fd56c5fe3db35cf1df0e66062
diff --git a/kernel/syscalls/pager.cpp b/kernel/syscalls/pager.cpp
index 84f32d2..0d97dfc 100644
--- a/kernel/syscalls/pager.cpp
+++ b/kernel/syscalls/pager.cpp
@@ -37,8 +37,8 @@
     if(!debugVmo.get()) {
         return ZX_ERR_BAD_STATE;
     }
-    out->make(debugVmoDispatch, ZX_RIGHT_READ);
-    return ZX_OK;
+    return out->make(debugVmoDispatch, ZX_RIGHT_READ | ZX_RIGHT_MAP);
+    
 }
 
 // zx_status_t zx_pager_create
diff --git a/system/uapp/debug/main.cpp b/system/uapp/debug/main.cpp
new file mode 100644
index 0000000..fa46e47
--- /dev/null
+++ b/system/uapp/debug/main.cpp
@@ -0,0 +1,24 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <zircon/syscalls.h>
+#include <zircon/process.h>
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+    zx_handle_t output;
+    if(zx_debugger_get_vmo(&output)) {
+        printf("Unable to acquire debug VMO\n");
+    }
+    size_t vmoLen;
+    if(zx_vmo_get_size(output, &vmoLen)) {
+        printf("Failed to get VMO size\n");
+    }
+    zx_vaddr_t addr;
+    if(zx_vmar_map(zx_vmar_root_self(), ZX_VM_PERM_READ, 0, output, 0, vmoLen, &addr)) {
+        printf("Failed to map VMO into root VMAR\n");
+    }
+
+    int fd = open("/data/debug", O_WRONLY | O_CREAT);
+    write(fd, ((size_t*)addr)+1, *(size_t*)((size_t)addr));
+    return 0;
+}
\ No newline at end of file
diff --git a/system/uapp/debug/rules.mk b/system/uapp/debug/rules.mk
new file mode 100644
index 0000000..95888e6
--- /dev/null
+++ b/system/uapp/debug/rules.mk
@@ -0,0 +1,26 @@
+# Copyright 2017 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+MODULE_TYPE := userapp
+MODULE_GROUP := core
+
+MODULE_NAME := debug
+
+# app main
+MODULE_SRCS := \
+    $(LOCAL_DIR)/main.cpp \
+
+MODULE_LIBS := \
+    system/ulib/zircon \
+    system/ulib/fdio \
+    system/ulib/c
+
+MODULE_FIDL_LIBS := \
+    system/fidl/fuchsia-io \
+
+include make/module.mk