Entries Category “programming”

Fri 28 June 2019

Enabling lldb on Mojave

I have an impression that each version of macOS system introduces additional obstacles for developer. From one point of view I understand that they just want to make the system more secure, and that should be the biggest priority above all (well, maybe not above common sense). But it's hard … read more
Sat 02 March 2019

Is it worth using make?

You may think you've created a nice and tidy Makefile, which tracks dependencies and works across many different operating systems, but ask yourself these questions (and answer honestly): Which compiler does your Makefile support? Is it GCC? Or Clang? Some of their options are pretty similar, so it may not … read more
Thu 07 February 2019

C++: Shooting yourself in the foot #4

C++11 has introduced a better way to generate random numbers than the immortal srand(time(NULL)) and rand() % N method. However, this family of functions sometimes may behave in a not very intuitive way, especially when it comes to multi-platform programming. TL;DR: before commenting, please at least read … read more
Thu 22 November 2018

Bringing Visual Studio compiler into MSYS2 environment

Hi, Using Windows is a painful experience for a command-line oriented person like me. Unfortunately, Windows doesn't offer any decent command-line oriented environment, because well, it has different goals, and that's understandable. The problem is when one is forced to use Windows when it's clear that those goals are incompatible … read more
Wed 21 November 2018

Generating preprocessed sources in CMake projects

Hi, It appears you can use CMake to quickly generate preprocessed source of your chosen .cpp file without modifying the CMakeLists.txt project file. This trick works only when your generator is make -- meaning, it won't work with the ninja builder. But still, if you're using make as your generator … read more
Thu 01 March 2018

C++: Shooting yourself in the foot #3

Hi, Everyone says that programming is complicated. Is it? Well, actually it is, especially if you're using your programming language in a non-recommended way. Take file input/output for example. In C++ there are some ways you can perform file I/O: std::ifstream is one example. Multiple frameworks like … read more
Sun 11 February 2018

C++: Shooting yourself in the foot #2

Hi, There are people in this world who are forced to use C++ against their will. Those people often defend themselves by writing C code, and by compiling it with a C++ compiler. Then hope that noone will notice. There are a lot of problems with this, and this short … read more
Sun 11 February 2018

You're using TABs in a wrong way

Hi, Tabs or spaces? I'm sure you have a strong opinion on this subject, as probably everyone. Can we summarize the arguments for each side? Advantages of TABs: Using TABs means the source code uses less space. Each 4 bytes (2 bytes if you're a Ruby programmer, or sometimes 8 … read more
Sat 20 January 2018

C++: Shooting yourself in the foot #1

Hi, Recently I was browsing some code, and I saw some construct that maybe is not very obvious to everyone. The code was located inside an important function, which took a hash in the argument and performed some action based on the contents of this hash. Pseudocode: typedef process_t { // ... uint8_t … read more
Wed 21 September 2016

Listing macOS loaded kext paths

The default kextstat command will display only the names of loaded kernel extensions. However, there are situations when you want to know where is the kernel extension file that contains the kext code. In other words, where in the filesystem is the kext bundle located? Turns out kextstat doesn't implement … read more
Fri 22 January 2016

"Lost connection" when debugging with lldb on Mavericks

Lost connection on simple debugging session Sometimes you just have to use older system to develop some things. Not because you want to, but simply because you have to. When trying to use lldb on Mavericks I had a following problem: box:default$ ./binary [log] starting binary... [log] it works … read more
Mon 12 January 2015

Type-parametrized unit testing in GTest

Google's testing framework, GTest, goes beyond writing basic unit tests. It has some more advanced functionality that allows the user to cover more code with less tests, which -- considering the fact that unit tests always make a significant share of the source code ratio in a project -- is always a … read more
Thu 16 October 2014

Enabling globbing in a console Win32 application

"Globbing" can be also described as an act of expanding the filename wildcards supplied in the command-line of a console application. Let's suppose we have a small command-line application that performs some operation on files supplied as arguments in the command-line. #include #include int main(int argc, char … read more
Fri 12 September 2014

Sending ATA commands on Linux

It appears that any user can send an ATA message on Linux. The function that allows this is called ioctl, by using message identifier 0x31F (HDIO_DRIVE_CMD). It is possible to send, i.e. ATA IDENTIFY message by using 0xEC message. This command should return a device identification information. Other status … read more
Fri 25 July 2014

PKCS #7 certificate formatting issue in OpenSSL

Some time ago I was having a problem with an old software, that used digital signatures to validate its data files. The problem with the software was that it didn't fit in the new environment that was being built, and a replacement for the creation of these digital signatures was … read more
Sat 12 July 2014

Emitting an event through an existing ETW provider

Let's assume a simple scenario. I have an application that uses native plugins. I have my own binary format for these plugins. Each plugin is loaded at runtime, using a method similar to mapping a DLL into the process' space. This means, each plugin has its own ImageBase, sections like … read more
Wed 02 July 2014

Control over symbol exports in MinGW linker

Below is an example on how to include, or exclude a symbol from the list of exported symbols in a DLL file. To test it out, we need to compile our object files first: C:\> g++ -O0 -gdwarf-4 dll\dllmain.cpp -c -o dllmain.o Linking is done by the … read more
Thu 11 July 2013

Friendly GDB

The gdb debugger is a very old application, used widely in the past, when a computer was not yet a part of every house's inventory. Contrary to what many people say, it's very usable even today, mainly because of its extensibility, which lets the user to adapt it to his … read more
Fri 02 November 2012

Compiling glibmm on Windows

Here is a short list of steps which need to be taken to successfully install the glibmm library, using gcc 4.7.1, in Windows environment. Use-case scenario for this install would be to use a virtual machine, not a physical one. In the case anyone would choose to use … read more
Sat 16 June 2012

The Linux binfmt subsystem

The binfmt subsystem is a special mechanism which allows the kernel to extend its ability to recognize different executable binary formats. It's invoked by the kernel when the user wants to execute a file with the executable (+x) flag, and its purpose is to help the kernel to understand the … read more