Community
Participate
Working Groups
Build Identifier: Eclipse 3.7.0 (Build id: I20110613-1736), CDT 8.0.0 (Build id: 201106081058) Problem Description ------------------- The Windows PE binary parser in CDT does not return global variables (which the ELF binary parser in CDT does). This bug report supercedes the old bug report 238081. We encounter this problem in our Eclipse/CDT based product when we programatically use the Windows PE binary parser in CDT. The easiest way to reproduce this problem without writing code is to list the global variables in the Variables view in CDT, which may be configured to use the Windows PE binary parser. Solution -------- The Windows PE binary parser in CDT (org.eclipse.cdt.utils.coff.parser.PEBinaryObject) does not handle global variables correctly. When going through the symbol table it uses a filtering criteria that only filters out the symbols for functions but not for variables. The problem is that it filters the symbol table by looking for the symbol type field (e_type), and it only tries to keep the following types: DT_PTR 01 Pointer to T DT_FCN 10 Function returning T DT_ARY 11 Array of T While this works for functions in the symbol table, it does not work for variables because we can have variables that are neither pointers nor arrays and in fact GCC sets all the variables in the symbol table to be of the type DT_NON 00 No derived type Filtering for DT_NON as well is too weak because of its zero value (a lot of invalid entries would pass), so in order to have only the global variables added we have to filter for the storage class field (e_sclass) as well. If the symbol has the following storage class: C_EXT 2 External (public) symbol it is a global variable and we can add it to our list of global symbols. A patch, relative CDT 8.0.0, for the org.eclipse.cdt.utils.coff.parser.PEBinaryObject and org.eclipse.cdt.utils.coff.Coff classes in the org.eclipse.cdt.core plugin is provided. Reproducible: Always Steps to Reproduce: 1. Make sure that you have a MinGW or Cygwin GCC/GDB installed. 2. Create an empty C project for executables and choose the toolchain MinGW GCC or Cygwin GCC. 3. Open the properties dialog on the newly created project and choose "C/C++ Build -> Settings -> Binary Parsers". Select the "PE Windows Parser" and deselect the "Cygwin PE Parser" (which works since it's only a wrapper around binutils and contains no symbol handling in its Java code). 4. Add the attached file test.c to the project and build it. 5. Create a "C/C++ Application" debug launch configuration and choose "Standard Create Process Launcher" as launcher. 6. Launch the debugger; you should now be in the main() function in test.c. 7. Single-step to one of the printf() lines in test.c. 8. Choose "Add Global Variables..." in the Variables view. Notice that the list of global variables is empty when at least "my_global_var" from test.c should be there.
Created attachment 202317 [details] Simple test program for exemplifying the bug
Created attachment 202318 [details] Patch for org.eclipse.cdt.core/src/org/eclipse/cdt/utils/coff/Coff.java
Created attachment 202319 [details] Patch for org.eclipse.cdt.core/src/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java
Is there any chance of having this fix included in CDT 8.0.1? Can I do anything to facilitate that?
(In reply to comment #4) > Is there any chance of having this fix included in CDT 8.0.1? Can I do anything > to facilitate that? Hi, thanks for working on that. This can't go in 8.0.1 or 8.0.2 because it introduces new API (public members in a class that's not in an internal package). You can use API Tooling to see that. http://wiki.eclipse.org/CDT/policy#Using_API_Tooling The new public members will need @since tags. Also, could you generate a single patch that can apply inside Eclipse? Here's a video that shows how to do it with EGit: http://www.youtube.com/user/cdtdoug#p/a/u/2/Lhwi3z2DyzQ