petelomax / Phix

The Phix Programming Language
http://phix.x10.mx/
Other
57 stars 2 forks source link

problem with trace and function parameters #6

Closed loo66 closed 3 years ago

loo66 commented 3 years ago

Hi again,

another interesting one: I crashed with a traced source if I want to check a function parameter.

function with trace call:

1: with trace
2:
3: global function ellip(atom m, atom a, atom ecc)
4: atom k,e,c,s,fac,rho
5: atom x, y, vx, vy
6:
7: trace(1)
8==> k := KGAUSS / sqrt(a);
9: e := eccanom(m,ecc); c:=cs(e); s:=sn(e);
10: fac:= sqrt((1.0-ecc)(1+ecc)); rho:=1.0-eccc;
11: x := a(c-ecc); y :=afacs; vx:=-ks/rho; vy:=kfacc/rho;
12:
13: return {x, y, vx, vy}
14: end function

then I want to see 'm' with '?' ... this gives a crash ...

variable name? m
m pDiagN.e line 3064: oops, rtn[=9476] out of range[1..4113] pDiagN.e line 3064: oops, rtn[=9488] out of range[1..4113] pDiagN.e line 3064: oops, rtn[=9516] out of range[1..4113] pDiagN.e line 3064: oops, rtn[=9584] out of range[1..4113] pDiagN.e line 3064: oops, rtn[=9645] out of range[1..4113] /home/thales/work/astro/phix/keplib/ellip.e:-1 (era=#00807E54, from_addr=#41CEDBA9, ret_addr=#41CEDC38) in function ellip() variable ???(varno=9366) has not been assigned a value m = 473.8013708 a = 17.93901765 ecc = 0.9672725 k = e = c = s = fac = rho = x = y = vx =

Tried to simplify the case with this code:

with trace

function p1(atom a, atom b) atom c

c = a + b trace(1)

return c end function

?p1(2,3)

doesn't crash but the output for the variables is c = 3 b = 8589934592 a = 2

Greetings Otto

petelomax commented 3 years ago

Good catch again. Works fine on 32 but not 64 bit. Change pTrace.e line 760 (two lines replaced):

--DEV 64-bit/see pdiagN.e
if nTyp=S_TVar then
    tidx = ss[S_Tidx]
    --o = getVal(ebp+tidx*4)
    --o = getVal(ebp4*4+tidx*4)
    o = getVal(ebp4*4+tidx*machine_word())
else
    tidx = ss[S_Slink]
    --o = getVal(static_base+tidx*4-4)
    --o = getVal(ds4*4+tidx*4-4)
    --o = getVal(ds4*4+tidx*4+16)
    o = iff(machine_bits()=32?16:24)
    o = getVal(ds4*4+tidx*machine_word()+o)
end if

and after recompiling (ie p -cp [or maybe p -c p64]) things should be much better. As you can see that code was simply never properly modified/tested for 64-bit.