Question

I have a C++ project in Ubuntu 12.04. To run the project the make file requires the following files:

1-All the .cpp files

2-All the .h files

3-Three shared libraries.

The project is fully functionall and performs according to the specifications. All the required .cpp files and .h files are available. The problem is that there is no main() function in any of the source files and the program entry point resides in one of the three shared libraries. My job is to find out the program execution pipeline and without having any main file I am not able to do that. I can't run the project in any IDE (i.e: eclipse) because there is no main function available.

Question: Can you please tell me how to find the program entry point?

P.S: I will be glad to provide any kind of information or material you may need to solve my problem.

Edit: The CMakeLists.txt file available here.

Edit 2: The build.sh file available here.

Was it helpful?

Solution

To find enty point look into each shared object with:

nm $library | egrep "T main$"

Library with main() will output something like

090d8ab0 T main

Very usefull way to visualize execution tree is to run:

valgrind --tool=callgrind ./my_executable -arg -arg ....

(you can abort execution early with Ctrl+C)

This will output callgrind.<pid> file. To visualize it run kcachegrind callgrind.<pid>.


You will need valgrind:

sudo apt-get install valgrind

and kcachegrind

sudo apt-get install kcachegrind

OTHER TIPS

Build it with the debug option -g and step into the program with a debugger like gdb (or cgdb or ddd). You'll need any appropriate debug libraries libraries though.

Short of that, play with the code a bit. Try putting printf or cout statements that print internal variables in any functions that look important, and see what the program status is and how frequently they get called. If main is hidden in a library, there's probably another function somewhere that behaves like main for the purposes of the API provided by whatever library has the real main.

What's the API documentation for your libraries? (is this a school project?). It sounds odd to have a hidden main and not say anything about it.

In case you use a build system (CMake, SCons, ...) it is highly possible that the build system is also generating some files, and one of them might be containing the main() method. We use this methodology when we generate the main function in order to instantiate classes for libraries that were specifically selected in CMake-gui.

And again, it is possible that the build system deletes the generated files due to some obscure policy the original developers thought of but didn't tell you. So search through your build system files, see what is actually happening there.

Edit

So, after seeing you CMakeLists.txt:

check ${DIR_EXT}/covis/src/ci.cpp where DIR_EXT is SET( DIR_EXT "../ext/" CACHE PATH "Folder holding external libraries" )

See what's in there and let us know :)

Edit2

After seeing build.sh (execute steps in order):

1. change

`cmake -D COMPILE_BINARY=ON ..` 

to

`cmake -D COMPILE_BINARY=ON -DCMAKE_BUILD_TYPE=Debug ..`

and add the same -DCMAKE_BUILD_TYPE=Debug to the other cmake command too.

This will build your library and executable in debug mode.

2. Now, in one of the c++ source files you have access to and you are sure will be called (the earlier the function will be calle the better), add:

asm("int $0x03");

This will create a breakpoint in your application.

(If you do not want to use this, see below).

3. Build your application.

4. Run it via a debugger in terminal:

gdb ./myapplication <ENTER>

(this will give you a gdb prompt)

(if you did not add the asm breakpoint from above, type in the gdb prompt: break filename.cpp:linenumber or break methodname to add a gdb breakpoint).

run <ENTER>

Now your application should stop in your function when it is executed. You are still in the gdb prompt, so type:

bt <ENTER>

This will print out the backtrace of your application. Somewhere you should see a main function, together with filename and linenumber.

However, that setnames.sh looks interesting, see if it does not do anything funny :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top