Eclipse : How to debug a C++ console application using a native Windows console instead of the IDE integrated one ?

You’re using Eclipse to develop a C/C++ Windows command line application, and instead of debugging using the Eclipse integrated console you would like to use a native DOS/Windows console. Some reasons to do so are that the Eclipse integrated console doesn’t deal very well with some DOS console features (like cursor positioning), and it may buffer some inputs. Happily, it is possible to configure Eclipse to use a native console !

The following steps describe in details the procedure to follow. Else, you can download from here a sample “HelloWorld” Eclipse C++ project which is configured to use an external DOS console for debug.

  1. Create your Hello World C++ command line project, from the Eclipse menu File > New > C++ Project :
    Eclipse-HelloWorldC++
  2. In your project folder, create a “.gdbinit” text file. It will contain your gdb debugger configuration
  3. Edit “.gdbinit”, and add the line (without the quotes) : “set new-console on”
    (or download the file from here)
  4. In Eclipse, go to menu Run > “Debug Configurations”, and select your application name in the left pane :
    Eclipse-Debug configurations
  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 :
    Eclipse-debug-command-line-config
  6. Click “Apply” and “Debug”. You’re done ! A native DOS command line should be launched.
  7. Eclipse-debug-command-line

 

8 thoughts on “Eclipse : How to debug a C++ console application using a native Windows console instead of the IDE integrated one ?

  1. sumanta karmakar

    After searching a lot found your blog ……… saved my week……….

    Thanks buddy thanks a lot………….

    Reply
  2. Symor Moose

    Really good Post Worked like a charm……
    Please do me one more favor and i’ll be in your debt. While I am running the debugger output is coming fine in the cmd console but the variable values showing in hexadecimal format in eclipse panel instead of decimal… and in the native console of eclipse showing the errors i pasted below.
    I guess this has to do something with the .gdbinit file….. may be the file i am using is not appropriate… yes the .gdbinit file link is broken i had to download it from other sources.

    Any idea what i am missing…………
    Whatever it is… Thanks Again…… You stopped my continuous search of 2 weeks…
    —————————————————- CONSOLE OUTPUT——————————————————————
    The target endianness is set automatically (currently little endian)
    [New Thread 4308.0x15ec]
    ———————————————————————————————————————–[regs]
     RAX: 0xError while running hook_stop:
    Value can’t be converted to integer.
    Error while running hook_stop:
    Value can’t be converted to integer.
    ———————————————————————————————————————–[regs]
     RAX: 0xError while running hook_stop:
    Value can’t be converted to integer.
    ———————————————————————————————————————–[regs]
     RAX: 0x———————————————————————————————————————–[regs]
    Error while running hook_stop:
    Value can’t be converted to integer.
     RAX: 0x———————————————————————————————————————–[regs]
     RAX: 0xError while running hook_stop:
    Value can’t be converted to integer.
    Error while running hook_stop:
    Value can’t be converted to integer.
    ———————————————————————————————————————–[regs]
     RAX: 0xError while running hook_stop:
    Value can’t be converted to integer.
    ———————————————————————————————————————–[regs]
     RAX: 0x———————————————————————————————————————–[regs]
     RAX:Error while running hook_stop:
    Value can’t be converted to integer.
    0x———————————————————————————————————————–[regs]

    Reply
  3. Sep

    Hi,

    Thank you for your helpful post. I need to do the same thing but under Linux. Can you give me a hint on that? I tried this in my Ubuntu 12.04 OS, but doesn’t seem to be working!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *