BBC BASIC for Windows
« Strange crash »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:58pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Strange crash  (Read 911 times)
sveinioslo
Developer

member is offline

Avatar




PM


Posts: 64
xx Strange crash
« Thread started on: Oct 29th, 2012, 11:44am »

The following plain simple program will crash IDE (and program), but only when using the utility 'list variables'.

If 'list var' is opened before 'run', IDE may or may not crash.

If 'list var' is opened while program is running and you resize 'list var window', IDE will crash almost immidiately.

It will not crash if you remove ' ,1 ' in any of the lines 70-73.
That is, change
A%=FN_x64(MID$(b64$,I%,1),pad%)
to
A%=FN_x64(MID$(b64$,I%),pad%)

If you insert a dummy line, say 'PRINT I%' between 69 and 70, it will not crash.
Inserting or removing elsewhere seems not to affect the crashing.

I have tried, save reopen, copy to notepad and copy back to fresh IDE. No change.

I have tried on 3 different computers, all win7 32 bit, they all crash.
On one stationary win7 32 bit i have tried versions 5.80a 5.92a 5.93a and 5.94a, they all crash.

.... Laptop win7 64 bit did not crash. !! ....

Attempt to extract minimum fault code, failed. Only full program will crash.

Waited 2 days before reporting this, just in case i have missed something obvious.
Well, i don't see it.!

Svein.
Ps. hope i posted at the correct place.


It is always the same exception code/offset.

