Tag C

Clang sanitizers

Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end. In this post I talk about some of the sanitizers available in Clang (some are avilable in GCC as well). They help you detect problems at run time (dynamic analysis). As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the tools from the repository (clang). For other distributions you can find the information in the documentation. As always,... (read more)

ARM C Compiler (ACC) - Basic Compiler II

I am working on a pet project to create a C compiler for the ARM architecture. You can find more information about this topic in my previous post ARM C Compiler (ACC) - Basic Compiler I. The source code of this project can be found in GitHub. What is the current state of the project? Currently, I have implemented a very basic compiler, this version is available in GitHub as v0.2. Basic compiler able to handle a single file with a main function (without parameters) and if/else statements with simple... (read more)

Linux Kernel Module example. Rickroll prank.

NOTE: The code used to replace the user's path with the one provided is BAD, never change user's pointer content unless he/she is expecting that to happen. Don't do that at home kids I decided to explain the basics of a Linux Kernel Module with humor. I am not saying this is a good idea for April's fool, but it is quite close ;) This module shares some ideas with the post about LD_PRELOAD, but this time it is not to defend ourselves. The module will replace the open syscall for our own where it... (read more)

FFF a mocking frameowork for C

This post is a continuation from a previous post called Unity; unit test for C, but in this post we are going to use FFF. FFF is one of the available mocking frameworks for C. In this example I will use CMake to configure the project and build it. All the code and configuration files used in this post are available in this repo in GitHub. Why do we need to mock functions? To answer that question I will introduce the signature of the two methods I will use during this post. The first function is... (read more)

ARM C Compiler (ACC) - Basic Compiler I

Why do you want to create your own compiler? To answer this question I have to give you some background. For Christmas I got a BeagleBone Black, perfect to learn ARM assembly. After a few weeks of doing the usual stuff I decided I wanted a bigger project to improve my knowledge. However, the idea to start the development of a compiler comes from http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler-in-40-days.html. The only aim of this project is to improve my knowledge of the ARM assembly,... (read more)

Unity: unit test for C

Unity is one of the available frameworks to create unit tests for C. In this example, I will use CMake to configure the project and build. All the code and configuration files used in this post are available in this repo in GitHub. Can you do unit test in C? And what is Unity? Some people do not know you can do unit tests in C and people must do unit tests in any language. My choice to do unit tests in C is Unity for several reasons: No need to install any package in your distro. Just add the three... (read more)

Clang tools: clang-format, clang-tidy and clang-modernize

Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end. There are also several awesome tools build on top of Clang and I am going to show the three of them I use the most. As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the tools from the repository (clang, clang-tools-extra). For other distributions you can find the information in the documentation. As always, all the code used in this... (read more)

rr debugger, record once, replay tens of times

rr is a debugging tool from Mozilla that enhances the behaviour of GDB. It can be found in GitHub, but my recomendation is to go first to the website of the project. In the website you can find really useful information and documentation. As usual, I am working from an Arch Linux computer. Therefore, I can install rr from the AUR repository (rr). For other distributions you can find the information in the documentation. As always, all the code used in this post is available in this repo. The videos... (read more)