热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法在C++项目中找到程序入口点-Can'tfindprogramentrypointinaC++project

IhaveaC++projectinUbuntu12.04.Toruntheprojectthemakefilerequiresthefollowingfiles:

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

我在Ubuntu 12.04中有一个C ++项目。要运行项目,make文件需要以下文件:

1-All the .cpp files

1 - 所有.cpp文件

2-All the .h files

2 - 所有.h文件

3-Three shared libraries.

3-Three共享库。

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.

该项目功能齐全,可根据规格执行。所有必需的.cpp文件和.h文件都可用。问题是任何源文件中都没有main()函数,程序入口点位于三个共享库之一。我的工作是找出程序执行管道,没有任何主文件,我无法做到这一点。我无法在任何IDE中运行该项目(即:eclipse),因为没有可用的主要功能。

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.

P.S:我很乐意提供您解决问题所需的任何信息或材料。

Edit: The CMakeLists.txt file available here.

编辑:此处提供的CMakeLists.txt文件。

Edit 2: The build.sh file available here.

编辑2:此处提供build.sh文件。

3 个解决方案

#1


4  

To find enty point look into each shared object with:

通过以下方式查找每个共享对象的内容:

nm $library | egrep "T main$"

Library with main() will output something like

带main()的库将输出类似的内容

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)

(您可以使用Ctrl + C提前中止执行)

This will output callgrind. file. To visualize it run kcachegrind callgrind..

这将输出callgrind。 文件。要想象它运行kcachegrind callgrind。


You will need valgrind:

你需要valgrind:

sudo apt-get install valgrind

and kcachegrind

sudo apt-get install kcachegrind

#2


0  

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.

使用调试选项-g构建它,并使用调试器(如gdb(或cgdb或ddd))进入程序。但是,您需要任何适当的调试库库。

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.

没错,请稍微玩一下代码。尝试将printf或cout语句放在任何看起来很重要的函数中打印内部变量,并查看程序状态以及调用它们的频率。如果main隐藏在库中,那么可能存在另一个函数,其行为类似于main,用于由任何库具有真正的main提供的API。

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.

您的库的API文档是什么? (这是一个学校项目吗?)。拥有一个隐藏的主体并且没有任何关于它的说法听起来很奇怪。

#3


0  

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.

如果您使用构建系统(CMake,SCons,...),构建系统很可能也生成一些文件,其中一个可能包含main()方法。当我们生成main函数时,我们使用这种方法来实例化在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:

所以,在看到你CMakeLists.txt之后:

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

检查$ {DIR_EXT} /covis/src/ci.cpp其中DIR_EXT是SET(DIR_EXT“../ext/”CACHE PATH“文件夹持有外部库”)

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

看看那里有什么,让我们知道:)

Edit2

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

看到build.sh后(按顺序执行步骤):

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.

并将相同的-DCMAKE_BUILD_TYPE = Debug添加到另一个cmake命令中。

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:

2.现在,在您可以访问的一个c ++源文件中,您确定将被调用(函数越早越好),添加:

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.

3.构建您的应用程序。

4. Run it via a debugger in terminal:

4.通过终端中的调试器运行它:

gdb ./myapplication 

(this will give you a gdb prompt)

(这会给你一个gdb提示)

(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).

(如果你没有从上面添加asm断点,请输入gdb提示符:break filename.cpp:linenumber或break methodname以添加gdb断点)。

run 

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

现在,您的应用程序应在执行时停止在您的函数中。您仍然在gdb提示符中,因此键入:

bt 

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 :)

但是,setnames.sh看起来很有趣,看看它是不是做了什么搞笑:)


推荐阅读
author-avatar
邻居小明
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有