How to Access a Text File While Debugging with Eclipse Cdt

how to access a text file while debugging with eclipse CDT

It could be an issue with relative paths. Is input.txt in the root directory of your project? Eclipse makes the top-level directory of the project the working directory. If you replace "input.txt" in your code with the fully qualified file name, that should also work.

how to access a text file while debugging with eclipse CDT

It could be an issue with relative paths. Is input.txt in the root directory of your project? Eclipse makes the top-level directory of the project the working directory. If you replace "input.txt" in your code with the fully qualified file name, that should also work.

Eclipse c++ debugging executable is not finding the file with relative path

I guess work directory is different for both cases, and thats why you can not open your file. Try to use absolute path for fopen() or look for a way to specify proper work directory for the second case.

There is a way to modify the working directory, as mentioned in this answer:

  • right-click on binary/executable Debug As -> Debug Configuration ...
  • in Arguments tab, in the bottom, there is a Working directory: area, uncheck the Use default and add the correct path (where is the executable/binary). The buttons Workspace... and File System... may help

How to create a debug file for an imported project in Eclipse?

You need to add the option "-g" to the flags for compiling and linking. This adds debugging symbols to the application.

Viewing complete strings while debugging in Eclipse

In the Variables view you can right click on Details pane (the section where the string content is displayed) and select "Max Length..." popup menu. The same length applies to expression inspector popup and few other places.

Sample Image

Controlling Eclipse CDT debugger output?

Note that you don't want a general way of drilling down into objects; you want to pretty-print STL containers.

I think CDT delegates this to the debugger backend; i.e. it is up to your debugger (gdb, perhaps?) to inform CDT about the value of a variable and how it can be expanded.

Edit: I don't think that the GDB backend shipped with CDT has any support for "intelligent" display of STL containers. If you're really interested in this, I'd suggest that you contact the CDT development team at cdt-dev@eclipse.org.

Update/Edit: Please see other responses below for instructions on how to enable pretty printers in CDT.

Better variable exploring when debugging C++ code with Eclipse/CDT

You need a version of GDB capable of using python to pretty print structures. I know at least on windows using mingw that this is not provided in the default install.

Pretty Printers are python modules which tell gdb how to display a given structure. You can write your own, but there are already printers for STL available for download.

To Get Pretty Printers working on Windows (instructions should be similiar for other OS's):

Prerequisites

  • Make sure you have you have Python 2.7 installed and in the system path.

    http://www.python.org/download/

  • Make sure MinGW-get is installed

    http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/

  • Make sure you have an SVN client are installed

Installation:

  • Open a command Shell and type:

    mingw-get install gdb-python
  • When its finished cd to a local directory and install the printers by typing:

    svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
  • Open the .gdbinit (create it in a text editor if need be) and type the following replaceing "C:/directory" with the folder that you checked the printers into.

    Python

    import sys

    sys.path.insert(0, 'C:/directory')

    from libstdcxx.v6.printers import register_libstdcxx_printers

    register_libstdcxx_printers (None)

    end

Eclipse Setup

  • Go To Windows > Preferences > C/C++ > Debug > GDB
  • Where it Says GDB Debugger put the path to the python enabled GDB it will most likely be in the mingw /bin folder with a name like gdb-python27.exe
  • Where it says GDB Command File put the path to the .gdb init file you made earlier.

That's it, debug like normal, the stl structures should be much easier to read.

How to allocate an input file instead of the stdin in an Eclipse CDT application?

In fact, solution 1 was using a relative path not related to the working directory. Using either button Workspace... or File System... in the GUI enables to select the files which shall already exist.

For example with Workspace definition, the field becomes :

${workspace_loc:/myprogram/inputfile.txt} (same for output)

And it works. Debuggers says :

[Console output redirected to file:/.../myprogram/outputfile.txt]



Related Topics



Leave a reply



Submit