gimli-rs / gimli

A library for reading and writing the DWARF debugging format
https://docs.rs/gimli/
Apache License 2.0
846 stars 108 forks source link

Can't parse this DWP file: InvalidIndexSlotCount #705

Closed mstange closed 6 months ago

mstange commented 6 months ago

The dwp file in this directory doesn't parse successfully:

% cargo run --bin dwarfdump -- --dwp ~/code/samply/fixtures/other/simple-example/out/with-dwp/main.dwp --dwo-parent ~/code/samply/fixtures/other/simple-example/out/with-dwp/main
Failed to dump '/home/ubuntu/code/samply/fixtures/other/simple-example/out/with-dwp/main.dwp': GimliError(InvalidIndexSlotCount)

It returns a GimliError(InvalidIndexSlotCount) from this code:

https://github.com/gimli-rs/gimli/blob/7294ff0abaeebbd4f5ed66a03941f7488058be46/src/read/index.rs#L166-L171

section_count, unit_count and slot_count are all zero for this dwp file.


I generated the dwp file with dwp version 2.34 on Ubuntu 20.04.4 LTS in an aarch64 VM, with gcc version 9.4.0.

Here's the script I used to generate it:

#!/bin/bash

mkdir -p out/with-dwp

# Compile source files into object files
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/main.cpp -o out/with-dwp/main.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file1.cpp -o out/with-dwp/file1.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file2.cpp -o out/with-dwp/file2.o
g++ -c -g -Os -Wall -Wextra -gsplit-dwarf src/file3.cpp -o out/with-dwp/file3.o

# Create libfile23.a from file2.o and file3.o
ar rcs out/with-dwp/libfile23.a out/with-dwp/file2.o out/with-dwp/file3.o

# Link libraries into executable
g++ out/with-dwp/main.o out/with-dwp/file1.o out/with-dwp/libfile23.a -o out/with-dwp/main

# Make dwp file
dwp -e out/with-dwp/main

# Remove .dwo, .o, .a files
rm out/with-dwp/*.dwo out/with-dwp/*.o out/with-dwp/*.a

The source code is here: https://github.com/mstange/samply/tree/f78bbae04b27e8c77e2a77ef8d8aed6c76abbc7a/fixtures/other/simple-example/src