473,385 Members | 1,655 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,385 software developers and data experts.

recording the program flow

Suppose that you want to know where your program has
passed, i.e. the exact flow of the program.

A brute force solution is to make an array of n lines, n being
the number of lines in the function. At each line then, you increment
a variable like this:

// NRLINES is the number of lines in the program module
int lines[NRLINES];
int fn(int a)
{
int s;
a = a + 1; lines[__LINE__]++;
s = a -= 1; lines[__LINE__]++;
etc
}

At the end of the run, you write into a file all those arrays. For each
source file you get one.

Obviously this is very inefficient. In the concrete example
above it would suffice a single counter since if you get
into that function at all, all the counters must have the
same value, there are no iterations constructs, gotos etc.

Refining this we could say that it suffices a single counter
for each basic block, i.e. between a label and a control
flow instruction (jump).

Function calls are a problem because they could indirectly call
longjmp and jump to a function higher in the stack.

I would like to research this a bit. Does anyone here know of
references to this problem in the literature?

Thanks in advance

jacob
Nov 14 '05 #1
7 1819
"jacob navia" <ja***@jacob.remcomp.fr> writes:
Suppose that you want to know where your program has
passed, i.e. the exact flow of the program.
[...]
I would like to research this a bit. Does anyone here know of
references to this problem in the literature?


For me, because I work with whole-system simulators and virtual
machine monitors extensively, the "obvious" solution seems to be
to use the simulator to record the program's flow. For example,
on x86 Linux you could adapt valgrind to keep track of which
basic blocks are executed.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2
jacob navia wrote:
Suppose that you want to know where your program has
passed, i.e. the exact flow of the program. [...]


The illustrative code you provided didn't record what
I'd understand as the "flow" of the program: that would
include not only how many times you'd reached a particular
spot in the program, but also how you happened to arrive
there and where you went next. From the code, I think
what you're looking for is "coverage analysis," a phrase
that gets plenty of hits on Google.

--
Er*********@sun.com

Nov 14 '05 #3
Didn't know about valgrind. Looks like a monster software...

Thanks a lot for this reference

Nov 14 '05 #4
The application I have in mind is when you hit a breakpoint in
my debugger, to be able to show the user the trace of the
last x lines executed, i.e to help the user understand how the
program got there.

jacob
Nov 14 '05 #5
"jacob navia" <ja***@jacob.remcomp.fr> writes:
The application I have in mind is when you hit a breakpoint in
my debugger, to be able to show the user the trace of the
last x lines executed, i.e to help the user understand how the
program got there.


Then the solution you mentioned in your original post:

lines[__LINE__]++;

won't do it; it just counts the number of times each line is executed.

What you want is something like:

trace[index++] = __LINE__;

Avoiding overflow and other such details are left as an exercise.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
A circular buffer will suffer from loops, that can swamp
the buffer if taken several hundred times, not an uncommon
thing in computer programs.

Of course is simple and easy to implement. But there
must be scientists that have researched this before, (at
least I think), and that have better solutions that either
mine or yours.

I mean tracing a program is not a new thing...

In Google I found only links about manual tracing,
some exercises for a university class...

In citeseer I found
Optimally Profiling and Tracing Programs
http://citeseer.ist.psu.edu/ball92optimally.html
but it is from 1992. I thought there could be more recent
work.

In any case I will start trying to understand that one.
It isn't easy reading... sigh.
Nov 14 '05 #7
"jacob navia" <ja***@jacob.remcomp.fr> wrote in message news:<ce**********@news-reader5.wanadoo.fr>...
A circular buffer will suffer from loops, that can swamp
the buffer if taken several hundred times, not an uncommon
thing in computer programs.

Of course is simple and easy to implement. But there
must be scientists that have researched this before, (at
least I think), and that have better solutions that either
mine or yours.

I mean tracing a program is not a new thing...

In Google I found only links about manual tracing,
some exercises for a university class...

In citeseer I found
Optimally Profiling and Tracing Programs
http://citeseer.ist.psu.edu/ball92optimally.html
but it is from 1992. I thought there could be more recent
work.

In any case I will start trying to understand that one.
It isn't easy reading... sigh.

It's something some Lisp systems can do. Maybe you could have a look
at the code of one.
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Albert Ahtenberg | last post by:
Hello, I had some bad experience with code organization and script functionality in writing my php based applications. And as the applications get bigger in scale it gets even worse. Therefore,...
1
by: Manfred Schwab | last post by:
Recording messages and print statements in a textfile during program execution. Is there a similar command to redirect errormessages or print statements into a standart asciifile during...
6
by: Dovelet | last post by:
Hi all, I would like to write DOS program to change the MS Windows Sound Recording source. When I run it with the parameter, it will change the recording source as follow: C:\> abc.exe...
1
by: Brett | last post by:
I'd like to have all of my documentation in one place. I use the following for documenting code: - attributes for certain types of documentation - use of the C# generated inline XML...
1
by: Sakharam Phapale | last post by:
Hi All, I am developing an application like sound recorder. While recording if there is a silence for more than given time (say 5 seconds), Recording should be paused.
7
by: Seymour | last post by:
I am trying to find a way to sign onto my Wall Street Journal account (http://online.wsj.com/public/us) and automatically download various financial pages on stocks and mutual funds that I am...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
6
by: Crooter | last post by:
Hello colleagues, Could anybody tell me if there are existing open-source solutions to extract the program tree using a program source code? I'm aware that GCC has program flow information and...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.