473,769 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1853
"jacob navia" <ja***@jacob.re mcomp.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[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof 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.re mcomp.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_Keit h) 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.re mcomp.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
4649
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, I am trying to build a general schema for data flow in a php/mysql application. What I has in mind is to design a three major units. To handle the input, processing and data access. Plus another unit to generate the output.
1
2435
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 programm execution. I would like to echo the complete console output into a textfile and send this file as email at a certain point in time. The programm execution shall not be stopped.
6
2510
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 microphone <- the Sound recording source change to Microphone C:\> abc.exe line <- the sound recording source change to Line-IN
1
2012
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 documentation - simple comments I also use Visual Paradigm for UML (class relationships), which integrates with VS.NET. I need something for general documentation of program flow. Any suggestions on what to use for this?
1
1822
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
2949
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 interested in tracking. I have a subscription to this site and am trying to figure out how to use python, which I have been trying to learn for the past year, to automatically login and capture a few different pages. I have mastered capturing web...
8
3122
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 initialized before the program starts executing." -- What does this mean? What is the name of the stage in which the mentioned initialization is performed? Compile-time or run-time? In the following snippet, variables b and c are defined at line 7...
6
2440
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 tree respectively for optimization, but I'm looking for something less complicated. An ideal case would be a small program based on a parser with YACC compatible grammar which extracts the program flow tree. Best regards,
3
4486
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 of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee. Here is my Inventory program from 1 to 3: package...
0
9586
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.