Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Variable on stack or heap?

Thanks Alena, I couldn't have phrased it better :)

Am 08.11.2009 um 02:06 schrieb Alena Laskavaia:

This is classic static analysis problem and can be partially solved by
data-flow analysis, but never can be solved completely,
i.e. but doing data-flow you can figure out if variable at given line
contains pointer to heap, pointer to non-heap, either or unknown.
Depends on depth and complexity
you reduce "unknown" factor. You cannot do it from AST you need to
build control-flow graph, data-flow graph and perform data-flow
evaluation for particular know "seeds"
i.e. call to malloc or new is known to return value in heap, then you
propagate this value through the graph.

On Sat, Nov 7, 2009 at 12:09 PM, Gavin Rehkemper <gavreh@xxxxxxxxx> wrote:
Thanks for all the help everyone.

Tobias, we're a bit confused by your example. x is on the stack, and *py is on the heap. In the first case, pint points to something on the stack, and
the second, it points to something on the heap. So you're saying that
because of this particular case we can never know if pInt is on the stack or
heap? Is there a way to check the last assignment?

Pete, we are writing an eclipse plugin that is doing some intelligent code refactoring. To take an example, say we're trying to get the size of an array. We could either use sizeof() or malloc_usable_size() - and we want to
figure out which one to use given a particular variable.

We were hoping there would be some aspect of the AST that would indicate this without having to run the code. So it sounds like you're saying there's
no easy way to do this before runtime?

Thanks,
Gavin

On Fri, Nov 6, 2009 at 9:50 AM, <cdt-dev-request@xxxxxxxxxxx> wrote:
Gavin Rehkemper wrote:
We have a variable, and we know it is a pointer. How do we determine
whether it points to something allocated on the heap (malloc'd, for
example), or something allocated on the stack (an array of finite length).

In the general case this is not possible from an AST, as it must be
determined at run-time (pointers can be changed to point at other
things, for example).

If the specific scenario is *very* simple, you could look for all the
assignments in the AST and *may* be able to determine from that exactly
what it is pointing to after the assignment completes.  Probably not
very likely or useful though.

At run-time you might be able to do this by checking the address that it
points to, assuming you know where the stack and heap are in memory.

What are you actually trying to achieve, if you don't mind me asking?

Pete

--
Peter J. Vidler
Senior Systems Developer, TTE Systems Ltd

p.vidler@xxxxxxxxxxxxxxx
+44 (0)116 223 1684

Registered address: 106 New Walk, Leicester, LE1 7EA
Company number: 05058157
VAT registration: 913 4859 12

www.tte-systems.com

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top