evaluating code lines above breakpoints ?

Diez B. Roggisch deets at nospam.web.de
Thu Aug 21 06:09:52 EDT 2008


Stef Mientki wrote:

> hello,
> 
> I'm trying to create a high level debugger, based on rpd2.
> 
> So when the debugger enters a breakpoint,
> I want to display the values of all variables in the, let's say,
> 5 lines above the breakpoint (if possible).
> Any hints on how I get a list of all vars in those lines ?
> My rough idea is to scan the lines, skip keywords, test type of each
> term ( by eval), if the term is var eval the value of it.
> Are there better ways ?

I don't know about better ways, but I for *sure* know that this is a really
bad idea. Simply because a debugger that executes arbitrary evals can cause
side-effects that make it useless. 

Why do you want this anyway? Why don't you simply show all the variables in
the local frame? I'd say thats enough.
 
> Another idea, when hoovering over a variable during a breakpoint, a
> hint appears with the type and value of that var.

The simple thing to do is to extract tokens, and then if these as names are
matched in the local frames, you can display the content.

Things get more difficult in cases like

foo[index]

as this can cause a side-effect to occur. I wouldn't automatically evaluate
the expression, for reasons given above.

Diez



More information about the Python-list mailing list