Difference between revisions of "Debug generated C code"

(Mac OS X)
(Added useful entry for disabling ASLR on Windows)
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
To see the mapping between Eiffel classes and features to C files and their methods, the file '''TRANSLAT''' in the '''W_code''' or '''F_code''' directory is very useful.
 
To see the mapping between Eiffel classes and features to C files and their methods, the file '''TRANSLAT''' in the '''W_code''' or '''F_code''' directory is very useful.
  
== Unix ==
+
== Runtime ==
 +
 
 +
If you need to compile the runtime with debug information, follow the steps below. The steps below include a copy operation to the Eiffel installation directory, so make sure to make a backup before overriding the runtime files.
 +
 
 +
===Unix===
 +
Edit $EIFFEL_SRC/C/CONFIGS/$ISE_PLATFORM and perform the same substitution as above for Unix. Then type '''./quick_configure''' in the $EIFFEL_SRC/C directory.
 +
 
 +
Once this is done make sure to copy the debugged runtime files located under $EIFFEL_SRC/C/run-time/lib* to the EiffelStudio delivery under $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/lib.
 +
 
 +
===Windows===
 +
Edit the config file in $EIFFEL_SRC/C/CONFIGS that matches your platform and your C compiler. For example, windows-x86-64-msc is for Windows 64-bit using the Microsoft C++ compiler. Comment out the debug and optimize entry and replace them with their corresponding debugged version (currently commented below). Then in the $EIFFEL_SRC/C directory type '''configure win64 m''' (Windows 64-bit) or '''configure win32 m''' (Windows 32-bit) to compile the runtime for the Microsoft C++ compiler.
 +
 
 +
