How can I find out what functions have been called from what classes? - c++

I'm using a Physics Toolkit (Geant4) which consists of several thousand C++ header and class files. In order to use the toolkit, you have to write a series of your own class files, that give the toolkit some basic information about what you are trying to model. You then write a main() file which registers these files with the toolkit, 'make' it and then execute the final program. I am using Ubuntu 10.10 as the platform to do this.
I'd like to better understand how the toolkit operates. Specifically, I'd like to find out what functions in what class files, throughout the toolkit, are called and in what order, when the program runs.
One, somewhat brute-force method would be to label each function in each file e.g. insert cout << "File Name, Function Name" << endl as the first statement in each function body and have this all output to a textfile. However, there are some 3000 files I'd need to go through, which would be somewhat... time-consuming.
Is there an easier way of finding out what functions have been called? I've searched through the toolkits manual and, unless I have missed something, I see no way there of doing this via the toolkit. I guess I would need some command at the terminal or an external program?!?
Any help, suggestions or advice would be greatly appreciated!

On ubuntu you'll have a choice of profilers.
I personally love
valgrind --tool=callgrind ./myprogram
kcachegrind
For this because it creates very good callgraphs and statistics (tree map visualizations).
The big FAQ profiler topic is here: How can I profile C++ code running in Linux?
Off the top off my head: gprof (needs instrumentation), oprofile and perf record -g are easy to get started with as well

Related

Callgrind: How to use Callgrind tool to evaluate function speed

I am interested in testing speed of some function calls from the code written in C/C++. I searched and I was directed to use Valgrind platform with Callgrind tool.
I have briefly read the manual, but I am still wondering how I can utilize the functionality of the tool to evaluate the time of my function runtime speed.
I was wondering if I could get some pointers how I can achieve my goal.
Any help would be appreciated.
Compile your program with debug symbols (e.g. GDB symbols works fine, which are activated with the "-ggdb" flag).
If you are executing your program like this:
./program
Then run it with Valgrind+Callgrind with this command:
valgrind --tool=callgrind ./program
Callgrind will then produce a file called callgrind.out.1234 (1234 is the process ID and will probably be different when you run). Open this file with:
cg_annotate callgrind.out.1234
You may want to use grep to extract your function name. In the left column the number of instructions used for that function is displayed. Functions that use a comparatively low amount of instructions will be ignored, though.
If you want to see the output some nice graphics, I would recommend you to install KCachegrind.

DBGP Implementation C/C++

Is there a Library that implements XDebug's DBGP in C/C++?
I'm interested in wrtting debugger and if such library exists will save me a lot!
I want to add the debugger to my editor coded in C++ Language but it is an editor for PHP Files.
None Exists. There was one from GSOC (App not a library) but I cannot take time to read and convert to my needs plus its written for wx2.8
So I will roll a class to Just glue up with my Editor
Edit
I ended using that one as I said.
Inside there is buggy libDBGp but I will fix it myself huh!
If you are interested its here (thanks to GitHub)
There are a few GDB based libraries that help debugger frontend writers like libgdb. DBGP is a very stupid and protocol with very small feature set - not enough for debugging C++.
For windows there is nothing like this. You can read the PDB database but it's pretty difficult. I spend a week to see how far i can get but wasn't very successfull. only the theory is easy. It might be better to write a frontend for the command line debugger windbg just like in the old days where you had to do this for GDB.

Taking an Input from a C++ Gui into another C++ program

I am currently developing a C++ program that does all the mathematical calculations, prints items to the screen that is scanned in by an RFID Reader, and allows the user to select a payment method. (Basically using RFID tags to replace barcodes)
I have started writing my C++ code for a keyboard entry and have no idea how to take an input from my RFID reader into my program. My RFID Reader is a DLP-RFID1 from it comes with some demo software and drivers. I got it working with windows 7 last week on the demo software(a GUI using Microsoft Visual Studio).
My question is can I take the input from my Demo GUI and some how use that as my input for my C++ program? If I can can some one push me in the right direction by links, pointers, reading material?
Also I have basic C++ experience. I am teaching myself how to program in C++ and right now only know print statements, while loops, switch/case, math functions, and etc.
That is a very specific question about hardware and software of that vendor an not really general knowledge. However, those types of devices, in my past experience with bar code readers and such, usually have a driver that comes with them which allows you to set them up as an actual keyboard (for example, you could even go into a text editor and capture the codes). If you can set them up like that, then reading them is nothing more than reading stdin. For example, cin >> stringVariable;
Assuming that you have demo software in C++:
The demo software should link against one or more libraries that comes with the demo, and include a header that declares the functions in the library. You have to (at minimum) include this header and link against that same library, and use those libraries. The demo will help you understand which functions you need to call and how.
As already said it is very dependent on how they want you to use it but some general guide lines.
Look for header file that came with their demo ( ends in ".h" or ".hpp")
you will need to #include that in your project at the very minimum
Look for a .lib file. you will need to link that to your file. With gcc you would type something like G++ -l[libname].
With MSVS there are two ways i know of. You will need to right click the project in the sidebar. Click something like options or preferences. Expand linker options. Add the library.
or you can type #pragma comment(lib, "filename.lib") in your file near your includes
If there is a .dll (windows) or .so(Linux) file you can dynamically link it. There are many ways to do this. Google search for C++ Dynamic link libraries should be some help. As a newbie try to stick with Static Linking first. that would be another good keyword to search for. The best tutorial on dynamic linking for windows i have found is actually in assembly. but its all Win32 function calls anyways so its not hard to understand. Icz DLL tutorial

Generating a C++ classes from IDL file using MICO (CORBA)

I wan to generate a C++ classes from a IDL file using MICO in the contxet of CORBA. I download the mico-2.3.13.zip but iI don't know how to use it. Please if someone can help me and thanks all.
The answer would probably be longer that would comfortably fit in a short reply, but here are some pages with helpful starter info.
This class webpage has a mini tutorial using mico
http://www.cs.wichita.edu/~chang/lecture/cs843/program/mico-idl.html
Here's another fairly simple tutorial page
http://people.inf.ethz.ch/roemer/micodoc/node16.html
You first need to compile MICO from the sources. Depending on your operating system and environment this will require different steps. In linux/mac os x they are basically calling the ./configure script and then make if it did not fail. Under windows I think that you can call nmake directly (with some options, read the README files).
After compilation completes (this may take a few minutes) and if everything goes fine, you should have the executables and can use them to create your own CORBA interfaces and services.

How can I develop a virtual drive

I would like to create a virtual drive for windows. I'm not looking to map a drive or something like that, I'm looking to map it to my DLL functions or something of that sort.
How can I get this accomplished?
I read that I would have to develop a device driver, or a shell extension?
I have a lot of experience with C++ and C#. Where do I get started?
I want to make it as simple as possible at first, how much time do I think it would take me? And what's the simplest way to do it, so that I could build my prototype.
My motivation is to pipe a file into an application, that currently only reads files from the file system. I'm only interested in pumping 1 file, so I think that a whole virtual drive would be an overkill, as well as writing kernel mode code.
If you want to build it from scratch then yes, you have to build a driver. However, it would be much easier for you to use a proxy driver like Dokan, and create the file system in user mode.
Take a look at the Wikipedia article on IFS, there are links to other useful tools at the bottom of the page.
I don't know what it worth, and it's not open source, but I've found this. It's a "fuse" like for windows