<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akihiro Oguri</title>
    <description>The latest articles on DEV Community by Akihiro Oguri (@inkuriment).</description>
    <link>https://dev.to/inkuriment</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4178142%2F791e1fb7-6f3e-4d80-80c4-2f43b12917bd.png</url>
      <title>DEV Community: Akihiro Oguri</title>
      <link>https://dev.to/inkuriment</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/inkuriment"/>
    <language>en</language>
    <item>
      <title>Reading a UBI Flash Dump: The EC Header and the VID Header</title>
      <dc:creator>Akihiro Oguri</dc:creator>
      <pubDate>Mon, 23 Nov 2026 10:13:54 +0000</pubDate>
      <link>https://dev.to/inkuriment/reading-a-ubi-flash-dump-the-ec-header-and-the-vid-header-5enk</link>
      <guid>https://dev.to/inkuriment/reading-a-ubi-flash-dump-the-ec-header-and-the-vid-header-5enk</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When you take a dump of NAND flash that has UBI on it, it is not obvious what is written where.&lt;/p&gt;

&lt;p&gt;What UBI writes to the flash is defined as structures in a kernel source header, &lt;code&gt;drivers/mtd/ubi/ubi-media.h&lt;/code&gt;. In this article, you read the two headers that UBI writes at the start of an erase block (PEB): the &lt;strong&gt;EC header&lt;/strong&gt;, which every PEB has, and the &lt;strong&gt;VID header&lt;/strong&gt;, which only PEBs assigned to an LEB have. You compare each one in a dump with its structure.&lt;/p&gt;

&lt;p&gt;The test environment is Linux 6.6 running on QEMU's &lt;code&gt;virt&lt;/code&gt; machine (ARM64), with nandsim, a kernel module that imitates a NAND flash chip. The NAND is 128 MiB, a PEB is 128 KiB (131072 bytes), and a page is 2048 bytes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Layout Inside a PEB
&lt;/h2&gt;

&lt;p&gt;In this environment, both headers are in the first page of a PEB. The numbers on the right are byte offsets from the start of the PEB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────────────────────┐ 0
│ EC header (64 bytes)         │  in every PEB
├──────────────────────────────┤ 64
│ (unused)                     │
├──────────────────────────────┤ 512
│ VID header (64 bytes)        │  only in PEBs assigned to an LEB
├──────────────────────────────┤ 576
│ (unused)                     │
├──────────────────────────────┤ 2048
│ data (129024 bytes)          │  the LEB's contents
└──────────────────────────────┘ 131072
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The position of the VID header (512) and the position of the data (2048) are the values for this NAND. By default, UBI puts the VID header at the next unit the NAND can write after the EC header. This NAND can write in 512-byte subpages, so the VID header is at 512. On a NAND that cannot, the VID header is at the start of the second page, and the data starts at the third page. On any device, the actual positions are written in &lt;code&gt;vid_hdr_offset&lt;/code&gt; and &lt;code&gt;data_offset&lt;/code&gt; of the EC header.&lt;/p&gt;

&lt;p&gt;The numeric fields of the headers are &lt;strong&gt;big-endian&lt;/strong&gt;. The structures use the types &lt;code&gt;__be32&lt;/code&gt; and &lt;code&gt;__be64&lt;/code&gt;. ARM64 runs little-endian here, but UBI writes its headers in big-endian whatever the CPU is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The EC Header: How Many Times the PEB Was Erased
&lt;/h2&gt;

&lt;p&gt;EC stands for Erase Counter. The main job of the EC header is to record, for each PEB, the number of times it was erased.&lt;/p&gt;

