[Gd-chatter] r11172 - in trunk/fundev/sources: lib/stack-walker registry/x86-linux

andreas at gwydiondylan.org andreas at gwydiondylan.org
Sun Feb 11 22:35:22 CET 2007


Author: andreas
Date: Sun Feb 11 22:35:20 2007
New Revision: 11172

Added:
   trunk/fundev/sources/lib/stack-walker/
   trunk/fundev/sources/lib/stack-walker/getebp.c   (contents, props changed)
   trunk/fundev/sources/lib/stack-walker/library.dylan   (contents, props changed)
   trunk/fundev/sources/lib/stack-walker/stack-walker.dylan   (contents, props changed)
   trunk/fundev/sources/lib/stack-walker/stack-walker.lid   (contents, props changed)
   trunk/fundev/sources/registry/x86-linux/stack-walker   (contents, props changed)
Log:
job: fd

El cheapo stack walker for Linux.  Needs research why dladdr() doesn't
resolve Dylan functions, even though they are supported.


Added: trunk/fundev/sources/lib/stack-walker/getebp.c
==============================================================================
--- (empty file)
+++ trunk/fundev/sources/lib/stack-walker/getebp.c	Sun Feb 11 22:35:20 2007
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#define __USE_GNU
+#include <dlfcn.h>
+
+int getebp () {
+    int ebp;
+    asm("mov (%%ebp), %0"
+        :"=r"(ebp));
+    return ebp;
+};
+
+void walkstack() {
+  int ebp = getebp();
+  int eip;
+  int rc;
+  Dl_info info;
+
+  while(ebp) {
+    eip = *((int*)ebp + 1);
+    rc = dladdr((void*)eip, &info);
+    if (!rc||(!info.dli_sname && !info.dli_fname)) {
+      printf("0x%x (unknown)\n");
+    } else {
+      if (!info.dli_sname) {
+        printf("0x%x (%s)\n", eip, info.dli_fname);
+      } else {
+        printf("%s+%i (%s)\n",
+               info.dli_sname,
+	       eip - (int)info.dli_saddr,
+	       info.dli_fname);
+      }
+    }
+    ebp = *((int*)ebp);
+  }
+}

Added: trunk/fundev/sources/lib/stack-walker/library.dylan
==============================================================================
--- (empty file)
+++ trunk/fundev/sources/lib/stack-walker/library.dylan	Sun Feb 11 22:35:20 2007
@@ -0,0 +1,15 @@
+module: dylan-user
+
+define library stack-walker
+  use common-dylan;
+  use c-ffi;
+
+  export stack-walker;
+end;
+
+define module stack-walker
+  use common-dylan;
+  use c-ffi;
+
+  export walk-stack;
+end;

Added: trunk/fundev/sources/lib/stack-walker/stack-walker.dylan
==============================================================================
--- (empty file)
+++ trunk/fundev/sources/lib/stack-walker/stack-walker.dylan	Sun Feb 11 22:35:20 2007
@@ -0,0 +1,5 @@
+module: stack-walker
+
+define C-function walk-stack
+  c-name: "walkstack"
+end;

Added: trunk/fundev/sources/lib/stack-walker/stack-walker.lid
==============================================================================
--- (empty file)
+++ trunk/fundev/sources/lib/stack-walker/stack-walker.lid	Sun Feb 11 22:35:20 2007
@@ -0,0 +1,4 @@
+library: stack-walker
+c-source-files: getebp.c
+files: library
+       stack-walker

Added: trunk/fundev/sources/registry/x86-linux/stack-walker
==============================================================================
--- (empty file)
+++ trunk/fundev/sources/registry/x86-linux/stack-walker	Sun Feb 11 22:35:20 2007
@@ -0,0 +1 @@
+abstract://dylan/lib/stack-walker/stack-walker.lid



More information about the chatter mailing list