Table of
contents
3.2 Address abstraction IAddress interface
3.4 Binary parser enhancements
CDT 2.0 has
several problems that prevent it from usage for 64-bit platform. They are as
follows.
l
Problems with
addresses
CDT uses Java long type
to manipulate with pointers
CDT assumes that
addresses may be ONLY 32bit
All address operations
are done as regular Java long operations (+,-,<,>,==)
l
C/C++ long type is
handled correctly
CDT assumes that long
is 32bit length however it is 64 bit length on Linux 64bit platforms and 32 bit
length on Windows 64bit platform
l
ELF64 binary format
which is used on Linux 64bit platforms is not supported
As the result
information about following binary files is not displayed correctly in C/C++
perspective
l
Object files - *.o
files
l
Shared libraries - *.so
files
l
Binary archives - *.a
l
Binary executables
Design
solution was concentrated on minimizing modifications to the CDT concept and on
providing extensible solution. Each problem was addressed respectively.
l
Introduce new type
to handle pointers in CDT
Introduce new interface
which supports all operations necessary for pointers
Replace all use cases
where address is interpreted as Java long are with new interface
Introduce address factory
to enable creation of particular address object
l
Enhance ELF binary
parser to support ELF64 binary format
l
Correct interpretation of long C/C++
variables
Following
plug-ins should be modified during CDT enhancement
org.eclipse.cdt.core
org.eclipse.cdt.debug.core
org.eclipse.cdt.debug.mi.core
org.eclipse.cdt.debug.ui
org.eclipse.cdt.debug.mi.ui
Key point
of 64bit support is new interface called IAddress.
l
Represents C/C++
address in CDT
l
Has all methods necessary to manipulate
address
Comparison
Add/Subtraction
Conversion to string
Address
interface is defined as follows
public interface IAddress
{
IAddress add(BigInteger offset);
BigInteger getMaxOffset();
BigInteger distance(IAddress other);
int compareTo(IAddress addr);
boolean equals(IAddress addr);
boolean isZero();
boolean isMax();
String toString(int radix);
String toString();
String toHexAddressString();
int getDigitsNum();
int getCharsNum();
}
l
Two new classes are defined to
implement new interface Addr32 and Addr64. These classes provide concrete
behavior of addresses depending on target system
l
All places in CDT where addresses were
interpreted as Java long type were replaced with IAddress
abstraction
Because
address is represented as Java interface in CDT we need address factory to have
ability to create address objects
Address
factory is defined as an interface which supports address creation
public interface IAddressFactory
{
IAddress getZero();
IAddress getMax();
IAddress createAddress(String addr);
IAddress createAddress(String addr, int
radix);
}
Two new
classes are defined to implement address factories Addr32Factory and
Addr64Factory. These classes provide concrete behavior of addresses factories
depending on target system
Modification
to binary parser consists of two changes
i. Java long is steel used as offset in
ELF64 file because all Java I/O method operates with long as file offset.
Offset is only used to read information from ELF64 file, so it is impossible to
have offsets greater than Long.MAX_VALUE
Access to
address factory is required on different levels of CDT model. Several elements
of CDT model were enhanced to have references to IAddressFactory
to provide ability to create address objects on different levels of CDT model.
They are
l
IBinary represents binary file in C model
l
CDebugTarget represents C debug target. It is
used to communicate to upper Eclipse debug framework org.eclipse.debug.core
and to provide information to debug UI level
l
Target represents
debug target in terms of CDI (Common Debug Interface) model on MI level.
As the
result
l
CDT operates address
abstractions which encapsulate particular addresses behavior
l
Polymorphism of
addresses is provided using address factories
l
Concrete address
factory is created based on format of executable
l
Modifications to CDT
are minimal
All places where
address is used as Java long were replaced with IAddress
l
CDT does not depend
on address nature
In future we may invent
16bit address for embedded systems for example
In this case we will
need to provide proper binary parser and debugger. There wont be need to
modify CDT.
l
IAddress fully encapsulates address behavior
Places where addresses
are manipulated are clear to understand and maintain
No need to have
utilities to convert Java long to address string
l
The same version of CDT code is able to
work with 32bit and 64bit applications (And any other address size in the
future)
It is possible to have
two debug sessions now with different targets. For example
One local session for
32bit application
And remote for 64 bit
application