&lt;p&gt;Dump the first page of PEB 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nanddump -s 0 -l 2048 /dev/mtd1 &lt;span class="o"&gt;|&lt;/span&gt; hexdump -C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00000000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 01  |UBI#............|
00000010  00 00 02 00 00 00 08 00  01 51 da fa 00 00 00 00  |.........Q......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 f6 59 ca 6f  |.............Y.o|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000800
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The structure is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* drivers/mtd/ubi/ubi-media.h */&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nf"&gt;ubi_ec_hdr&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;magic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;padding1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be64&lt;/span&gt;  &lt;span class="n"&gt;ec&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Warning: the current limit is 31-bit anyway! */&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;vid_hdr_offset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;data_offset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;image_seq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;padding2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;hdr_crc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;__packed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compared with the dump, it reads as follows:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Offset&lt;/th&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;code&gt;magic&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;55 42 49 23&lt;/code&gt; (&lt;code&gt;UBI#&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Marks an EC header&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;code&gt;version&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The version of the UBI format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ec&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;00 … 01&lt;/code&gt; (1)&lt;/td&gt;
&lt;td&gt;The number of times this PEB was erased&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;&lt;code&gt;vid_hdr_offset&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;00 00 02 00&lt;/code&gt; (512)&lt;/td&gt;
&lt;td&gt;The position of the VID header&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;&lt;code&gt;data_offset&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;00 00 08 00&lt;/code&gt; (2048)&lt;/td&gt;
&lt;td&gt;The position of the data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;td&gt;&lt;code&gt;image_seq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;01 51 da fa&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A number chosen at each format. The same value is written to every PEB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hdr_crc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;f6 59 ca 6f&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The CRC of the 60 bytes up to here&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;From byte 512 on, it is still &lt;code&gt;0xFF&lt;/code&gt;. PEB 0 has no VID header. It is a free PEB, not yet assigned to any LEB.&lt;/p&gt;

&lt;p&gt;Neither the NAND chip nor MTD counts erases. UBI keeps the count by writing it in this EC header. So if you erase a NAND that has UBI on it with &lt;code&gt;flash_erase&lt;/code&gt;, the count is lost along with the EC header. &lt;code&gt;ubiformat&lt;/code&gt; reads the count before erasing, adds 1, and writes it back.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;image_seq&lt;/code&gt; is used at attach time. If a PEB has a value (other than 0) that differs from the value in the first PEB read, attach stops with the error &lt;code&gt;bad image sequence number&lt;/code&gt;. This is to detect PEBs from an old image left behind after a new image was written.&lt;/p&gt;

&lt;h2&gt;
  
  
  The VID Header: Which LEB of Which Volume
&lt;/h2&gt;

&lt;p&gt;VID stands for Volume Identifier. The main job of the VID header is to record which LEB (logical erase block) of which volume the PEB is assigned to.&lt;/p&gt;

