Bug 356077 - Windows PE binary parser in CDT does not return global variables
Summary: Windows PE binary parser in CDT does not return global variables
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-29 09:48 EDT by Stefan Bylund CLA
Modified: 2020-09-04 15:19 EDT (History)
3 users (show)

See Also:


Attachments
Simple test program for exemplifying the bug (241 bytes, text/plain)
2011-08-29 09:51 EDT, Stefan Bylund CLA
no flags Details
Patch for org.eclipse.cdt.core/src/org/eclipse/cdt/utils/coff/Coff.java (902 bytes, patch)
2011-08-29 09:54 EDT, Stefan Bylund CLA
no flags Details | Diff
Patch for org.eclipse.cdt.core/src/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java (1.35 KB, patch)
2011-08-29 09:55 EDT, Stefan Bylund CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Bylund CLA 2011-08-29 09:48:58 EDT
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.
Comment 1 Stefan Bylund CLA 2011-08-29 09:51:18 EDT
Created attachment 202317 [details]
Simple test program for exemplifying the bug
Comment 2 Stefan Bylund CLA 2011-08-29 09:54:00 EDT
Created attachment 202318 [details]
Patch for org.eclipse.cdt.core/src/org/eclipse/cdt/utils/coff/Coff.java
Comment 3 Stefan Bylund CLA 2011-08-29 09:55:48 EDT
Created attachment 202319 [details]
Patch for org.eclipse.cdt.core/src/org/eclipse/cdt/utils/coff/parser/PEBinaryObject.java
Comment 4 Stefan Bylund CLA 2011-09-07 05:10:32 EDT
Is there any chance of having this fix included in CDT 8.0.1? Can I do anything to facilitate that?
Comment 5 Marc-André Laperle CLA 2011-09-07 13:04:01 EDT
(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