Problem Event Name: APPCRASH
Application Name: bbcwin.exe
Application Version: 5.94.1.0
Application Timestamp: 504120a5
Fault Module Name: msvcrt.dll
Fault Module Version: 7.0.7601.17744
Fault Module Timestamp: 4eeaf722
Exception Code: c0000005
Exception Offset: 000309b6
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1044
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Code:
    1 
    2 Test%=0 : REM 0=my work   1=RTR's
    3 IF Test% THEN PRINT "testing RTR's"
    4 a$="":Err%=0:T%=TIME
    5 
    6 FOR b=1 TO 4 : T1%=TIME
    7   PRINT "test ";b;"  stringlen = ";LENa$;" to ";LENa$+1000;
    8   FOR a=1 TO 1000
    9     a$+=CHR$RND(255)
   10     IF Test% THEN
   11       b$=FNattach(a$)
   12       IF a$<>FN_b64_bin(b$) Err%+=1
   13     ELSE
   14       b$=FN_bin_b64(a$)
   15       IF a$<>FN_b64_bin(b$) Err%+=1
   16     ENDIF
   17   NEXT a
   18   
   19   b$=a$
   20   FOR a=1 TO 100
   21     IF Test% THEN
   22       c$=FNattach(b$)
   23       b$=FN_b64_bin(c$)
   24     ELSE
   25       c$=FN_bin_b64(b$)
   26       b$=FN_b64_bin(c$)
   27     ENDIF
   28   NEXT a
   29   
   30   IF a$=b$ THEN
   31     PRINT " ok";"  time = ";INT((TIME-T1%)/100);" sec"
   32   ELSE
   33     PRINT " test failed............":Err%+=1
   34   ENDIF
   35 NEXT b
   36 PRINT "number of errors = ";Err%;"  time = ";INT((TIME-T%)/60)/100;" min"
   37 END
   38 
   39 DEF FN_bin_b64(bin$)
   40 LOCAL pad%,b64$,A%,B%,C%,D%,E%,F%,G%,I%
   41 I%=LEN(bin$) MOD 3
   42 IF I%=1 THEN bin$+=CHR$(0)+CHR$(0):pad%=2
   43 IF I%=2 THEN bin$+=CHR$(0):pad%=1
   44 FOR I%=1 TO LEN(bin$) STEP 3
   45   A%=ASCMID$(bin$,I%,1)
   46   B%=ASCMID$(bin$,I%+1,1)
   47   C%=ASCMID$(bin$,I%+2,1)
   48   D%=A% >> 2
   49   E%=(A% AND &03) << 4 OR B% >> 4
   50   F%=(B% AND &0F) << 2 OR C% >> 6
   51   G%=C% AND &3F
   52   b64$+=CHR$(FN_b64(D%))+CHR$(FN_b64(E%))
   53   b64$+=CHR$(FN_b64(F%))+CHR$(FN_b64(G%))
   54 NEXT I% : I%=LEN(b64$)
   55 IF pad%=1 THEN MID$(b64$,I%,1)="="
   56 IF pad%=2 THEN MID$(b64$,I%-1,2)="=="
   57 =b64$
   58 
   59 DEF FN_b64(E%)
   60 IF E%<26 THEN =E%+65 : REM A-Z
   61 IF 25<E% IF E%<52 THEN =E%+71 : REM a-z
   62 IF 51<E% IF E%<62 THEN =E%-4 : REM 0-9
   63 IF E%=62 THEN =43 : REM +
   64 IF E%=63 THEN =47 : REM /
   65 =0:REM suppress cross ref warning
   66 
   67 DEF FN_b64_bin(b64$)
   68 LOCAL pad%,bin$,A%,B%,C%,D%,E%,F%,G%,I%
   69 FOR I%=1 TO LENb64$ STEP 4
   70   A%=FN_x64(MID$(b64$,I%,1),pad%)
   71   B%=FN_x64(MID$(b64$,I%+1,1),pad%)
   72   C%=FN_x64(MID$(b64$,I%+2,1),pad%)
   73   D%=FN_x64(MID$(b64$,I%+3,1),pad%)
   74   E%=A% << 2 OR B% >> 4
   75   F%=(B% AND &0F) << 4 OR C% >> 2
   76   G%=(C% AND &03) << 6 OR D%
   77   bin$+=CHR$(E%)+CHR$(F%)+CHR$(G%)
   78 NEXT I%
   79 bin$=LEFT$(bin$,LENbin$-pad%)
   80 =bin$
   81 
   82 DEF FN_x64(e$,RETURN pad%)
   83 LOCAL E%:E%=ASC(e$)
   84 IF 64<E% IF E%<91 THEN =E%-65 : REM A-Z
   85 IF 96<E% IF E%<123 THEN =E%-71 : REM a-z
   86 IF 47<E% IF E%<58 THEN =E%+4 : REM 0-9
   87 IF E%=43 THEN =62 : REM +
   88 IF E%=47 THEN =63 : REM /
   89 IF E%=61 THEN pad% +=1 : =0 : REM = padding
   90 =0:REM not a b64 file
   91 
   92 DEF FNattach(bin$)
   93 LOCAL B$,b64$,L%,A%,D%,I%
   94 B$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
   95 L%=LENbin$ MOD 3
   96 IF L%=1 bin$+=CHR$0+CHR$0 ELSE IF L%=2 bin$+=CHR$0
   97 FOR A%=1 TO LENbin$ STEP 3
   98   D%=ASCMID$(bin$,A%,1) << 16 OR ASCMID$(bin$,A%+1,1) << 8 OR ASCMID$(bin$,A%+2,1)
   99   FOR I%=1 TO 4
  100     b64$+=MID$(B$,(D% >> 18)+1,1)
  101     D%=D% << 6 AND &FFFFFF
  102   NEXT I%
  103 NEXT A%
  104 IF L%=1 RIGHT$(b64$,2) = "==" ELSE IF L%=2 RIGHT$(b64$) = "="
  105 =b64$
 


« Last Edit: Oct 29th, 2012, 9:55pm by sveinioslo » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Strange crash
« Reply #1 on: Oct 29th, 2012, 11:12pm »

on Oct 29th, 2012, 11:44am, sveinioslo wrote:
The following plain simple program will crash IDE (and program), but only when using the utility 'list variables'.

