Scripting: useful developers commands

Scripting: useful developers commands

  • mdo  DigitalBox
  •   Scripting
  •   June 14, 2025

This week is the last article about the useful commands series.

What about using commands which are useful when doing development under Haiku ? 

Command Description
file Identifies the type of a file
objdump Displays detailed information about object files
readelf Shows ELF file headers and sections
nm Lists symbols from object or binary files
c++filt Demangles C++ symbol names
size Displays the size of sections in a binary
strings Extracts readable text from binary files
listimage Lists loaded images for a given process
strace Traces system calls made by a program

Before moving further, you will need to setup a development environment as indicated in Setting a C++ dev environment.

In this setup, there's a simple program named "SimpleOpenGLCube", which we will use.

Compile that program as below:

g++ SimpleOpenGLCube.cpp -g -O2 -o SimpleOpenGLCube_Debug -lGL -lGLU -lbe
g++ SimpleOpenGLCube.cpp -o SimpleOpenGLCube_Release -lGL -lGLU -lbe

file

The first command - file - will allow to identify the type of file and especially if debug information is available:

file SimpleOpenGLCube_Debug
file SimpleOpenGLCube_Release

In the case of the binary with debug information, you will notice the result "with debug_info" of the first program (Debug), while the second one (Release) is not including any debug information. 

c++filt

When you compile a c++ program, the names of the functions and variables are mangled in order to include information like class name, type of parameters, etc.

The aim of the c++filt command is to demangles these C++ symbol names:

echo _ZSt4cout | c++filt 

objdump

The objdump command gives detailed information about object files.

Let's review - for instance - the symbols table of the binary:

objdump -t SimpleOpenGLCube_Debug | less

You will have the below results:

You can also demangle the results:

objdump -t SimpleOpenGLCube_Debug | c++filt | less

And the results will be more clear as below:

This command can also show disassembled machine code if needed with the "-d" option.

readelf

When you need to display ELF file headers and sections, the readelf command is the one to use.

readelf -a ./SimpleOpenGLCube_Debug | less

And the results will be as below:

nm

This command is needed when you want to list the symbols from a binary file.

For instance, let's check the symbols of the libxml2 library:

nm /system/lib/libxml2.so.2 | less

The output result is:

The lines with the "T" letter indicate a function name which can be access globally (like a main() function).

size

The size command indicate the size of the sections in a binary.

size ./SimpleOpenGLCube_Debug
size ./SimpleOpenGLCube_Release

These values can be useful to identify the memory footprint of your program.

strings

This command extracts readable text from binary files.

Let check that:

strings ./SimpleOpenGLCube_Debug | less

You should see all kind of text as below:

listimage

Do you need to identify the lists of loaded images for a given program ?

For that you need to use listimage followed by the process of your program.

First let's launch the program:

./SimpleOpenGLCube_Debug

Open another Terminal window and type:

pidof SimpleOpenGLCube_Debug
listimage 2408

As you can see, with the pid of the program, listimage indicates the images loaded like the libraries.

strace

The last command let you traces system calls made by a program.

In the Terminal type:

strace ./SimpleOpenGLCube_Debug

As you can see many system calls are displayed in the Terminal.

When the program will quit, you will have the below last results:

Do you use other commands when you need to write some scripts for your developments?

If you you can share your comment below.


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider