469,616 Members | 1,696 Online

# How to write a program to track the value of a certain variable at run-time using debug features???

Hello everyone,

I'm totally new to the group and I would like to learn from you. Thank
you in advance!

I need to write a program to track whether a mathematical function has
changed during run-time or not. The program should work with any
mathematical function provided by users.

Let's take an example in the C language:
//================================================== =
//The users define the two parameters a, b as two global variables.
The users can define as many parameters as possible and my program
does not know about this!!!
int a;
int b;

//below is the prototype for our mathematical function
void f(vector x);

//at first, an user wants f = 1x+1y, so he sets the value of a, b
accordingly
a=b=1;

double value=f(x); //calculate the value of function f

//now the user want f = 1x +2y, so he set b = 2
b =2;

//and invoke the function f again
value=f(x);
//=================================================

As can be seen from the code above, the function f has changed from f
= x+y to f=x+2y and my program needs to track this at run-time (The
function f, along with its parameters (a and b), will be integrated
with my program).

However, the problem is that my program will NOT KNOW which function
to be provided by the users and which/ how many parameters (defined as
global variables) the function may take

I think that one solution for the problem might be:

1. List all global variables currently used in the program
2. Find out which global variables are being used by f (I can do that
by parsing the source code file of f)
3. Tracking the value of all these global variables to see whether
they have been changed outside of f or not. If they have, then
possibly that f has been changed too.

Now the question is: How to list all global variables and how to track
the value of a certain global variable at run-time???

I wonder whether the existing debugger of windows/Visual Studio can
provide me with the necessary APIs to answer the question above?

Thank you so much for your help

Best regards,

Thanh

Mar 19 '07 #1
6 1473
I need to write a program to track whether a mathematical function has
changed during run-time or not. The program should work with any
mathematical function provided by users.
One of the first chapters of 'The C++ programming language' has an example
of a calculator that does what you want.
Personally, I think the example is an example of bad programming, since it
involves a recursive loop that weaves its way through a codepath of n
different functions.

Still, it might give you an idea on how to tackle the problem.

Btw, this sounds like a homework assignment.
If so, remember that Learning by copying != learning.

--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Mar 19 '07 #2
On 19 Mar, 15:23, Bruno van Dooren [MVP VC++]
<bruno_nos_pam_van_doo...@hotmail.comwrote:
I need to write a program to track whether a mathematical function has
changed during run-time or not. The program should work with any
mathematical function provided by users.

One of the first chapters of 'The C++ programming language' has an example
of a calculator that does what you want.
Personally, I think the example is an example of bad programming, since it
involves a recursive loop that weaves its way through a codepath of n
different functions.

Still, it might give you an idea on how to tackle the problem.
Dear Bruno,

Thank you very much for your help. I will take a look at the book.
Btw, this sounds like a homework assignment.
If so, remember that Learning by copying != learning.
Thanks again for the reminder, but actually it is not my assignment.
As a part of my research, I have written an algrithm to solve
numerical functions which users provide as black boxes. Over time they
may change their funcions without noticing my algorithm, so I need a
method to track the changes.

Best regards,

Thanh.

Mar 19 '07 #3
<bruno_nos_pam_van_doo...@hotmail.comwrote:
I need to write a program to track whether a mathematical function has
changed during run-time or not. The program should work with any
mathematical function provided by users.

One of the first chapters of 'The C++ programming language' has an example
of a calculator that does what you want.
Dear Bruno,

I have taken a look at the book. Unfortunately it is not what I want.
The example implement a calculator when user can input different
functions.

Actually I have written an algorithm to solve numerical
functions which are considered as black boxes. The algorithm will be
integrated by users with the code of their numerical functions so
that
their program can solve the functions.

What I want is a method to track whether the parameters of a given
function has changed or not. Users may also are not awared of the
change of the value of parameter, hence the only way to track it is to
periodically check whether the values have changed or not.
The problem is that my algorithm does not know anything about the
source code of users' function. It means that my algorithm does not
know neither the content of the function nor the variables that the
function may use and/or modify.

Mar 19 '07 #4
One possible solution, as suggested by Martin Irman from
microsoft.public.vc.debugger is to use C++ wrapper class. When used
along with template class this solution can help us to check each time
a parameter change. Something like this:

template <class PRM_TYPE>
class Parameter
{
private:
PRM_TYPE _prm;
public:
PRM_TYPE operator = (const PRM_TYPE& prm)
{
return (_prm = prm);
//some code to handle the change here ...
}
//...
};

However, this solution still require users to do the following:
1. Either use Parameter as the base class for the parameters that they
will use in the function
2. Or, use Parameter as the base class for all parameters. In this
case, we will still need to parse the code to find which parameter
being used in the function.

As a result, I was considering this the last resort and looking for
another alternative...
As I see, the VC debugger can show the list of global variables and
their value at run-time, so I wonder whether it is possible for me to
re-use some API from the debugger.
If it is impossible, then probably the solution above is the best
choice.

Thank you very much

Best regards,

Thanh.

Mar 19 '07 #5
In article <11**********************@b75g2000hsg.googlegroups .com>,
classicalmania <tr**********@gmail.comwrote:
>As a result, I was considering this the last resort and looking for
another alternative...
As I see, the VC debugger can show the list of global variables and
their value at run-time, so I wonder whether it is possible for me to
re-use some API from the debugger.
No. Your exe's code, and the code executed in these user-specified
functions *MUST* be kept 100% separate. See my other email --
comingling the two is going to lead to a lot of pain, security problems,
and the like.

Nathan Mates
--
<*Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Mar 19 '07 #6
Dear Nathan,

Again, thank you very much for your advices and your useful links.

On Mar 19, 8:55 pm, nat...@visi.com (Nathan Mates) wrote:
No. Your exe's code, and the code executed in these user-specified
functions *MUST* be kept 100% separate. See my other email --
comingling the two is going to lead to a lot of pain, security problems,
and the like.
They should be separated in case of developing commercial and/or real-
world applications. However, in my research community (where my
algorithm would likely be applied to), it is acceptable to combine the
two different bit of codes like this, because they don't care much to
the reliability of code at this stage. Code optimization will only be
the task of the next stage, if the research results became fruitful
and applicable.

Best regards,

Thanh.

Mar 19 '07 #7

### This discussion thread is closed

Replies have been disabled for this discussion.

### Similar topics

 1 post views Thread by MJS | last post: by 1 post views Thread by Tony Johansson | last post: by 92 posts views Thread by Raghavendra R A V, CSS India | last post: by 18 posts views Thread by jacob navia | last post: by 5 posts views Thread by BabyBoo24 | last post: by 4 posts views Thread by bergko | last post: by 9 posts views Thread by axs221 | last post: by 5 posts views Thread by James Wong | last post: by 6 posts views Thread by Tony | last post: by 4 posts views Thread by itsmee | last post: by 1 post views Thread by strativab | last post: by reply views Thread by billypeterson | last post: by reply views Thread by Drake Tucker | last post: by reply views Thread by eddparker01 | last post: by reply views Thread by devrayhaan | last post: by reply views Thread by neerajsundriyal | last post: by 1 post views Thread by Simmer | last post: by reply views Thread by aprens | last post: by reply views Thread by isladogs | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.