> This patch makes parrot stop execution of the vm when running as a
> debugger.
> 
> This makes the pdb stop executing and shows the exception message
> instead of silently exiting.

Hi, pancake!

I have tried to update your patch to svn r20469, see attached patch.
Unfortunately, it doesn't work any longer.

I wrote a simple test file (see attached test.pir) that just generates
an exception.  Then I tried to run it under parrot, and it generated
an exception, as expected.

[EMAIL PROTECTED] ~/parrot $ ./parrot test.pir
Null PMC access in get_string()
current instr.: 'main' pc 0 (test.pir:3)


Problem is, when I then ran it under pdb, it died pretty horribly.


[EMAIL PROTECTED] ~/parrot $ ./pdb test.pir
Parrot Debugger 0.4.x

Please note: the debugger is currently under reconstruction

(pdb) r
Restarting
Hijacked exception: Null PMC access in get_string()
Restarting
*** glibc detected *** ./pdb: free(): invalid pointer: 0xb6f191b8 ***
======= Backtrace: =========
/lib/libc.so.6[0xb6e4efaf]
/lib/libc.so.6(__libc_free+0x89)[0xb6e4fce9]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(mem_sys_free+0x23)[0xb7c3b9b3]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(PDB_free_file+0x98)[0xb7c2eb38]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(PDB_disassemble+0x62)[0xb7c2e712]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(Parrot_debug+0x65)[0xb7c31c85]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(runops_slow_core+0x60)[0xb7c76130]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(runops_int+0x190)[0xb7c46b80]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(runops+0xfd)[0xb7c474cd]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14[0xb7c476e6]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(Parrot_runops_fromc_args+0x36)[0xb7c477f6]
/home/paranoid/parrot/blib/lib/libparrot.so.0.4.14(Parrot_runcode+0x22f)[0xb7c31c0f]
./pdb(main+0x2d2)[0x8048f22]
/lib/libc.so.6(__libc_start_main+0xe2)[0xb6dfe9d2]
./pdb[0x8048bb1]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 fe:03 636705     /home/paranoid/parrot/pdb
0804a000-0804b000 rw-p 00001000 fe:03 636705     /home/paranoid/parrot/pdb
0804b000-08410000 rw-p 0804b000 00:00 0          [heap]
b5b00000-b5b21000 rw-p b5b00000 00:00 0
b5b21000-b5c00000 ---p b5b21000 00:00 0
b5cca000-b5d0c000 rw-p b5cca000 00:00 0
b5d0c000-b5d0d000 ---p b5d0c000 00:00 0
b5d0d000-b650d000 rw-p b5d0d000 00:00 0
b650d000-b650e000 ---p b650d000 00:00 0
b650e000-b6d10000 rw-p b650e000 00:00 0
b6d10000-b6d18000 r-xp 00000000 fe:00 292092     
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.4.6/libgcc_s.so.1
b6d18000-b6d19000 rw-p 00007000 fe:00 292092     
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.4.6/libgcc_s.so.1
b6d19000-b6ddf000 r-xp 00000000 fe:00 292103     
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.4.6/libstdc++.so.6.0.3
b6ddf000-b6de4000 rw-p 000c6000 fe:00 292103     
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.4.6/libstdc++.so.6.0.3
b6de4000-b6de9000 rw-p b6de4000 00:00 0
b6de9000-b6f16000 r-xp 00000000 03:01 40041      /lib/libc-2.6.so
b6f16000-b6f17000 r--p 0012d000 03:01 40041      /lib/libc-2.6.so
b6f17000-b6f19000 rw-p 0012e000 03:01 40041      /lib/libc-2.6.so
b6f19000-b6f1c000 rw-p b6f19000 00:00 0
b6f1c000-b6f57000 r-xp 00000000 03:01 6397       /lib/libncurses.so.5.6
b6f57000-b6f60000 rw-p 0003a000 03:01 6397       /lib/libncurses.so.5.6
b6f60000-b6f8c000 r-xp 00000000 03:01 20277      /lib/libreadline.so.5.2
b6f8c000-b6f90000 rw-p 0002b000 03:01 20277      /lib/libreadline.so.5.2
b6f90000-b6f92000 rw-p b6f90000 00:00 0
b6f92000-b6fc3000 r-xp 00000000 fe:00 7746       /usr/lib/libgmp.so.3.4.1
b6fc3000-b6fc4000 rw-p 00031000 fe:00 7746       /usr/lib/libgmp.so.3.4.1
b6fc4000-b6fcb000 r-xp 00000000 03:01 35535      /lib/librt-2.6.so
b6fcb000-b6fcd000 rw-p 00006000 03:01 35535      /lib/librt-2.6.so
b6fcd000-b6fcf000 r-xp 00000000 03:01 40037      /lib/libutil-2.6.so
b6fcf000-b6fd1000 rw-p 00001000 03:01 40037      /lib/libutil-2.6.so
b6fd1000-b6fd6000 r-xp 00000000 03:01 40035      /lib/libcrypt-2.6.so
b6fd6000-b6fd8000 rw-p 00004000 03:01 40035      /lib/libcrypt-2.6.so
b6fd8000-b6fff000 rw-p b6fd8000 00:00 0
b6fff000-b7001000 r-xp 00000000 03:01 40028      /lib/libdl-2.6.so
b7001000-b7003000 rw-p 00001000 03:01 40028      /lib/libdl-2.6.so
b7003000-b7016000 r-xp 00000000 03:01 6394       /lib/libnsl-2.6.so
b7016000-b7018000 rw-p 00012000 03:01 6394       /lib/libnsl-2.6.so
b7018000-b701b000 rw-p b7018000 00:00 0
b701b000-b79ca000 r--p 00000000 fe:00 384232     /usr/lib/libicudata.so.36.0
b79ca000-b79cb000 rw-p 009ae000 fe:00 384232     /usr/lib/libicudata.so.36.0
b79cb000-b7adc000 r-xp 00000000 fe:00 403052     /usr/lib/libicuuc.so.36.0
b7adc000-b7ae3000 rw-p 00111000 fe:00 403052     /usr/lib/libicuuc.so.36.0
b7ae3000-b7ae5000 rw-p b7ae3000 00:00 0
b7ae5000-b7b08000 r-xp 00000000 03:01 40040      /lib/liAborted
[EMAIL PROTECTED] ~/parrot $