Yes, sorry about that. It happens because you are frequently changing the length of a string, and unfortunately because the List Variables utility runs in a different, asynchronous, thread it can sometimes pick up data from the heap which is transiently invalid (in this particular case a string whose length is non-zero but whose address is zero).

I was aware of the theoretical possibility of that happening, but statistically it's not very likely. Sadly your program seems to provoke it every time! Realistically the only practical solution is not to use the List Variables utility while your program is running.

Richard.
User IP Logged

sveinioslo
Developer

member is offline

Avatar




PM


Posts: 64
xx Re: Strange crash
« Reply #2 on: Dec 13th, 2012, 1:33pm »

> List Variables utility runs in a different, asynchronous, thread it can sometimes pick up data from the heap which is transiently invalid <

So, would this be related to invalid cache or critical section or ...?

This got me started on the assembler, i had been waiting for a reason to dig into the assembler stuff.
More than 20 years since i did anything in assembler.
I was thinking i would like to write a custom LVu with selectable variables + more.
I started to read about critical section (MSDN), but that was a bit too much new info at once.
So i started another 'first x86' project instead.
Been thinking about this issue the past weeks.

If this is a critical section issue:
When i write the custom LVu in assembler:

While running in/from ide, no issues.

While running in/from ide in a PROC and started from timerlib, no issues, timerlib takes care of critical section.

While running in/from ide and called directly from a modified timerlib, take care, if/when error in code, no way of stopping it ??

While running as a separat .exe ??
There were some info about how to enter critical section from an external process.
But i guess it takes some time before i reach that level.

If it's not critical section issue, then ??.

Hope you have time for some info regarding this, i'll do my best to google the things i don't understand.

Svein
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Strange crash
« Reply #3 on: Dec 13th, 2012, 9:28pm »

on Dec 13th, 2012, 1:33pm, sveinioslo wrote:
So, would this be related to invalid cache or critical section or ...?

Neither really: it's because a string is represented by a 6-byte descriptor (a 4-byte pointer plus a 2-byte length) and there are no CPU instructions which perform 'atomic' operations on 6-byte blocks. Therefore any communication of a BBC BASIC string between one thread and another will inevitably involve two operations, and there's therefore a possibility that they won't be 'coherent' (in other words the 4-byte address and the 2-byte length won't belong to the same string).

Quote:
I was thinking i would like to write a custom LVu with selectable variables + more.

There is already a 'custom' List Variables utility by Malcolm Marten ('List Variables Alternative'), described at the bottom of this Wiki page; I don't know whether that might be a better starting point:

http://bb4w.wikispaces.com/Tools+and+Utilities

Quote:
I started to read about critical section (MSDN), but that was a bit too much new info at once.

A Critical Section would certainly be one solution, but that requires both ends to cooperate, and of course you have no way of modifying the BB4W interpreter to use a Critical Section 'at its end'. Indeed such a modification wouldn't be sensible, since it would impair the performance of the interpreter - which is a price too high to pay to fix a minor problem with a debugging tool.

Naturally I'll fix the List Variables crash if and when I release another version of BB4W, but I've no idea when that might be.

Richard.
User IP Logged

sveinioslo
Developer

member is offline

Avatar




PM


Posts: 64
xx Re: Strange crash
« Reply #4 on: Dec 14th, 2012, 12:25am »

> 6-byte descriptor (a 4-byte pointer plus a 2-byte length) and there are no CPU instructions which perform 'atomic' operations on 6-byte blocks <

Aah!, didn't think of that, very theoretical, yes.

> Naturally I'll fix the List Variables crash if and when <

I'm probably the only one running tests like that.
Now that i know, i'm fine with it as it is.


> List Variables utility by Malcolm Marten <

Haven't tried it, but from the description, it is very far from what i have in mind. It is something i have wanted to do, but not without assembler.
I could upload the running demo skeleton gui design idea, if you are curious.

Svein
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls