使用控制台输入进行Eclipse调试 [英] Eclipse debugging with input from console

查看:131
本文介绍了使用控制台输入进行Eclipse调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试使用Eclipse用C ++编写的程序。
该程序包括从用户那里获取输入,但是当我将输入输入到控制台时,它将永远不会继续运行代码(它将继续要求输入)。
如果不解决此问题,我将无法调试,希望对您有所帮助。
谢谢。

I'm trying to debug a program I wrote in C++ using Eclipse. The program includes getting input from the user but when I enter the input to the console it won't ever continue running the code (it'll keep asking for input). I can't debug without fixing this and would appreciate some help. Thank you.

代码被困在while循环fgets中:

The code gets stuck on the while loop fgets:

int main(int argc, const char**argv) {
    FILE* inputFile = NULL;

    setlocale(LC_ALL, "");
    if(argc == 2){
        inputFile = fopen(argv[1], "r");
        if (inputFile == NULL){
            printf("Problem opening file %s, make sure correct path name is given.\n", argv[1]);
            return 0;
        }
    }
    else {
        inputFile = stdin;
    }

    char buffer[MAX_STRING_INPUT_SIZE];
    // Reading commands
    while ( fgets(buffer, MAX_STRING_INPUT_SIZE, inputFile) != NULL ) {
        fflush(stdout);
        if ( parser(buffer) == error ){
            printf("ERROR\n");
            break;
        }
    };
    fclose(inputFile);
    return 0;
}


推荐答案

问题来自Eclipse缓冲控制台输入。
修复它的一种方法是强制Eclipse使用Windows / DOS本机控制台进行调试。

The issue comes from Eclipse buffering the console inputs. One way to fix it is to force Eclipse to debug using a Windows/DOS native console.

详细说明了该过程,但要简短地说:

The procedure is described in details here, but in brief :


  1. 从Eclipse菜单文件>新建> C ++项目

  2. 创建您的Hello World C ++命令行项目,在您的项目文件夹中,创建一个。 gdbinit文本文件。它将包含您的gdb调试器配置

  3. 编辑 .gdbinit,并添加以下行(不带引号): set new-console on

  4. 在Eclipse中,转到菜单运行>调试配置,然后在左窗格中选择您的应用程序名称

  5. 在调试器标签中,立即确保 GDB命令文件指向您的 .gdbinit»文件。否则,输入 .gdbinit配置文件的路径

  6. 单击应用和调试。你完成了 !应该启动本机DOS命令行。

  1. Create your Hello World C++ command line project, from the Eclipse menu File > New > C++ Project
  2. In your project folder, create a ".gdbinit" text file. It will contain your gdb debugger configuration
  3. Edit ".gdbinit", and add the following line (without quotes) : "set new-console on"
  4. In Eclipse, go to menu Run > "Debug Configurations", and select your application name in the left pane
  5. In the "debugger" tab, ensure the "GDB command file" now points to your « .gdbinit » file. Else, input the path to your ".gdbinit" configuration file
  6. Click « Apply » and « Debug ». You’re done ! A native DOS command line should be launched.

这篇关于使用控制台输入进行Eclipse调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