It's a useful patch, and I think it *almost* works.  Maybe pdb itself
is broken.

Also note I've created a test program[1] for pdb, at t/tools/pdb.t.
It's pretty minimal thus far, but if I can find a fix for this, I'll
add a test for exception handling.

Mark

[1]: There, Andy, are you happy?  I avoided using the word "script"!
Index: src/exceptions.c
===================================================================
--- src/exceptions.c	(revision 20469)
+++ src/exceptions.c	(working copy)
@@ -406,10 +406,22 @@
 throw_exception(PARROT_INTERP, PMC *exception, SHIM(void *dest))
 {
     opcode_t *address;
-    PMC * const handler = find_exception_handler(interp, exception);
+    PMC * handler;
 
+    /* debugger hook */
+    if (interp->debugger) {
+        STRING * const message = VTABLE_get_string_keyed_int(interp, exception, 0);
+    	char *m = string_to_cstring(interp, message);
+        printf("Hijacked exception: %s\n", m);
+	/* TODO: interface for deciding what to do with the exception (ignore, ...) */
+	interp->pdb->state |= PDB_STOPPED;
+	return NULL; 
+    }
+
+    handler = find_exception_handler(interp, exception);
     if (!handler)
         return NULL;
+
     /* put the handler aka continuation ctx in the interpreter */
     address = VTABLE_invoke(interp, handler, exception);
     /* address = VTABLE_get_pointer(interp, handler); */
@@ -564,10 +576,7 @@
 size_t
 handle_exception(PARROT_INTERP)
 {
-    /* absolute address of handler */
-    const opcode_t * const dest = create_exception(interp);
-
-    return dest2offset(interp, dest);
+    return dest2offset(interp, create_exception(interp));
 }
 
 /*

Attachment: test.pir
Description: Binary data

Reply via email to