summaryrefslogtreecommitdiff
path: root/vm_dump.c
diff options
context:
space:
mode:
authorDavid CARLIER <devnexen@gmail.com>2019-08-19 09:36:28 +0100
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-08-19 17:36:28 +0900
commit6dd9736c3a73ecd9b0dcf47348a81fb934eb88b3 (patch)
tree0f495573266b8c4c82c826223a4ef81fab20b9a2 /vm_dump.c
parent605d2ce9b98c4306505c8be05483e3d296db5f1e (diff)
crash report on mac little update
displaying vm info as Linux and FreeBSD. checking libproc as it is present only from 10.5 version. https://github.com/ruby/ruby/pull/2384
Diffstat (limited to 'vm_dump.c')
-rw-r--r--vm_dump.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/vm_dump.c b/vm_dump.c
index 47e6776d8a..8ae55aa335 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -16,6 +16,16 @@
#ifdef HAVE_UCONTEXT_H
#include <ucontext.h>
#endif
+#ifdef __APPLE__
+#ifdef HAVE_LIBPROC_H
+#include <libproc.h>
+#endif
+#include <mach/vm_map.h>
+#include <mach/mach_init.h>
+#ifdef __LP64__
+#define vm_region_recurse vm_region_recurse_64
+#endif
+#endif
/* see vm_insnhelper.h for the values */
#ifndef VMDEBUG
@@ -984,6 +994,41 @@ rb_vm_bugreport(const void *ctx)
fprintf(stderr, "\n");
}
#endif /* __FreeBSD__ */
+#ifdef __APPLE__
+ vm_address_t addr = 0;
+ vm_size_t size = 0;
+ struct vm_region_submap_info map;
+ mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT;
+ natural_t depth = 0;
+
+ fprintf(stderr, "* Process memory map:\n\n");
+ while (1) {
+ if (vm_region_recurse(mach_task_self(), &addr, &size, &depth,
+ (vm_region_recurse_info_t)&map, &count) != KERN_SUCCESS) {
+ break;
+ }
+
+ if (map.is_submap) {
+ // We only look at main addresses
+ depth++;
+ } else {
+ fprintf(stderr, "%lx-%lx %s%s%s", addr, (addr+size),
+ ((map.protection & VM_PROT_READ) != 0 ? "r" : "-"),
+ ((map.protection & VM_PROT_WRITE) != 0 ? "w" : "-"),
+ ((map.protection & VM_PROT_EXECUTE) != 0 ? "x" : "-"));
+#ifdef HAVE_LIBPROC_H
+ char buff[PATH_MAX];
+ if (proc_regionfilename(getpid(), addr, buff, sizeof(buff)) > 0) {
+ fprintf(stderr, " %s", buff);
+ }
+#endif
+ fprintf(stderr, "\n");
+ }
+
+ addr += size;
+ size = 0;
+ }
+#endif
}
}