unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
@ 2022-09-20  7:23 Andrew Whatson
  2022-09-21 10:50 ` Maxime Devos
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Whatson @ 2022-09-20  7:23 UTC (permalink / raw)
  To: guile-devel; +Cc: Andrew Whatson

Workaround for <https://bugs.gnu.org/57948>.

* module/system/vm/frame.scm (frame-call-representation): Treat a
binding as "unspecified" if its slot exceeds 'frame-num-locals'.
---
 module/system/vm/frame.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/module/system/vm/frame.scm b/module/system/vm/frame.scm
index 3be73e29c..6b14fc62a 100644
--- a/module/system/vm/frame.scm
+++ b/module/system/vm/frame.scm
@@ -381,8 +381,16 @@
         (frame-local-ref frame i 'scm))
        ((find-slot i bindings)
         => (lambda (binding)
-             (let ((val (frame-local-ref frame (binding-slot binding)
-                                         (binding-representation binding))))
+             (let* ((slot (binding-slot binding))
+                    ;; HACK: Avoid out-of-range from frame-local-ref.
+                    ;; Some frames have bindings beyond nlocals.  That
+                    ;; is probably a bug somewhere else, but at least
+                    ;; this workaround allows them to be printed.
+                    (val (if (< slot nlocals)
+                             (frame-local-ref frame slot
+                                              (binding-representation binding))
+                             ;; else #<unspecified>
+                             )))
                ;; It could be that there's a value that isn't clobbered
                ;; by a call but that isn't live after a call either.  In
                ;; that case, if GC runs during the call, the value will
-- 
2.37.3




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-20  7:23 [PATCH] Avoid 'frame-local-ref' errors when printing backtrace Andrew Whatson
@ 2022-09-21 10:50 ` Maxime Devos
  2022-09-22 13:53   ` Andrew Whatson
  2022-09-22 13:58   ` Andrew Whatson
  0 siblings, 2 replies; 12+ messages in thread
From: Maxime Devos @ 2022-09-21 10:50 UTC (permalink / raw)
  To: Andrew Whatson, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1264 bytes --]



