Assembly Programming and Debugging in Eclipse on Linux

The original article my article is based on is: While being good information to achieve the ultimate goal it is outdated in the year 2020 since Eclipse has changed so much since the article was published.

This article will use the 12-2019 Eclipse for C++ developers and the Linux GCC Toolchain to assemble and debug code within Eclipse.

Basically Eclipse 12-2019 is installed. A C++ project is created. A main.S file is added. The compiler and linker options are adjusted. A debug configuration is created and the sample application is compiled and debugged.

Installing and running Eclipse on Linux

The file eclipse-cpp-2019-12-R-linux-gtk-x86_64.tar.gz is downloaded and extracted.

tar -zxvf eclipse-cpp-2019-12-R-linux-gtk-x86_64.tar.gz

A eclipse folder is created. Eclipse can be run with:

Create a Project

File > New > C++ Project > C++ Managed Build > Executable > Empty Project > Linux GCC > Name: test

Add an Assembly File

File > New > Source File > main.S

The casing of the filename is in fact relevant! There has to be an uppercase S as an extension. The S extension is used by Eclipse to select the correct tools from the toolchain to assemble and link your application! If you use .s it will not work!

Add assembler code to the main.S file.

.section .data
message: .string "Hello World!\n"

.section .text

# this directive allows the linker to see the "main" label
# which is our entry point
.globl main

# this directive allows the eclipse gdb to see a function called "main"
.func main
mov $4, %eax
mov $1, %ebx
mov $message, %ecx
mov $14, %edx
int $0x80
mov $0, %eax
Adjust the Tool Settings

Project > Properties > C/C++ Build > Settings > Tab: Tool Settings > GCC Assembler > Command line pattern append: -g –gstabs immediately following ${COMMAND}


The way Linux, Unix and BSD systems assemble code has changed according to the posts:

Instead of using absolute addresses, the 64 bit way of modern assembly is now relocatable assembly. The code listing above is not moden 64 bit relocatable assembly.

The way to get the Linux GCC toolchain to assemble the code anyways is to add the -no-pie flag to the linker:

Project > Properties > C++ Build > Settings > GCC C++ Linker > Command Line Patter > add -no-pie after ${FLAGS}

Create a Debug Configuration

For eclipse to start an application from within the IDE, you have to supply a Run Configuration for normal execution or a Debug Configuration for debugging the application. Run / Debug Configurations are descriptors of an application run. They contain things such as environment variables and command line parameters to the application amongst other options and parameters.

First make sure your application does in fact build properly. In the next step you have to select your binary, that is why you have to be able to build your project.

In our case, in Eclipse, create a new Debug Configuration. As a type select ‘C/C++ Application’. Click Browser and select your binary for the C/C++ Application input field.

Set a breakpoint into the assembler source code and start the Debug configuration.