473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 1633
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MJS | last post by:
I am new to perl and I need some help with the following problem. I have two files viz. file1 and file2. I have to determine if a scalar variable in file1 (without knowing its location) has a...
1
by: Tony Johansson | last post by:
Hello experts! As this program is now it's works perfectly when running as a application or as an Applet. Now to my question if I just change this row "public class Converter extends Applet "...
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
5
by: BabyBoo24 | last post by:
I must create ten multiple choice questions.The questions will be weighted Question1: 10.0 points question2: 15.0 points, etc. Each question has different weights. The weights must be defined as...
4
by: bergko | last post by:
Hi there, I'm thinking of how to write a struct to a binary file, could anyone help me with this? for example typedef struct record{ char *name int contact
9
by: axs221 | last post by:
I am trying to move some of our large VBA Access front-end file into ActiveX DLL files. I created two DLL files so far, one was a module that contains code to integrate into the QuickBooks...
5
by: James Wong | last post by:
hi, I want to write some delegate function to the DLL. How can I output the value to my main program? (Do not output the value to the UI) Any good idea for this program? Thanks~ For example,
6
by: Tony | last post by:
Is there any value to pursuing program designs that mimimize the mainline call stack? For example, within main() I could code up something like: while(GetMsg(m)) DispatchMsg(m); instead of...
4
by: itsmee | last post by:
I am trying to trace the program below but I am not understanding certain lines of codes. I made tables for each function with their variables to keep track as they change. The program output is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.