&lt;p&gt;The VID header starts with &lt;code&gt;UBI!&lt;/code&gt; (&lt;code&gt;55 42 49 21&lt;/code&gt;). Here you read PEB 257, which has a VID header. PEB 257 starts at byte &lt;code&gt;257 × 131072 = 0x2020000&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nanddump -s 0x2020000 -l 2048 /dev/mtd1 &lt;span class="o"&gt;|&lt;/span&gt; hexdump -C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00000000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 00  |UBI#............|
00000010  00 00 02 00 00 00 08 00  01 51 da fa 00 00 00 00  |.........Q......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 55 cf e2 23  |............U..#|
00000040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000200  55 42 49 21 01 01 01 05  7f ff ef ff 00 00 00 00  |UBI!............|
00000210  00 00 00 00 00 00 58 00  00 00 00 00 00 00 00 00  |......X.........|
00000220  3d 26 c9 e1 00 00 00 00  00 00 00 00 00 00 00 01  |=&amp;amp;..............|
00000230  00 00 00 00 00 00 00 00  00 00 00 00 dd 89 12 1c  |................|
00000240  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000800
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The EC header is at byte 0, and the VID header is at byte 512 (&lt;code&gt;00000200&lt;/code&gt;). The structure is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* drivers/mtd/ubi/ubi-media.h */&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nf"&gt;ubi_vid_hdr&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;magic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;vol_type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;copy_flag&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;compat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;vol_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;lnum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;padding1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;data_size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;used_ebs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;data_pad&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;data_crc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;padding2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be64&lt;/span&gt;  &lt;span class="n"&gt;sqnum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__u8&lt;/span&gt;    &lt;span class="n"&gt;padding3&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;__be32&lt;/span&gt;  &lt;span class="n"&gt;hdr_crc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;__packed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main fields compared with the dump are as follows. The offsets are byte offsets from the start of the VID header. For example, the VID header starts at &lt;code&gt;0x200&lt;/code&gt; and &lt;code&gt;vol_id&lt;/code&gt; is 8 bytes into it, so &lt;code&gt;vol_id&lt;/code&gt; is the four bytes at &lt;code&gt;0x208&lt;/code&gt; of the dump.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Offset&lt;/th&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;code&gt;magic&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;55 42 49 21&lt;/code&gt; (&lt;code&gt;UBI!&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Marks a VID header&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;&lt;code&gt;copy_flag&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;UBI sets it when it replaces a whole LEB at once or copies an LEB to another PEB. Here, the volume table was rewritten when the volume was created. Used at attach time (below)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;&lt;code&gt;vol_id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;7f ff ef ff&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Which volume's LEB this is&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;&lt;code&gt;lnum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;00 00 00 00&lt;/code&gt; (0)&lt;/td&gt;
&lt;td&gt;Which LEB of that volume&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;&lt;code&gt;sqnum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;00 … 01&lt;/code&gt; (1)&lt;/td&gt;
&lt;td&gt;A number that increases each time a VID header is written&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hdr_crc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;dd 89 12 1c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The CRC of the 60 bytes up to here&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Volumes you create are numbered from 0 in &lt;code&gt;vol_id&lt;/code&gt;. &lt;code&gt;0x7FFFEFFF&lt;/code&gt; is the number of a dedicated volume that holds the list of volumes (the volume table). PEB 257 holds LEB 0 of this volume.&lt;/p&gt;

&lt;h2&gt;
  
  
  What UBI Does at Attach Time
&lt;/h2&gt;

&lt;p&gt;At attach time, UBI reads the EC header and the VID header of every PEB and builds a table of LEB-to-PEB mappings in memory.&lt;/p&gt;