On 20-09-2022 09:23, Andrew Whatson wrote:
>           => (lambda (binding)
> -             (let ((val (frame-local-ref frame (binding-slot binding)
> -                                         (binding-representation binding))))
> +             (let* ((slot (binding-slot binding))
> +                    ;; HACK: Avoid out-of-range from frame-local-ref.
> +                    ;; Some frames have bindings beyond nlocals.  That
> +                    ;; is probably a bug somewhere else, but at least
> +                    ;; this workaround allows them to be printed.
> +                    (val (if (< slot nlocals)
> +                             (frame-local-ref frame slot
> +                                              (binding-representation binding))
> +                             ;; else #<unspecified > +                             )))

I propose to add a link to the bug report in the comments, for future 
reference.  Also, there is an interest in returning zero values in such 
cases: <https://www.mail-archive.com/bug-guile@gnu.org/msg07927.html> 
(that patch didn't work out, but the sentiment is still there).

As such, I recommend being explicit:

(if [...]
     [...]
     *unspecified*)

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-21 10:50 ` Maxime Devos
@ 2022-09-22 13:53   ` Andrew Whatson
  2022-09-22 15:10     ` Maxime Devos
                       ` (2 more replies)
  2022-09-22 13:58   ` Andrew Whatson
  1 sibling, 3 replies; 12+ messages in thread
From: Andrew Whatson @ 2022-09-22 13:53 UTC (permalink / raw)
  To: guile-devel; +Cc: Andrew Whatson

Workaround for <https://bugs.gnu.org/57948>.

* module/system/vm/frame.scm (frame-call-representation): Treat a
binding as "unspecified" if its slot exceeds 'frame-num-locals'.
---
 module/system/vm/frame.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/module/system/vm/frame.scm b/module/system/vm/frame.scm
index 3be73e29c..e36eb797c 100644
--- a/module/system/vm/frame.scm
+++ b/module/system/vm/frame.scm
@@ -381,8 +381,16 @@
         (frame-local-ref frame i 'scm))
        ((find-slot i bindings)
         => (lambda (binding)
-             (let ((val (frame-local-ref frame (binding-slot binding)
-                                         (binding-representation binding))))
+             (let* ((slot (binding-slot binding))
+                    ;; HACK: Avoid out-of-range from frame-local-ref.
+                    ;; Some frames have bindings beyond nlocals.  That
+                    ;; is probably a bug somewhere else, but at least
+                    ;; this workaround allows them to be printed.
+                    ;; See <https://bugs.gnu.org/57948>.
+                    (val (if (< slot nlocals)
+                             (frame-local-ref frame slot
+                                              (binding-representation binding))
+                             *unspecified*)))
                ;; It could be that there's a value that isn't clobbered
                ;; by a call but that isn't live after a call either.  In
                ;; that case, if GC runs during the call, the value will
-- 
2.37.3




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-21 10:50 ` Maxime Devos
  2022-09-22 13:53   ` Andrew Whatson
@ 2022-09-22 13:58   ` Andrew Whatson
  1 sibling, 0 replies; 12+ messages in thread
From: Andrew Whatson @ 2022-09-22 13:58 UTC (permalink / raw)
  To: Maxime Devos; +Cc: guile-devel

Maxime Devos <maximedevos@telenet.be> wrote:
>
> I propose to add a link to the bug report in the comments, for future
> reference.  Also, there is an interest in returning zero values in such
> cases: <https://www.mail-archive.com/bug-guile@gnu.org/msg07927.html>
> (that patch didn't work out, but the sentiment is still there).
>
> As such, I recommend being explicit:
>
> (if [...]
>      [...]
>      *unspecified*)

Done and done!  Thanks for the review :)



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-22 13:53   ` Andrew Whatson
@ 2022-09-22 15:10     ` Maxime Devos
  2022-10-12 20:34     ` Ludovic Courtès
  2022-11-29 18:06     ` lloda
  2 siblings, 0 replies; 12+ messages in thread
From: Maxime Devos @ 2022-09-22 15:10 UTC (permalink / raw)
  To: Andrew Whatson, guile-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 982 bytes --]



On 22-09-2022 15:53, Andrew Whatson wrote:
> -             (let ((val (frame-local-ref frame (binding-slot binding)
> -                                         (binding-representation binding))))
> +             (let* ((slot (binding-slot binding))
> +                    ;; HACK: Avoid out-of-range from frame-local-ref.
> +                    ;; Some frames have bindings beyond nlocals.  That
> +                    ;; is probably a bug somewhere else, but at least
> +                    ;; this workaround allows them to be printed.
> +                    ;; See<https://bugs.gnu.org/57948>.
> +                    (val (if (< slot nlocals)
> +                             (frame-local-ref frame slot
> +                                              (binding-representation binding))
> +*unspecified*)))

Looks reasonable from here, FWIW (I'm not familiar with (system vm frame)).

(Please keep in mind I do not have commit access.)

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-22 13:53   ` Andrew Whatson
  2022-09-22 15:10     ` Maxime Devos
@ 2022-10-12 20:34     ` Ludovic Courtès
  2022-10-13  3:36       ` Andrew Whatson
  2023-01-11  5:24       ` Andrew Whatson
  2022-11-29 18:06     ` lloda
  2 siblings, 2 replies; 12+ messages in thread
From: Ludovic Courtès @ 2022-10-12 20:34 UTC (permalink / raw)
  To: Andrew Whatson; +Cc: guile-devel, 57948

Hi Andrew,

Andrew Whatson <whatson@gmail.com> skribis:

> Workaround for <https://bugs.gnu.org/57948>.
>
> * module/system/vm/frame.scm (frame-call-representation): Treat a
> binding as "unspecified" if its slot exceeds 'frame-num-locals'.

Yay, great to see that fixed (or almost)!

It would be great if you could add a simple test case though, so that
the bug doesn’t eventually come back to haunt us.

Could you send an updated patch?

Thanks,
Ludo’.

PS: BTW, it’ll be great to have more patches from you!  :-) To that end,
    please check out the new Guile copyright policy and let us know what
    option you’d like to choose:
    <https://lists.gnu.org/archive/html/guile-devel/2022-10/msg00008.html>.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-10-12 20:34     ` Ludovic Courtès
@ 2022-10-13  3:36       ` Andrew Whatson
  2022-10-13 13:09         ` Ludovic Courtès
  2023-01-11  5:24       ` Andrew Whatson
  1 sibling, 1 reply; 12+ messages in thread
From: Andrew Whatson @ 2022-10-13  3:36 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel, 57948

Ludovic Courtès <ludo@gnu.org> wrote:
>
> It would be great if you could add a simple test case though, so that
> the bug doesn’t eventually come back to haunt us.
>
> Could you send an updated patch?

Ah yes, getting this covered in a test is on my list.  I had trouble
writing a reproducer previously, I think the bug might only occur in a
nested compilation context (top-level error compiling a dependency
module), but I'll have another go.

> PS: BTW, it’ll be great to have more patches from you!  :-) To that end,
>     please check out the new Guile copyright policy and let us know what
>     option you’d like to choose:
>     <https://lists.gnu.org/archive/html/guile-devel/2022-10/msg00008.html>.

I have already assigned copyright of my work on Guile to the FSF,
happy for that to remain.

That said, I'm glad to see this requirement being eased!

Cheers,
Andrew



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-10-13  3:36       ` Andrew Whatson
@ 2022-10-13 13:09         ` Ludovic Courtès
  0 siblings, 0 replies; 12+ messages in thread
From: Ludovic Courtès @ 2022-10-13 13:09 UTC (permalink / raw)
  To: Andrew Whatson; +Cc: guile-devel, 57948

Hi,

Andrew Whatson <whatson@gmail.com> skribis:

> Ludovic Courtès <ludo@gnu.org> wrote:
>>
>> It would be great if you could add a simple test case though, so that
>> the bug doesn’t eventually come back to haunt us.
>>
>> Could you send an updated patch?
>
> Ah yes, getting this covered in a test is on my list.  I had trouble
> writing a reproducer previously, I think the bug might only occur in a
> nested compilation context (top-level error compiling a dependency
> module), but I'll have another go.

Awesome.

>> PS: BTW, it’ll be great to have more patches from you!  :-) To that end,
>>     please check out the new Guile copyright policy and let us know what
>>     option you’d like to choose:
>>     <https://lists.gnu.org/archive/html/guile-devel/2022-10/msg00008.html>.
>
> I have already assigned copyright of my work on Guile to the FSF,
> happy for that to remain.

Oh sorry I had overlooked that, perfect!

Thanks,
Ludo’.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-09-22 13:53   ` Andrew Whatson
  2022-09-22 15:10     ` Maxime Devos
  2022-10-12 20:34     ` Ludovic Courtès
@ 2022-11-29 18:06     ` lloda
  2 siblings, 0 replies; 12+ messages in thread
From: lloda @ 2022-11-29 18:06 UTC (permalink / raw)
  To: Andrew Whatson; +Cc: guile-devel


Pushed to c7fa78fc751eb336bcfafbb5ac59c460ee2c5d7a.

Thank you!



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2022-10-12 20:34     ` Ludovic Courtès
  2022-10-13  3:36       ` Andrew Whatson
@ 2023-01-11  5:24       ` Andrew Whatson
  2023-01-11 23:03         ` Ludovic Courtès
  1 sibling, 1 reply; 12+ messages in thread
From: Andrew Whatson @ 2023-01-11  5:24 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel, 57948

[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

Ludovic Courtès <ludo@gnu.org> wrote:
>
> It would be great if you could add a simple test case though, so that
> the bug doesn’t eventually come back to haunt us.

I've finally tracked this one down, a patch with a unit test for this
bug is attached.

Cheers,
Andrew

[-- Attachment #2: test-frame-local-ref-error.patch --]
[-- Type: text/x-patch, Size: 2111 bytes --]

commit 164bdce6acf53796cb96ef1930a89c6caf84bc39
Author: Andrew Whatson <whatson@gmail.com>
Date:   Wed Jan 11 14:04:32 2023 +1000

    Test for 'frame-local-ref' errors when printing backtrace.
    
    This test reproduces the error from <https://bugs.gnu.org/56493>, and
    passes with the workaround which was merged in commit
    c7fa78fc751eb336bcfafbb5ac59c460ee2c5d7a.
    
    * test-suite/tests/eval.test ("avoid frame-local-ref out of range"): New
    test.

diff --git a/test-suite/tests/eval.test b/test-suite/tests/eval.test
index 9d20812f2..316153385 100644
--- a/test-suite/tests/eval.test
+++ b/test-suite/tests/eval.test
@@ -22,6 +22,7 @@
   :use-module ((system vm vm) :select (call-with-stack-overflow-handler))
   :use-module ((system vm frame) :select (frame-call-representation))
   :use-module (ice-9 documentation)
+  :use-module (ice-9 exceptions)
   :use-module (ice-9 local-eval))
 
 
@@ -387,7 +388,27 @@
       (and (eq? (car (frame-call-representation (car frames)))
                 'make-stack)
            (eq? (car (frame-call-representation (car (last-pair frames))))
-                'with-exception-handler)))))
+                'with-exception-handler))))
+
+  (pass-if "avoid frame-local-ref out of range"
+    (with-exception-handler
+        (lambda (ex)
+          ;; If frame-call-representation fails, we'll catch that
+          ;; instead of the expected "Wrong type to apply" error.
+          (string-prefix? "Wrong type to apply" (exception-message ex)))
+      (lambda ()
+        (with-exception-handler
+            (lambda (ex)
+              (let* ((stack (make-stack #t))
+                     (frames (stack->frames stack)))
+                (for-each frame-call-representation frames))
+              (raise-exception ex))
+          (lambda ()
+            ;; This throws a "Wrong type to apply" error, creating a
+            ;; frame with an incorrect number of local slots as
+            ;; described in bug <https://bugs.gnu.org/56493>.
+            (primitive-eval '(define foo (#t))))))
+      #:unwind? #t)))
 
 ;;;
 ;;; letrec init evaluation

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2023-01-11  5:24       ` Andrew Whatson
@ 2023-01-11 23:03         ` Ludovic Courtès
  2023-01-12  2:09           ` Andrew Whatson
  0 siblings, 1 reply; 12+ messages in thread
From: Ludovic Courtès @ 2023-01-11 23:03 UTC (permalink / raw)
  To: Andrew Whatson; +Cc: guile-devel, 57948-done, lloda

Hi,

Andrew Whatson <whatson@gmail.com> skribis:

> commit 164bdce6acf53796cb96ef1930a89c6caf84bc39
> Author: Andrew Whatson <whatson@gmail.com>
> Date:   Wed Jan 11 14:04:32 2023 +1000
>
>     Test for 'frame-local-ref' errors when printing backtrace.
>     
>     This test reproduces the error from <https://bugs.gnu.org/56493>, and
>     passes with the workaround which was merged in commit
>     c7fa78fc751eb336bcfafbb5ac59c460ee2c5d7a.
>     
>     * test-suite/tests/eval.test ("avoid frame-local-ref out of range"): New
>     test.

Applied, thanks!

Ludo’.

PS: Please use ‘git format-patch’ so the patch can be directly consumed
    by ‘git am’.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] Avoid 'frame-local-ref' errors when printing backtrace.
  2023-01-11 23:03         ` Ludovic Courtès
@ 2023-01-12  2:09           ` Andrew Whatson
  0 siblings, 0 replies; 12+ messages in thread
From: Andrew Whatson @ 2023-01-12  2:09 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel, 57948-done, lloda

Ludovic Courtès <ludo@gnu.org> wrote:
>
> Applied, thanks!

Thank you!

> PS: Please use ‘git format-patch’ so the patch can be directly consumed
>     by ‘git am’.

My mistake, sorry about that.  Noted for next time :)

Cheers,
Andrew



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-01-12  2:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20  7:23 [PATCH] Avoid 'frame-local-ref' errors when printing backtrace Andrew Whatson
2022-09-21 10:50 ` Maxime Devos
2022-09-22 13:53   ` Andrew Whatson
2022-09-22 15:10     ` Maxime Devos
2022-10-12 20:34     ` Ludovic Courtès
2022-10-13  3:36       ` Andrew Whatson
2022-10-13 13:09         ` Ludovic Courtès
2023-01-11  5:24       ` Andrew Whatson
2023-01-11 23:03         ` Ludovic Courtès
2023-01-12  2:09           ` Andrew Whatson
2022-11-29 18:06     ` lloda
2022-09-22 13:58   ` Andrew Whatson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).