Click here to Skip to main content
15,883,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi there,
I am trying to create an application which should do the following:

1. It should parse an executable C/C++ program and insert appropriate comments in that at appropriate positions... like: //main starts....//call to fun1...etc.

2. It should create a tree/ control flow graph of the application

3. It should provide the dynamic information about the input like...how much it takes to execute and which loop/function takes the most time etc etc.


1 and 2 I am able to achieve by parsing the input program using flex and bison....third point is a problem..cause I dont have any idea how to do it.....shall I attach a debugger to my application..if yes then shall I create it or I can attach any one...or can I use the information from a custom build debugger...plz help....
Posted

It depends on the platform, but it looks like your don't have to "attach" the debugger. You simple need to run the code under debugger and go by breakpoints and then step-by-step.

The term "attach" the debugger refers to much more complex debugging problem when it is not possible to run the code under debugger. Example of such cases include debugging of Windows Service of some code started when the OS is being loaded. In some cases, you can attach the debugger to already running process. I don't see where you need it.

For more information, you need to see the documentation of your debugger: they are all different, especially on different platforms.

—SA
 
Share this answer
 
Comments
nautiyal.sudhanshu 21-Mar-11 4:34am    
Thanks for the reply..but I am afraid you din't understand my question....
I dont want to debug my application.....I want to create an application which could be used to extract runtime information from the input programs like the most time consuming loop and all........SO I was asking tht whether I need to include a debugger in my application to get run time information of input programs or there is any other easier way??.....
hope you understand now...
Thanks for the reply
Sergey Alexandrovich Kryukov 21-Mar-11 5:08am    
You see, with the title like the one you have written for your question, it is easy to get confused. Imagine normal reaction: I look at the title and see: aha, OP wants to use debugger, quickly scan the text of operation -- nothing special, so... here is how to use debugger.

Anyway, I'm sorry for confusion.

Now I understand, however not completely. You need to explain, what, source code of the program is not available for all cases?

First, about the debugger. 1) You don't include a debugger in the application, you include debug information, a debugger is a program, include it or not; 2) it won't help you much: you will be able to get the names, so what? With the level of the task you're working at, you need to understand how the debugger works better.

More importantly, you should understand that your cannot solve (#3) based on analysis; there is a well-known theorem of computability, it proves theoretically impossible even to predict in general case if the program take infinite time to run or not. If you experimentally run the program and time different parts of run-time, this is a regular profiler, it measures only the timing on _this_ very runtime, nothing else. If this is what you want, try to find information on existing profilers.

Other parts of your problems are at least extremely difficult, if solvable in principle; and hard to understand why. To me, it looks like you're not seriously enough into it. In your understanding the complexity of the problem is seriously underestimated.

--SA
nautiyal.sudhanshu 21-Mar-11 6:38am    
Yeah..I am sorry for the misleading title but I din't know how to give it a good title...anyways...
And I know that the problem looks complicated thats why it was given to me and I dont have any idea how to do it....but there are a lot of simplification I have made in the problem...some of them are:

1. No we are not calculating time complexity of an algorithm of the program and all we just want to get as you put it "Profiling information"..I mean in this run how much time it takes and all stuff...
2. The application is targeted towards the maintainers of legacy systems or new developers and testers who need to understand the complex code flows quickly. It will be achieved by providing a tree or flow chart kind of diagram based o the control flow of the program.
3. We also need to generate some test case suggestion to the peron using the application.

I believe some of your questions are answered now..If not I am so sorry...I have just one month to complete this project and I am totally bewildered about it...yes feasibility of the project is questionable but there is nothing I can do about it.....my basic idea to solve this problem is

1-> Parse the input using lex and yacc and collect as much inf as is possible ...which can be used to create the trees and other stuff..
2-> run the input program and get the required run time information..I thought a debugger would do this work but you are telling a profiler would do it...so this part is yet to be solved...

.....Once again my knowledge and experience on this subject is limited so please excuse me if I am acting as a total fool at some places...but I really don't understand it much...and I am trying hard to get it done perfectly...so please bear with me..:)
Sergey Alexandrovich Kryukov 21-Mar-11 22:27pm    
Thank you for the explanations. It looks like development utility. From this idea, I guess you can use the source code for analysis (is that right?).

I remember something like that in 198x, much less ambitious though. The biggest practical development in the field of static code analysis I know was in Microsoft's Singularity OS, but that is a managed platform. I read Microsoft research work aimed to overcome limitation of the fact that a halting problem is undecidable, based on the idea that the class of algorithms under consideration should be narrowed still allowing for practically significant cased. guess your can use source code.

To me, the feasibility of the project is more than questionable, and this is not just and not so much due to the complexity of the problem, but due to the general approach where you are not armed with any theory of knowledge on existing approaches and probably don't have time for research. I fail to understand what can be done here. Just working in some direction being blindfolded can turn to a mere time loss...

Anyway, good luck.
--SA
nautiyal.sudhanshu 22-Mar-11 14:38pm    
Yes we can get the source code for the static analysis.
Well as far as the feasibility and complexity of the project are concerned we have simplified the objectives of the project...

So now we are not analyzing anything but just representing the data in a comprehensive manner..which contains a control flow graph of the input program along with the no. of loops and all.
as far as the profiler was concerned we are just trying to get some run time information about the program like how many clock cycle does a particular loop of the program run at tht time and all....
Even now the stuff looks really high fi to me...so i would really appreciate all the help I can get in this project...If you can just guide me into the right direction I d be greatful....

Thanks for the help...
Put the breakpoint and press f5. Microsoft has provided the debug window which can have the all break point lines.
No need to attach any aditional debugger to the application.
 
Share this answer
 
Comments
nautiyal.sudhanshu 22-Mar-11 6:28am    
Thanks for the reply..but I am afraid you din't understand my question....
I dont want to debug my application.....I want to create an application which could be used to extract runtime information from the input programs like the most time consuming loop and all........SO I was asking tht whether I need to include a debugger in my application to get run time information of input programs or there is any other easier way??.....
hope you understand now...
Thanks for the reply
it depends on the OS and the debugger your attempting to use if its is windows i suggest win debug attaching the debugger is not a simple process as you need to provide the symbols (generated when you compile the application)

if you want to analysis the behavior of a program (like a profiler) you need to trace the stack and heap and then analyse the information acquired. note this not trivial stuff and it can get pretty complex

Good Luck!!
 
Share this answer
 
Comments
nautiyal.sudhanshu 22-Mar-11 6:30am    
Yes Actually I do want to create a profiler...I used the term debugger by mistake...Main requirement of my project is to get the execution time of different loops or functions.....Can you atlest guide me how to achieve this????...cause I am stuck at this point...
Kurt Degiorgio 1-Apr-11 10:32am    
http://msdn.microsoft.com/en-us/library/ms679288(v=VS.85).aspx check that out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900