[Fwd: [Fwd: Re: Breakpoints set in the pseudocode of functions]]
Sylvestre Ledru
sylvestre.ledru at inria.fr
Tue Apr 29 11:00:27 CEST 2008
Could be interesting for other Scilab devs
-------- Message transféré --------
De: Serge Steer <Serge.Steer at inria.fr>
Répondre à: Serge.Steer at inria.fr
À: fvogelnew1 at free.fr
Sujet: Re: Breakpoints set in the pseudocode of functions
Date: Mon, 28 Apr 2008 10:05:10 +0000
François Vogel a écrit :
> Hi Serge,
>
> I have seen that in order to close bug 2542 you wrote macros
> add_profiling, remove_profiling, and so on, that use the bytecode of
> the function to profile. This looks very nice to me.
>
> I was wondering if the same approach could be used with some
advantage
> to set/remove breakpoints in functions instead of using set/delbpt? I
> remember you mentioned such an approach a few years ago, but I think
> this never took shape.
>
> Currently setbpt/delbpt maintain an internal array of breakpoints
> (function names and line numbers), and this array is checked during
> execution of each line against the current execution point.
>
> The new approach would be to store a special pseudocode after each
> line of each function, telling whether the execution should stop at
> this point or not.
>
> See also http://bugzilla.scilab.org/show_bug.cgi?id=884#c1
>
> I think you wrote me privately a long time ago that such a new
> approach would have some other advantages, but I can't remember which
> ones exactly at the moment.
>
> Do you have any thoughts on this old idea in the light of what you
> just achieved for profiling with pseudocodes?
>
> Thanks,
> Francois
>
>
I am still thinking about that. But there are some difficult points with
the current way the function are handled:
- it is not possible to change the internal coding of a function while
it is running (strictly speaking, it is not possible to change the
sizes). Here a possible solution should be to prepare a function for
debugging adding void pseudo codes at the end of each line (see
below) .
then at run time to replace these void pseudo codes by a break point
pseudo-code, without changing the sizes.
- if a function is modified inside a given context (for example to
activate a breakpoint) the modification will be lost in the calling
contexts
- if a function is reloaded, the current breakpoints must be recreated.
Serge
ps:
preparation for debugging can be made by
function add_debugging(funname)
//add debugging instruction bytecode after each function line
nsiz=6
execstr('code=bytecode('+funname+')')
lc=1
lc = lc + nsiz*double(code(lc)) + 1
lc = lc + nsiz*double(code(lc)) + 1
long=code(lc)
lc = lc+1
c=code(lc:$)
c1=bytecodewalk(c,15,addvoid)
code=[code(1:lc-2) int32(size(c1,'*')) c1]
execstr(funname+' = resume(bytecode(code))')
endfunction
with
function [c,l]=addvoid(l)
//add debugging instruction bytecode
c=int32([15 0 3 0]);l=l+1;
endfunction
The op code 0 just make the interpretor skip n integers in the pseudo
code, where n is the value just after the op code
15 is the eol opcode
To introduce a break point somewhere one has then to replace the
sequence [0 3 0] by [12 0 2] where 12 is the pause opcode
More information about the dev
mailing list