
pstruct Command in Linux
The pstruct command in Linux dumps the C structures generated from stabs. It is an early tool designed to analyze C structures by leveraging debugging information from the compiler's symbol table (stabs). It helps developers inspect structure layouts, member offsets, and sizes, making it useful for low-level debugging and binary analysis. However, pstruct is now deprecated due to changes in debugging formats and the availability of better alternatives.
Table of Contents
Here is a comprehensive guide to the options available with the pstruct command â
- Syntax of pstruct Command
- pstruct Command Options
- Examples pstruct Command in Linux
- Alternative to pstruct Command
Syntax of pstruct Command
The syntax of the pstruct command in Linux is as follows −
pstruct [options] [file]
The [options] field is used to specify various options to change the commandâs behavior. The [file] field is used to specify the C file to process.
Options of pstruct Command
The options of the pstruct command are listed below −
Option | Description |
---|---|
-w | Wide format output. |
-x | Display offsets and sizes in hexadecimal. |
-n | Do not generate Perl code (default for pstruct). |
-p | Generate Perl code (default for c2ph). |
-slist | Dump only specified structures. |
-v | Generate Perl code, with C decls as comments. |
Examples pstruct Command in Linux
This section explains how to use the Linux pstruct command with examples −
Extracting Structure Definitions from a C Header File
To extract the structure definitions from a C header file, use the pstruct command in the following way −
pstruct file.h
The above command processes the file.h file, extracting the structure definitions and their memory layouts. The output lists the structure fields, their offsets (byte positions in memory), and their sizes. A typical output looks like this −

000, 004, and 018 are the start offsets, while 4, 20, and 8 are sizes in bytes. This helps developers understand how structures are arranged in memory.
Extracting Structure Definitions from a C Header File in Hexadecimal
To extract the structure definitions from a C header file, use the -x option with the pstruct command −
pstruct -x file.h
Generating Perl Code
To generate Perl code while keeping the original C declarations as comments, use the -v option −
pstruct -v file.h
Note − The pstruct command is deprecated due to reliance on the obsolete stabs format; use pahole with DWARF-enabled binaries for modern structure analysis.
Alternative to pstruct Command
The pstruct command is deprecated due to reliance on the obsolete stabs format, lack of maintenance, and limited support for modern C features. There are different alternatives, one of them is the pahole tool. The pahole tool is a modern and efficient tool that extracts structure layout information.
To use pahole on Linux, it must be installed. To install it on Ubuntu, Kali Linux, Debian, and other Debian-based distributions, use the following command −
sudo apt install dwarves
To install it on Fedora, use −
sudo dnf install dwarves
To verify the installation, check the version of pahole −
pahole --version

Note that pahole works only on compiled binaries (ELF files) that contain DWARF debugging information. It cannot directly analyze .h header files like pstruct could.
To use the pahole command first get the binary of the C code by compiling it using the following command:
gcc -g -o output_binary file.c
The above command compiles the file.c file and generates its binary with the name of the output_binary in the current working directory:
Now, use the pahole command with the output binary file name:
pahole output_binary
The output of the pahole is quite similar to the output of the pstruct command, as shown in the image below:

The above output provides the following details:
- int age − Starts at offset 0, size 4 bytes.
- float height − Starts at offset 4, size 4 bytes.
- char name[50] − Starts at offset 8, size 50 bytes.
Conclusion
The pstruct command was a useful tool for analyzing C structures using stabs debugging information, but it is now deprecated due to changes in debugging formats and the availability of better alternatives. This tutorial covered its syntax, options, and usage, along with an alternative tool, pahole, which provides similar functionality for modern debugging formats like DWARF.
While pstruct worked directly on header files, pahole requires compiled binaries but remains a more effective and maintained tool for structure analysis in Linux.