&lt;p&gt;When UBI rewrites data, it does not overwrite the same PEB. It writes to another PEB and then erases the original one. If the power is cut before the erase, the same LEB remains in two PEBs. In that case, UBI uses the one with the larger (newer) &lt;code&gt;sqnum&lt;/code&gt;. However, if &lt;code&gt;copy_flag&lt;/code&gt; is set in the newer one, UBI also checks the CRC of its data against &lt;code&gt;data_crc&lt;/code&gt; in the VID header, and if they do not match, it uses the older one (&lt;code&gt;ubi_compare_lebs()&lt;/code&gt; in &lt;code&gt;drivers/mtd/ubi/attach.c&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting a Volume's Data Out of a Dump
&lt;/h2&gt;

&lt;p&gt;With what you have read so far, you can get a volume's data out of a dump.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Collect the PEBs of the volume you want by &lt;code&gt;vol_id&lt;/code&gt; in the VID header&lt;/li&gt;
&lt;li&gt;Put them in &lt;code&gt;lnum&lt;/code&gt; order&lt;/li&gt;
&lt;li&gt;If two PEBs have the same &lt;code&gt;lnum&lt;/code&gt;, choose one the same way UBI does at attach time (above)&lt;/li&gt;
&lt;li&gt;Join their data parts (from &lt;code&gt;data_offset&lt;/code&gt; in the EC header on)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An LEB that was never written has no PEB. In a dynamic volume, UBI reads such an LEB as &lt;code&gt;0xFF&lt;/code&gt; bytes, so put one LEB's worth of &lt;code&gt;0xFF&lt;/code&gt; (129024 bytes here) in its place. If you just join the PEBs you found, the LEBs after a gap shift forward.&lt;/p&gt;

&lt;p&gt;When you investigate the flash of a returned product, take a dump including the OOB (&lt;code&gt;nanddump -o&lt;/code&gt;) before you format or attach. Even attaching alone can make UBI write to the flash: it may rewrite a corrupted volume table or move data to another PEB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Header&lt;/th&gt;
&lt;th&gt;Location&lt;/th&gt;
&lt;th&gt;Marker&lt;/th&gt;
&lt;th&gt;Main fields&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;EC header&lt;/td&gt;
&lt;td&gt;Byte 0 of every PEB&lt;/td&gt;
&lt;td&gt;&lt;code&gt;UBI#&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ec&lt;/code&gt; (erase count), &lt;code&gt;vid_hdr_offset&lt;/code&gt; and &lt;code&gt;data_offset&lt;/code&gt;, &lt;code&gt;image_seq&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;VID header&lt;/td&gt;
&lt;td&gt;At &lt;code&gt;vid_hdr_offset&lt;/code&gt; of an assigned PEB&lt;/td&gt;
&lt;td&gt;&lt;code&gt;UBI!&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;vol_id&lt;/code&gt; and &lt;code&gt;lnum&lt;/code&gt; (which LEB of which volume), &lt;code&gt;sqnum&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Look for &lt;code&gt;UBI#&lt;/code&gt; and &lt;code&gt;UBI!&lt;/code&gt; in a dump, and you can see where each PEB starts and which PEB is used for what. From there, you can read the rest by comparing it with the structures in &lt;code&gt;ubi-media.h&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Want to Learn More?
&lt;/h2&gt;

&lt;p&gt;This article is based on Chapter 6 of my book, &lt;strong&gt;&lt;em&gt;Hands-On Embedded Linux UBI with QEMU: Stop Writing Off Flash Corruption as "Cause Unknown"&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the book, with no real hardware, using just one PC, you load nandsim into Linux running on QEMU and put UBI on top of it. You dump the contents of the flash and compare them with the structures in the kernel source. Then you deliberately cause failures that could happen at any time on real hardware, and check in the logs and the contents of the flash what UBI does.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read the volume table in a dump, one field at a time&lt;/li&gt;
&lt;li&gt;See why rewriting data moves it to another erase block&lt;/li&gt;
&lt;li&gt;Corrupt the volume table and the headers, and see how UBI deals with it&lt;/li&gt;
&lt;li&gt;Power cuts in the middle of a rewrite, an update, and a format&lt;/li&gt;
&lt;li&gt;Bit flips, erase and write failures, and bad blocks increasing until no erase block is left to replace them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.amazon.com/dp/B0HSNLRQWN" rel="noopener noreferrer"&gt;Hands-On Embedded Linux UBI with QEMU on Amazon&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hardware</category>
      <category>linux</category>
      <category>systems</category>
    </item>
    <item>
      <title>Why gdb Shows ?? Instead of Function Names: 4 Causes and Fixes</title>
      <dc:creator>Akihiro Oguri</dc:creator>
      <pubDate>Mon, 12 Oct 2026 13:51:31 +0000</pubDate>
      <link>https://dev.to/inkuriment/why-gdb-shows-instead-of-function-names-4-causes-and-fixes-47ci</link>
      <guid>https://dev.to/inkuriment/why-gdb-shows-instead-of-function-names-4-causes-and-fixes-47ci</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Sometimes you look at a backtrace in gdb and find &lt;code&gt;??&lt;/code&gt; where the function names should be.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#0  0x0000aaaaaaaa0894 in ?? ()
#1  0x0000aaaaaaaa0994 in ?? ()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;??&lt;/code&gt; means that gdb &lt;strong&gt;could not find a function name for that address&lt;/strong&gt;. This article covers four reasons you get &lt;code&gt;??&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The application has been &lt;code&gt;strip&lt;/code&gt;ped&lt;/li&gt;
&lt;li&gt;The function is inside a library and is not public&lt;/li&gt;
&lt;li&gt;The location of the libraries was not given with &lt;code&gt;set sysroot&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When a core dump is opened on the host, gdb cannot match it with the application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The test environment is ARM64 Linux (BusyBox) running on QEMU, with an Ubuntu 24.04 host.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reason 1: The Application Has Been &lt;code&gt;strip&lt;/code&gt;ped
&lt;/h2&gt;

&lt;p&gt;Applications shipped in products are sometimes run through &lt;code&gt;strip&lt;/code&gt; to make the file smaller. &lt;code&gt;strip&lt;/code&gt; removes the following two things:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What is removed&lt;/th&gt;
&lt;th&gt;Contents&lt;/th&gt;
&lt;th&gt;What gdb uses it for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Symbols&lt;/td&gt;
&lt;td&gt;The mapping between function and variable names and addresses&lt;/td&gt;
&lt;td&gt;Turning addresses into function names&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Debug information&lt;/td&gt;
&lt;td&gt;Line numbers, the types and locations of variables, and so on (added with &lt;code&gt;-g&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Showing line numbers and the values of variables&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The symbols that function names come from are gone, so every function in the application becomes &lt;code&gt;??&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(No debugging symbols found in ./sensor-stripped)
...
Program received signal SIGSEGV, Segmentation fault.
0x0000aaaaaaaa0894 in ?? ()
(gdb) bt
#0  0x0000aaaaaaaa0894 in ?? ()
#1  0x0000aaaaaaaa0994 in ?? ()
#2  0x0000fffff7e184c4 in ?? () from /lib/libc.so.6
#3  0x0000fffff7e18598 in __libc_start_main () from /lib/libc.so.6
#4  0x0000aaaaaaaa0770 in ?? ()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;file&lt;/code&gt; command tells you whether a file has been stripped. If it says &lt;code&gt;stripped&lt;/code&gt; at the end, it has.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ file sensor-stripped
sensor-stripped: ELF 64-bit LSB pie executable, ARM aarch64, ... stripped
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Fix: Keep the Unstripped Application or a Debug Information File
&lt;/h3&gt;

&lt;p&gt;Even if the application on the target stays stripped, if you keep &lt;strong&gt;the unstripped application from the same build&lt;/strong&gt; on the host, gdb on the host can show function names and line numbers when you connect through gdbserver.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(gdb) bt
#0  print_average () at sensor.c:33
#1  0x0000aaaaaaaa0994 in main () at sensor.c:51
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of keeping the whole unstripped application, you can also put just the debug information in a separate file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;objcopy &lt;span class="nt"&gt;--only-keep-debug&lt;/span&gt; sensor sensor.debug
objcopy &lt;span class="nt"&gt;--add-gnu-debuglink&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sensor.debug sensor-stripped
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The first line extracts only the debug information and symbols into &lt;code&gt;sensor.debug&lt;/code&gt;. The second line writes a marker into the stripped application saying "the debug information is in &lt;code&gt;sensor.debug&lt;/code&gt;." gdb follows this marker and loads &lt;code&gt;sensor.debug&lt;/code&gt; (see "Debugging Information in Separate Files" in the gdb manual: &lt;a href="https://sourceware.org/gdb/current/onlinedocs/gdb.html/Separate-Debug-Files.html" rel="noopener noreferrer"&gt;https://sourceware.org/gdb/current/onlinedocs/gdb.html/Separate-Debug-Files.html&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With either method, what you keep must come from the same build.&lt;/strong&gt; With something rebuilt later, the instructions and addresses may shift, and they cannot be matched correctly.&lt;/p&gt;
&lt;h3&gt;
  
  
  Note: Just Leaving Out &lt;code&gt;-g&lt;/code&gt; Does Not Give You &lt;code&gt;??&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you build without &lt;code&gt;-g&lt;/code&gt;, the symbols remain, so function names still appear. What you lose are line numbers and variables. You get &lt;code&gt;??&lt;/code&gt; only when &lt;code&gt;strip&lt;/code&gt; removes the symbols as well.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reason 2: The Function Is Inside a Library and Is Not Public
&lt;/h2&gt;

&lt;p&gt;Sometimes the application itself is not stripped, but only the frames inside a library are &lt;code&gt;??&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(gdb) bt
#0  0x0000fffff7e92b1c in ?? () from /lib/libc.so.6
#1  0x0000aaaaaaaa0874 in reset_average () at sensor.c:27
#2  0x0000aaaaaaaa093c in main () at sensor.c:46
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Line 27 in &lt;code&gt;#1&lt;/code&gt; is the line that calls &lt;code&gt;memset()&lt;/code&gt;, so &lt;code&gt;#0&lt;/code&gt; is inside &lt;code&gt;memset()&lt;/code&gt;. Even so, its name is &lt;code&gt;??&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The C library may keep only the names of the functions it exports. &lt;code&gt;memset()&lt;/code&gt; actually works by running an implementation function chosen to suit the CPU, and that implementation function is not exported. So its name is shown as &lt;code&gt;??&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fix: Look at the Calling Line
&lt;/h3&gt;

&lt;p&gt;Even if you do not know the name of the function inside the library, &lt;code&gt;bt&lt;/code&gt; tells you which line of your own code called it. In the example above, &lt;code&gt;sensor.c:27&lt;/code&gt; in &lt;code&gt;#1&lt;/code&gt; leads you to the &lt;code&gt;memset()&lt;/code&gt; that caused the problem.&lt;/p&gt;

&lt;p&gt;If you do not need to follow it into the library, the shortcut is to skip the &lt;code&gt;??&lt;/code&gt; frames and look at &lt;strong&gt;the topmost frame in your own code&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reason 3: The Location of the Libraries Was Not Given with &lt;code&gt;set sysroot&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;An application runs using shared libraries such as the C library. gdb on the host reads the function names inside a library from the library's file.&lt;/p&gt;

&lt;p&gt;When you open a core dump with gdb on the host alone, you need to tell gdb with &lt;code&gt;set sysroot&lt;/code&gt; where on the host the target's library files are. If you do not, gdb cannot read the library files, and the frames inside the libraries become &lt;code&gt;??&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When you are connected through gdbserver, gdb receives the library files from the target through gdbserver and reads them, even without &lt;code&gt;set sysroot&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fix: Prepare a Directory Laid Out Like the Target and Specify It
&lt;/h3&gt;

&lt;p&gt;gdb treats the directory specified with &lt;code&gt;set sysroot&lt;/code&gt; as &lt;code&gt;/&lt;/code&gt; on the target. For example, if you specify &lt;code&gt;~/sysroot&lt;/code&gt;, gdb looks for &lt;code&gt;/lib/libc.so.6&lt;/code&gt; on the target at &lt;code&gt;~/sysroot/lib/libc.so.6&lt;/code&gt; on the host.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;(gdb) set sysroot ~/sysroot
(gdb) file ./sensor
(gdb) core-file core
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So inside the directory you specify, you need to place the libraries &lt;strong&gt;at the same paths as on the target&lt;/strong&gt;. The gdb manual (Commands to Specify Files: &lt;a href="https://sourceware.org/gdb/current/onlinedocs/gdb.html/Files.html" rel="noopener noreferrer"&gt;https://sourceware.org/gdb/current/onlinedocs/gdb.html/Files.html&lt;/a&gt;) says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you use set sysroot to find executables and shared libraries, they need to be laid out in the same way that they are on the target, with e.g. a /bin, /lib and /usr/lib hierarchy under path.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use the same library files as the ones running on the target. Specify &lt;code&gt;set sysroot&lt;/code&gt; before loading the core dump.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reason 4: When a Core Dump Is Opened on the Host, gdb Cannot Match It with the Application
&lt;/h2&gt;

&lt;p&gt;Even after specifying &lt;code&gt;set sysroot&lt;/code&gt; as in the fix for Reason 3, you may still get &lt;code&gt;??&lt;/code&gt;. Here is an example where only the libraries were placed there, not the application. Even though the application is given with &lt;code&gt;file&lt;/code&gt;, neither function names nor line numbers appear.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;(gdb) set sysroot ~/appdbg-study/initramfs
(gdb) file ./sensor
Reading symbols from ./sensor...
(gdb) core-file core
warning: Can't open file /mnt/ch05/sensor during file-backed mapping note processing
&lt;/span&gt;&lt;span class="c"&gt;...
&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;0  0x0000aaaae5490894 &lt;span class="k"&gt;in&lt;/span&gt; ?? &lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="go"&gt;(gdb) bt
&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;0  0x0000aaaae5490894 &lt;span class="k"&gt;in&lt;/span&gt; ?? &lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="gp"&gt;#&lt;/span&gt;1  0x0000ffff81c884c4 &lt;span class="k"&gt;in&lt;/span&gt; ?? &lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="gp"&gt;#&lt;/span&gt;2  0x0000aaaae5490770 &lt;span class="k"&gt;in&lt;/span&gt; ?? &lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Cause
&lt;/h3&gt;

&lt;p&gt;Before gdb on the host applies function names, it checks that the application in the core dump and the application given with &lt;code&gt;file&lt;/code&gt; are the same. What it uses for this check is the start of the application (the ELF headers), and gdb looks for it in this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inside the core dump&lt;/li&gt;
&lt;li&gt;In the application at the same path as on the target, inside the directory specified with &lt;code&gt;set sysroot&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If it is in neither place, function names become &lt;code&gt;??&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this environment, it was in neither place.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The ELF headers were not in the core dump&lt;/strong&gt;: whether they are included is decided by the &lt;code&gt;0x10&lt;/code&gt; bit of &lt;code&gt;/proc/&amp;lt;pid&amp;gt;/coredump_filter&lt;/code&gt; (bit 4 in &lt;code&gt;man 5 core&lt;/code&gt;, "Dump ELF headers."). On the target, the value was &lt;code&gt;00000023&lt;/code&gt;, and this bit was not set&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The application was not placed in the sysroot&lt;/strong&gt;: the libraries were there, but the application (&lt;code&gt;/mnt/ch05/sensor&lt;/code&gt;) was not&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This default is decided by the kernel configuration &lt;code&gt;CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS&lt;/code&gt;. In the kernel's Kconfig (&lt;code&gt;fs/Kconfig.binfmt&lt;/code&gt;), it defaults to enabled, but the ARM64 defconfig disables it. In kernels distributed by board makers, it was also disabled in NXP's &lt;code&gt;imx_v8_defconfig&lt;/code&gt; and in Jetson Linux's &lt;code&gt;defconfig&lt;/code&gt; / &lt;code&gt;tegra_defconfig&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fix: Make One of the Two Available
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;th&gt;What to do&lt;/th&gt;
&lt;th&gt;When to do it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Place the application in the sysroot&lt;/td&gt;
&lt;td&gt;Inside the directory specified with &lt;code&gt;set sysroot&lt;/code&gt;, place the application at the same path as on the target too&lt;/td&gt;
&lt;td&gt;After the crash, on the host&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Put the ELF headers in the core dump&lt;/td&gt;
&lt;td&gt;Set &lt;code&gt;coredump_filter&lt;/code&gt; to &lt;code&gt;0x33&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Before the crash, on the target&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you set &lt;code&gt;coredump_filter&lt;/code&gt; in the shell, it applies to the applications run from that shell.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;0x33 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /proc/self/coredump_filter
./sensor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With a core dump taken this way, function names and line numbers appeared even without placing the application in the sysroot.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;#&lt;/span&gt;0  print_average &lt;span class="o"&gt;()&lt;/span&gt; at sensor.c:33
&lt;span class="gp"&gt;33      printf("%s average: %d\n", avg.sensor-&amp;gt;&lt;/span&gt;name, avg.sum / avg.num&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="go"&gt;(gdb) bt
&lt;/span&gt;&lt;span class="gp"&gt;#&lt;/span&gt;0  print_average &lt;span class="o"&gt;()&lt;/span&gt; at sensor.c:33
&lt;span class="gp"&gt;#&lt;/span&gt;1  0x0000aaaac4cd0994 &lt;span class="k"&gt;in &lt;/span&gt;main &lt;span class="o"&gt;()&lt;/span&gt; at sensor.c:51
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can change the default by adding &lt;code&gt;coredump_filter=0x33&lt;/code&gt; to the kernel boot options, or by enabling &lt;code&gt;CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS&lt;/code&gt; and rebuilding the kernel.&lt;/p&gt;

&lt;p&gt;Note that what goes into the core dump is only the ELF headers, not the whole files. With either fix, the shared libraries must be placed inside the sysroot at the same paths as on the target.&lt;/p&gt;
&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;th&gt;Where &lt;code&gt;??&lt;/code&gt; appears&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The application has been &lt;code&gt;strip&lt;/code&gt;ped&lt;/td&gt;
&lt;td&gt;Every function in the application&lt;/td&gt;
&lt;td&gt;Keep the unstripped application from the same build, or a debug information file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A library function that is not public&lt;/td&gt;
&lt;td&gt;Frames inside the library&lt;/td&gt;
&lt;td&gt;Look at the calling line in your own code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The location of the libraries was not given with &lt;code&gt;set sysroot&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Frames inside the libraries&lt;/td&gt;
&lt;td&gt;Prepare a directory laid out like the target and specify it with &lt;code&gt;set sysroot&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;gdb cannot match the core dump opened on the host with the application&lt;/td&gt;
&lt;td&gt;Every function in the application&lt;/td&gt;
&lt;td&gt;Place the application in the sysroot, or set &lt;code&gt;coredump_filter&lt;/code&gt; to &lt;code&gt;0x33&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When you see &lt;code&gt;??&lt;/code&gt;, first check which frames are &lt;code&gt;??&lt;/code&gt;; that gives you an idea of which reason applies. If everything, even inside the application, is &lt;code&gt;??&lt;/code&gt;, it is Reason 1 or 4. If only the frames inside libraries are, it is Reason 2 or 3.&lt;/p&gt;


&lt;h2&gt;
  
  
  Want to Learn More?
&lt;/h2&gt;

&lt;p&gt;This article is based on my book, &lt;strong&gt;&lt;em&gt;Hands-On Linux Application Debugging with QEMU&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the book, with no real hardware, using just one PC, you debug applications for embedded Linux both on the target and from the host. You run applications with bugs put in on purpose and use tools to find the line that causes each one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop an application in gdb, look at its variables, and get a backtrace. Find the line that overwrote a value with a watchpoint&lt;/li&gt;
&lt;li&gt;Connect from the host with gdbserver and VS Code to debug&lt;/li&gt;
&lt;li&gt;Open the core dump of a crashed application, both on the target and on the host&lt;/li&gt;
&lt;li&gt;In a multithreaded application that has stopped, see which thread is waiting for what&lt;/li&gt;
&lt;li&gt;Find memory errors that do not cause a crash with ASan and UBSan&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://www.amazon.com/dp/B0HMRN2WVR/" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;amazon.com&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>linux</category>
      <category>gdb</category>
      <category>debugging</category>
      <category>embedded</category>
    </item>
  </channel>
</rss>
