Forum > General

SetJmp / LongJmp results in Illegal Instruction: 4

(1/5) > >>

pleumann:
Hi,

I am trying to improve the error handling in my project using SetJump/LongJmp. The simple example

https://www.freepascal.org/docs-html/rtl/system/setjmp.html

from the docs works fine, but if I do exactly the same in my (much more complex) code the resulting binary stops with "Illegal Instruction: 4" when the LongJump is being executed. I have no idea what this means or how to solve it.

I'm using FPC 3.2.2 with MacOS 12.1 running on a Mac with M1 processor. Any pointers are appreciated.

Cheers
Joerg

440bx:

--- Quote from: pleumann on May 23, 2022, 08:13:04 pm ---I do exactly the same in my (much more complex) code the resulting binary stops with "Illegal Instruction: 4" when the LongJump is being executed. I have no idea what this means or how to solve it.

--- End quote ---
First thing would be to ensure the SetJmp parameter has the values it's supposed to have.  Be particularly careful if the parameter resides on the stack, it can be corrupted and also, it's only valid during the execution of the function it is local to, not on a subsequent re-entry (unless it is re-set to a new value.)

The illegal instruction is most likely due to the LongJmp parameter not being the way it was when SetJmp was called.

HTH.

pleumann:
Thanks!

My Jmp_Buf is a global variable. How can I check that it's been assigned something useful? Can I find the definition for Arm somewhere? The docs seem to be Intel-specific.

https://www.freepascal.org/docs-html/rtl/system/jmp_buf.html

I did copy the example into my code more or less verbatim, though. The main difference is that my code is several orders of magnitude more complex (compiler with recursive descent parser).

pleumann:
Damn! You were right. The code was indeed taking a path that left the Jmp_Ptr uninitialized. Stupid me. It's working now, Thanks a lot!

440bx:

--- Quote from: pleumann on May 23, 2022, 09:11:24 pm ---It's working now, Thanks a lot!

--- End quote ---
You're welcome.  I'm glad you figured it out.

You mentioned you're writing a compiler using recursive descent, may I ask, for what language ?

Navigation

[0] Message Index

[#] Next page

Go to full version