Once this is done make sure to copy the debugged runtime files located under $EIFFEL_SRC/C/run-time/lib/*.lib to the EiffelStudio delivery under $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/lib/$ISE_C_COMPILER.
 +
 
 +
==Application==
 +
=== Unix ===
 
There are 2 methods:
 
There are 2 methods:
 
* Edit $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/include/config.sh and
 
* Edit $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/include/config.sh and
 
*#To the value of '''wkoptimize''' add the '''-g''' option.
 
*#To the value of '''wkoptimize''' add the '''-g''' option.
 
*#Replace the value of '''optimize''' to disable the C optimization (usually '''-O0''') and add '''-g'''.
 
*#Replace the value of '''optimize''' to disable the C optimization (usually '''-O0''') and add '''-g'''.
* set the '''CFLAGS''' environment variable with '''-g'''
+
* set the '''CFLAGS''' environment variable with '''-O0 -g'''
  
 
Once you have done that, do in your W_code or F_code directory:
 
Once you have done that, do in your W_code or F_code directory:
Line 19: Line 34:
 
Now, the generated executable should contain debugger symbols. It can be debugged with gdb or ddd (Data Display Debugger).
 
Now, the generated executable should contain debugger symbols. It can be debugged with gdb or ddd (Data Display Debugger).
  
== Windows ==
+
=== Windows ===
 
After doing the changes below (depending on your C compiler), you can recompile your project from scratch and the debug information will be present.
 
After doing the changes below (depending on your C compiler), you can recompile your project from scratch and the debug information will be present.
  
=== MinGW ===
+
==== MinGW ====
 
Edit $ISE_EIFFEL\studio\config\$ISE_PLATFORM\$ISE_C_COMPILER\config.eif and perform the following edits:
 
Edit $ISE_EIFFEL\studio\config\$ISE_PLATFORM\$ISE_C_COMPILER\config.eif and perform the following edits:
 
# Replace the content of ''optimize'' by '''-O0 -g'''.
 
# Replace the content of ''optimize'' by '''-O0 -g'''.
 
# Replace the content of ''wkoptimize'' by '''-O0 -g'''.
 
# Replace the content of ''wkoptimize'' by '''-O0 -g'''.
  
=== Visual C++ ===
+
==== Visual C++ ====
 
Edit $ISE_EIFFEL\studio\config\$ISE_PLATFORM\$ISE_C_COMPILER\config.eif and perform the following edits:
 
Edit $ISE_EIFFEL\studio\config\$ISE_PLATFORM\$ISE_C_COMPILER\config.eif and perform the following edits:
 
# Replace the content of ''optimize' by '''-Od -Zi -MT'''.
 
# Replace the content of ''optimize' by '''-Od -Zi -MT'''.
 
# Search and replace all occurrences of '''-NODEFAULTLIB:libc''' by '''-NODEFAULTLIB:libc -DEBUG'''.
 
# Search and replace all occurrences of '''-NODEFAULTLIB:libc''' by '''-NODEFAULTLIB:libc -DEBUG'''.
 +
# Disable ASLR (Address Space Layout Randomization) would certainly help in having a consistent debugging experience across execution. This can be done by adding '''-DYNAMICBASE:NO''' after -DEBUG.
  
 
With Visual C++, you can have access to the Visual Studio C debugger which will let you attach Eiffel running processes. We certainly recommend that you catch all exceptions (Ctrl + Alt + E to get to the dialog).
 
With Visual C++, you can have access to the Visual Studio C debugger which will let you attach Eiffel running processes. We certainly recommend that you catch all exceptions (Ctrl + Alt + E to get to the dialog).
Line 36: Line 52:
 
If you have issues with Visual Studio not finding some debugging information, it might be necessary to tell Visual Studio where to find the associated PDB of your Eiffel executable or DLL.
 
If you have issues with Visual Studio not finding some debugging information, it might be necessary to tell Visual Studio where to find the associated PDB of your Eiffel executable or DLL.
  
== Mac OS X ==
+
=== Mac OS X ===
 
Follow the same instructions as above for Unix, except that before recompiling the C code you need to modify the Makefile.SH manually for all Cx directories and remove the line <pre>$(RM) $(OBJECTS)</pre>
 
Follow the same instructions as above for Unix, except that before recompiling the C code you need to modify the Makefile.SH manually for all Cx directories and remove the line <pre>$(RM) $(OBJECTS)</pre>
 
The following shell script will do the magic for you:
 
The following shell script will do the magic for you:
Line 45: Line 61:
  
 
You can use Eclipse to debug your application, Xcode can be set up as well ([https://developer.mozilla.org/en/Debugging_on_Mac_OS_X more]).
 
You can use Eclipse to debug your application, Xcode can be set up as well ([https://developer.mozilla.org/en/Debugging_on_Mac_OS_X more]).
 
== Runtime ==
 
===Unix===
 
Edit $EIFFEL_SRC/C/CONFIGS/$ISE_PLATFORM and perform the same substitution as above for Unix. Then type '''./quick_configure''' in the $EIFFEL_SRC/C directory.
 
 
Once this is done make sure to copy the debugged runtime files located under $EIFFEL_SRC/C/run-time/lib* to the EiffelStudio delivery under $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/lib.
 
 
===Windows===
 
Edit the config file in $EIFFEL_SRC/C/CONFIGS that matches your platform and your C compiler. For example, windows-x86-64-msc is for Windows 64-bit using the Microsoft C++ compiler. Comment out the debug and optimize entry and replace them with their corresponding debugged version (currently commented below). Then in the $EIFFEL_SRC/C directory type '''configure win64 m''' (Windows 64-bit) or '''configure win32 m''' (Windows 32-bit) to compile the runtime for the Microsoft C++ compiler.
 
 
Once this is done make sure to copy the debugged runtime files located under $EIFFEL_SRC/C/run-time/lib/*.lib to the EiffelStudio delivery under $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/lib/$ISE_C_COMPILER.
 

Latest revision as of 08:52, 17 June 2015

Sometimes you need debug the Eiffel generated C code. This page will show you how to achieve this. In addition you may also want to compile the runtime in debug mode (see the instructions at the end of this page).

To see the mapping between Eiffel classes and features to C files and their methods, the file TRANSLAT in the W_code or F_code directory is very useful.

Runtime

If you need to compile the runtime with debug information, follow the steps below. The steps below include a copy operation to the Eiffel installation directory, so make sure to make a backup before overriding the runtime files.

Unix

Edit $EIFFEL_SRC/C/CONFIGS/$ISE_PLATFORM and perform the same substitution as above for Unix. Then type ./quick_configure in the $EIFFEL_SRC/C directory.

Once this is done make sure to copy the debugged runtime files located under $EIFFEL_SRC/C/run-time/lib* to the EiffelStudio delivery under $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/lib.

Windows

Edit the config file in $EIFFEL_SRC/C/CONFIGS that matches your platform and your C compiler. For example, windows-x86-64-msc is for Windows 64-bit using the Microsoft C++ compiler. Comment out the debug and optimize entry and replace them with their corresponding debugged version (currently commented below). Then in the $EIFFEL_SRC/C directory type configure win64 m (Windows 64-bit) or configure win32 m (Windows 32-bit) to compile the runtime for the Microsoft C++ compiler.

Once this is done make sure to copy the debugged runtime files located under $EIFFEL_SRC/C/run-time/lib/*.lib to the EiffelStudio delivery under $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/lib/$ISE_C_COMPILER.

Application

Unix

There are 2 methods:

  • Edit $ISE_EIFFEL/studio/spec/$ISE_PLATFORM/include/config.sh and
    1. To the value of wkoptimize add the -g option.
    2. Replace the value of optimize to disable the C optimization (usually -O0) and add -g.
  • set the CFLAGS environment variable with -O0 -g

Once you have done that, do in your W_code or F_code directory:

make clobber
finish_freezing

Now, the generated executable should contain debugger symbols. It can be debugged with gdb or ddd (Data Display Debugger).

Windows

After doing the changes below (depending on your C compiler), you can recompile your project from scratch and the debug information will be present.

MinGW

Edit $ISE_EIFFEL\studio\config\$ISE_PLATFORM\$ISE_C_COMPILER\config.eif and perform the following edits:

  1. Replace the content of optimize by -O0 -g.
  2. Replace the content of wkoptimize by -O0 -g.

Visual C++

Edit $ISE_EIFFEL\studio\config\$ISE_PLATFORM\$ISE_C_COMPILER\config.eif and perform the following edits:

  1. Replace the content of optimize' by -Od -Zi -MT.
  2. Search and replace all occurrences of -NODEFAULTLIB:libc by -NODEFAULTLIB:libc -DEBUG.
  3. Disable ASLR (Address Space Layout Randomization) would certainly help in having a consistent debugging experience across execution. This can be done by adding -DYNAMICBASE:NO after -DEBUG.

With Visual C++, you can have access to the Visual Studio C debugger which will let you attach Eiffel running processes. We certainly recommend that you catch all exceptions (Ctrl + Alt + E to get to the dialog).

If you have issues with Visual Studio not finding some debugging information, it might be necessary to tell Visual Studio where to find the associated PDB of your Eiffel executable or DLL.

Mac OS X

Follow the same instructions as above for Unix, except that before recompiling the C code you need to modify the Makefile.SH manually for all Cx directories and remove the line
$(RM) $(OBJECTS)

The following shell script will do the magic for you:

sed -i -e 's/$(RM) $(OBJECTS)//g' `find -d . | grep "Makefile.SH"`

You can use Eclipse to debug your application, Xcode can be set up as well (more).