【发布时间】:2014-11-02 16:20:01
【问题描述】:
我有一个 C++ 开源代码,它包含许多文件中的数千行代码,可帮助运行机器人手抓取模拟器工具。它有一个前端 GUI,可以选择导入各种机器人手和物体,并在它们上执行抓取动作。虽然我已经理解了一些正在使用的概念,并且通过浏览理解了一些源文件,但我无法大致了解整个过程是如何工作的。我想通过按下特定的 gui 按钮来确定正在调用哪些文件和函数。有没有办法从头开始调试软件 gui 代码?
我对自己编写的小代码的编写技术和分步调试技术有所了解,但是对于包含数百个文件和数百个对象的代码来说这样做太令人困惑了。
此外,调试菜单有两个我可以使用的选项,1-调试项目:这样做时,用户界面窗口会绕过我放置的断点打开。 2- step into:它总是从 Disassembly (main) 开始,step over,out 不再变灰,我可以使用它们。那是代码的汇编语言吗?有没有更简单的调试方法?
我们将不胜感激任何形式的指导和帮助。
编辑:下面列出的是开源代码的主文件,由于声誉较低,不能发布带有断点的快照,在 cmets 中提到它们。
/*! \file
\brief Program execution starts here. Server is started, main window is built,
and the interactive loop is started.
The main call returns an exit code as indicated by the graspit GUI (0 by default)
to provide feedback to calling program, if desired.
*/
#define GRASPITDBG
#include <iostream>
#include <graspitApp.h>
#include "graspitGUI.h"
#include "graspitServer.h"
#include "mainWindow.h"
#ifdef Q_WS_WIN
#include <windows.h>
#include <wincon.h>
#endif
int main(int argc, char **argv) {
#ifdef GRASPITDBG
#ifdef Q_WS_WIN
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
//ios::sync_with_stdio();
#endif
#endif
//*******placed breakpoint1
GraspItApp app(argc, argv); //shows the GraspIt! logo splash screen in the
//center of the screen.
if (app.splashEnabled()) {
app.showSplash();
QApplication::setOverrideCursor(Qt::waitCursor);
}
//******* placed breakpoint2
GraspItGUI gui(argc, argv); // Implements the graspit user interface.
// Responsible for creating both MainWindow and IVmgr.
//This is the GraspIt TCP server. It can be used to connect to GraspIt from
//external programs, such as Matlab.
//On some machines, the Q3Socket segfaults at exit, so this is commented out by
//default
//GraspItServer server(4765);
app.setMainWidget(gui.getMainWindow()->mWindow);
QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
if (app.splashEnabled()) {
app.closeSplash();
QApplication::restoreOverrideCursor();
}
if (!gui.terminalFailure()) {
gui.startMainLoop();
}
return gui.getExitCode();
}
【问题讨论】:
-
在您的代码中放置断点,在调试模式下从 netbeans 运行项目并检查何时遇到断点。你的小代码有什么区别?
-
我在调试模式下运行,但我不确定在哪里放置断点。主文件只包含一个用于启动屏幕的类对象和另一个用于创建 GUI 的类对象,以及用于与 MATLAB 等软件进行外部集成的更多代码行。我在 GUI 文件中随机放置了断点,但是当我按“Step into”进行调试时,模拟器 GUI 出现了,我没有看到调试器在任何断点处停止。
-
您必须了解程序工作流程。要检查按钮是否正常工作,您必须研究代码并找出按钮调用了哪个插槽。
-
实际上我试图通过调试来了解工作流程,但是通过在调试模式下运行项目,GUI 窗口似乎绕过了我在创建主窗口之前放置的所有断点。
-
在命令行中使用
gdb调试器。
标签: c++ linux debugging user-interface netbeans