<div dir="ltr"><div>Did you even read what I wrote? You got nothing correct.<br></div><div><br></div><div>Your points;</div><div>1. In C, not in Gambas. We were talking about Gambas.</div><div>2. Can happen in C, but the stack protection probably stops the execution before that happens... and again, not in Gambas.</div><div>3. Same as point 1.</div><div><i><br></i></div><div><i>"Suppose the interpreter provides a "SendToRemotePeer" ..."</i><br></div><div><br></div><div>Wrong, does not happen in Gambas. Unless of course there is bug in Gambas.<br></div><div><br></div><div><i>"Should an interpreter be coded to be robust?  A general purpose usage 
one, like Gambas, yep.  Should it be absolutely robust?  I'm not sure 
that is even theoretical possible."<br></i></div><br><div>I'm not talking about "absolute robustness", I'm talking about fixing bugs when we find them. Proper error message tells quite a much more than just sig11.</div><div><br></div><div><br></div><div>Jussi<br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 29, 2019 at 6:20 PM Cedron Dawg <<a href="mailto:cedron@exede.net">cedron@exede.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Jussi,<br>
<br>
First, I wish I could help the OP better.  I can understand his frustration.  If the problem is in Gambas, finding the minimal program that demonstrates it is definitely the best approach.  If that is a laborious task, I think he should ask if he can email the full code to either Tobi or Benoit to look at, rather than attach it to this thread.  He can also email it to me (cedron at exede dot net), and if I can reproduce it (3.12.2) I might be able to minimize it.<br>
<br>
Let's return to our discussion and generalize it away from the OP's situation.  How can capacity issues lead to a seg fault?  Here's a few ways:<br>
<br>
1) A malloc return value is not checked and a memory allocation error occurs returning a null.  The subsequent code tries to write to the NULL pointer and boom, seg default.<br>
<br>
2) The interpreter keeps an internal stack of some type.  The calling program never calls the "close" for all the "open"s, the stack overflows, and boom, seg default.<br>
<br>
3) A circular buffer captures sensor readings.  The process reading the buffer calculates the index into a lookup table by taking the difference of two sensor readings.  They can only change so much from reading to reading so a range check isn't made.  The sensor goes nuts, starts spewing out readings, the buffer overflows, and the lookup index is made from two readings that buffer size apart, goes out of range, and boom seg default.<br>
<br>
How can a "bad case scenario" lead to a seg fault?  Here's an example:<br>
<br>
Suppose the interpreter provides a "SendToRemotePeer" function that has an internal buffer for holding the message text.  The function call specifies where in the buffer to lay the text.  This code has to be fast so range checks aren't made.  The calling program passes parameters that causes an overwrite on the buffer by one character.  The bug is in the calling program, not the interpreter, boom, seg fault.  Even though it had called the same function flawlessly thousands of times before.<br>
<br>
Now, let's talk about fragility and robustness.  The difference only becomes important when the calling program sends invalid parameters.  Shouldn't all functions be coded to be robust?  No.  Robustness comes at a cost in code size, complexity, and execution time.  Whether it is worth it in a particular location is a judgement call.<br>
<br>
What is robustness?  "parameter validation"  How do errors get caught by the interpreter?  "parameter validation"<br>
<br>
What happens when you fail to do "parameter validation" and invalid data gets through?  Like you said, unpredictable results, and maybe, even yes, boom, seg fault.<br>
<br>
All of the examples I cited above could have been caught with proper parameter validation.  Fragile code is not a bug or an error.  The bug lies in the code calling the fragile code with invalid values.<br>
<br>
Should an interpreter be coded to be robust?  A general purpose usage one, like Gambas, yep.  Should it be absolutely robust?  I'm not sure that is even theoretical possible.<br>
<br>
>From the user point of view, does it make much difference if Gambas catches a seg fault and displays a popup, or does a parameter validation finding the error cleanly and give the user a popup.  The latter is likely to be a tad more informative of the nature of the error, but other than that there isn't really a qualitative difference.<br>
<br>
In the OP's situation, what needs to be determined is:<br>
<br>
1) Is it invalid data from the calling program and fragile Gambas code.<br>
<br>
or <br>
<br>
2) Is it valid data from the calling program and a bug in Gambas code.<br>
<br>
Finally, about blowing up on the first call being a locus indicator.  If a function call blows up on the first call, you can easily determine whether the parameters are valid or not at the calling level.  So, with valid data, you know it is condition 2 above and a bug in the interpreter.  However, if the function call works a bunch of times, then fails, condition 1 becomes the more likely case.<br>
<br>
I still probably didn't explain things clearly enough, but that's what I was saying.<br>
<br>
Ced<br>
<br>
P.S.  "Real Mode" was the predecessor to "Protected Mode" meaning there was no processor level out of range checking on memory referencing.  Those kinds of bugs are particularly difficult to reproduce and find.<br>
<br>
<br>
<br>
----- Original Message -----<br>
From: "Jussi Lahtinen" <<a href="mailto:jussi.lahtinen@gmail.com" target="_blank">jussi.lahtinen@gmail.com</a>><br>
To: "user" <<a href="mailto:user@lists.gambas-basic.org" target="_blank">user@lists.gambas-basic.org</a>><br>
Sent: Saturday, April 27, 2019 6:24:27 PM<br>
Subject: Re: [Gambas-user] Debugging Gambas (again)<br>
<br>
BTW, Jussi, I wrote a comprehensive byte-code interpreter in 8086 assembly in Real Mode as a DOS 3.1 TSR that was used in production for several years, circa 1988 <br>
<br>
Segmentation fault means that the program is trying to access memory address, which it doesn't have privileges to access. So, you can right away say it is definitely not capacity issue or "bad case scenario" in the program logic, as you suggested. How could it be? Also whether the program causes crash right away or later, says absolutely nothing about where the bug is. It just cannot, not even in theory. <br>
<br>
Test this: <br>
<br>
Dim p As Pointer = 1 <br>
Dim hStream As Stream <br>
<br>
hStream = Memory p For Write <br>
Print #hStream, "hello!" <br>
Close hStream <br>
<br>
There is no segmentation fault, but "write error" from Gambas. Why? Because if errors are not caught by Gambas, then they can lead to undetermined behaviour later. Thus this "However, adding parameter validation testing to every function call is a questionable endeavor" is also sign of not understanding at all what you are talking about. <br>
<br>
Once more: <br>
Segmentation fault = operating system tells that Gambas tried to do something illegal. <br>
The "clean" errors = Gambas tells the programmer, that he tried to do something illegal. <br>
<br>
<br>
Jussi <br>
<br>
----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
</blockquote></div>