Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
variable dependency debugging tool

Subject: variable dependency debugging tool

From: Alan B

Date: 5 May, 2010 22:34:06

Message: 1 of 3

I have an idea for a debugging tool that would be very useful for me, I'm wondering if anyone has ever seen something like this: a program that determines the assignment dependencies of all variables in a given Matlab function. Ideally it would plot a graph of as well. The top of the plot would show all function inputs and hard-coded parameters, the bottom of the plot would show all function outputs. In between, linked nodes would be drawn such that any variable is linked to any variable whose value it depends on, and also to any variable whose value depends on it.

I suppose a basic implementation via text scanning wouldn't be too difficult, but I don't want to reinvent the wheel if I don't have to. I can't seem to think of good search terms to look for this, has anyone seen anything like this on the FEX?

Subject: variable dependency debugging tool

From: John D'Errico

Date: 6 May, 2010 00:25:21

Message: 2 of 3

"Alan B" <monguin61REM@OVETHIS.yahoo.com> wrote in message <hrsrou$e38$1@fred.mathworks.com>...
> I have an idea for a debugging tool that would be very useful for me, I'm wondering if anyone has ever seen something like this: a program that determines the assignment dependencies of all variables in a given Matlab function. Ideally it would plot a graph of as well. The top of the plot would show all function inputs and hard-coded parameters, the bottom of the plot would show all function outputs. In between, linked nodes would be drawn such that any variable is linked to any variable whose value it depends on, and also to any variable whose value depends on it.
>
> I suppose a basic implementation via text scanning wouldn't be too difficult, but I don't want to reinvent the wheel if I don't have to. I can't seem to think of good search terms to look for this, has anyone seen anything like this on the FEX?

It will be more difficult than you think to do this at
all well. With nested functions, the tool would need
to worry about what happens inside them.

And of course eval or its cousins would cause massive
headaches. Global variables too would drive you crazy.

And suppose that you define a variable that overloads
an existing matlab function? The tool would need to
recognize the overloading.

Yes, if you limit the possibilities, excluding anything
inside an eval, globals, etc., you could do something
simple. But the fact is, if the code is simple enough,
you don't need such a tool anyway.

John

Subject: variable dependency debugging tool

From: Alan B

Date: 6 May, 2010 04:29:04

Message: 3 of 3

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hrt29h$d6c$1@fred.mathworks.com>...
> It will be more difficult than you think to do this at
> all well. With nested functions, the tool would need
> to worry about what happens inside them.
>
> And of course eval or its cousins would cause massive
> headaches. Global variables too would drive you crazy.
>
> And suppose that you define a variable that overloads
> an existing matlab function? The tool would need to
> recognize the overloading.
>
> Yes, if you limit the possibilities, excluding anything
> inside an eval, globals, etc., you could do something
> simple. But the fact is, if the code is simple enough,
> you don't need such a tool anyway.
>
> John

I know it isn't easy to do it *correctly*. Even before everything you listed, a few simple problems occurred to me - block comments, multi-line statements, and character strings that contain anything resembling Matlab code. I think, just the presence of these entities would necessitate half of a syntax parser, rather than simple line-by-line string matching. Globals, evals, loads, overloads, nested and subfunctions, all make it that much worse.

However, M-Lint does provide a limited subset of this functionality - "the value assigned to X might never be used"; "input argument Y appears never to be used";
function return value Z appears to never be set". M-lint can't handle some of the cases you mentioned, but it is good for a quick hint once in a while. So, I know it has been partially implemented in a useful way.

The code that I would like to use this for tends to be not much more sophisticated than a long (~300 lines) series of relatively simple (but dense) commands, saved as a script. Sometimes there are a few big if-else blocks or loops surrounding the bulk of the code. Sometimes the script starts with a load() and finishes with a save(). Basically, though, it does not tend to be too complicated in the sense that you warn against.

I think you will tell me it is still a bad idea to become dependent on such a tool. You would be right. Can we still consider it, as a matter of curiosity? I wrote a very simple function that scans text for strings on LHS or RHS of assignment operators, and just spits out a list. I would like to see a function that is barely more sophisticated than this, say by making a first attempt at linking all of these scanned assignment statements.

Thanks for the reply.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us