Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Testing exception causes segmentation fault. #8

Closed
jklmnn opened this issue Jul 11, 2018 · 10 comments
Closed

Testing exception causes segmentation fault. #8

jklmnn opened this issue Jul 11, 2018 · 10 comments
Labels
bug Something isn't working

Comments

@jklmnn
Copy link
Member

jklmnn commented Jul 11, 2018

I tried to add a test which tests the exception behaviour. The expected behaviour is a call to ada_raise_exception which prints the message and exits the program cleanly. Yet this isn't happening. I could track the issue down to Create_File_Line_String but not further. When omitting its call in Rcheck_CE_Explicit_Raise and issuing a constant message the behaviour above applies.

@jklmnn jklmnn added the bug Something isn't working label Jul 11, 2018
@jklmnn
Copy link
Member Author

jklmnn commented Jul 11, 2018

I added this test on https://github.com/jklmnn/ada-runtime/tree/issue_8.

@treiher
Copy link
Member

treiher commented Jul 11, 2018

Could this be related to the secondary stack? Last time we talked about that the current implementation for the POSIX platform which is used for the tests is not correct.

@jklmnn
Copy link
Member Author

jklmnn commented Jul 11, 2018

I first thought it had to do with the File argument being a null pointer but the segfault also occured when I passed the address of local string. The secondary stack could indeed be a problem. I'll test that. What bothers me is that the secondary stack test doesn't fail (assuming ptr[-1] causes a segfault as well when ptr is allocated by malloc).

@jklmnn
Copy link
Member Author

jklmnn commented Jul 11, 2018

https://github.com/jklmnn/ada-runtime/commit/c49ba92336d65fec361081d68d1c9cdffec03e73 indeed seems to fix that behaviour by using the upper bound of the memory region. Could you please check if this solution has any drawbacks, especially if the (indeed quite simple) is correct?

@treiher
Copy link
Member

treiher commented Jul 11, 2018

I see no drawbacks in the solution.

@jklmnn
Copy link
Member Author

jklmnn commented Jul 11, 2018

Then I'd say you can squash these three commits and put them on master and we can close the issue.

@treiher
Copy link
Member

treiher commented Jul 11, 2018

The error message looks strange:

$ tests/exception/test 
warning: Get_Jmpbuf_Address_Soft not implemented
warning: Set_Jmpbuf_Address_Soft not implemented
Exception raised (256): explicit raise: Sest.adbuf_Address_Soft not implemented

@treiher
Copy link
Member

treiher commented Jul 12, 2018

I found the error in Create_File_Line_String and will fix it.

@senier
Copy link
Member

senier commented Jul 12, 2018

@treiher: Can you please briefly describe what issue was an how you solved it? That way, our tickets can help us to learn and avoid similar issues in the future.

@treiher
Copy link
Member

treiher commented Jul 12, 2018

@senier The issue was just a stupid beginner mistake, but as you demand a description: An uninitialized fixed-length string was used to store the exception message. The string was at the same location as the log message which was printed before and so initially contained this message. The file name was just written character-per-character into this string, the rest of the string remained unchanged.

Now the implementation determines the length of the file name before declaring a fixed-length string with the correct size and writing the file name into it.

@jklmnn jklmnn mentioned this issue Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants