Skip to content

Commit dd12007

Browse files
committed
Fix finding of source files with dwarfdump program
* bdx/binary.py (_find_source_file_dwarfdump): Return the path even if it doesn't exist. * tests/fixture/Makefile (CFLAGS): Add an argument to have consistent source in all binaries regardless of compiling machine. * tests/test_index.py (test_indexing_adds_source_field_with_dwarfdump): Update accordingly. * .github/workflows/ci.yml (Set up build system): Install dwarfdump. * tests/fixture/subdir/bar.cpp.o: * tests/fixture/subdir/foo.c.o: * tests/fixture/toplev.c.o: Rebuild.
1 parent 76ff18e commit dd12007

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ jobs:
7171
# For generating compile_commands.json file for tests
7272
sudo apt-get install bear
7373
74+
# Tests require dwarfdump
75+
sudo apt-get install dwarfdump
76+
7477
# Install prerequisites for xapian-bindings.
7578
# https://github.com/sphinx-doc/sphinx/issues/6524
7679
pip install Sphinx

bdx/binary.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ def _find_source_file_dwarfdump(elf: ELFFile) -> Optional[Path]:
265265
dw_at_name, dw_at_comp_dir = match.groups()
266266

267267
path = Path(dw_at_comp_dir) / Path(dw_at_name)
268-
if path.exists():
268+
try:
269269
return path.resolve()
270-
return None
270+
except OSError:
271+
return path
271272

272273

273274
def _find_source_file(

tests/fixture/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
CFLAGS += "-fdebug-prefix-map=${PWD}=/src"
2+
13
FILES := \
24
subdir/bar.cpp \
35
subdir/foo.c \
@@ -11,12 +13,12 @@ OBJFILES := $(patsubst %,%.o,${FILES})
1113
%.cpp.o: %.cpp
1214
${CXX} ${CFLAGS} -g -c -o $@ $^
1315

14-
compile_commands.json: ${FILES}
15-
bear -- ${MAKE} clean default
16-
1716
default: ${OBJFILES}
1817

1918
clean:
2019
rm -f ${OBJFILES}
2120

21+
compile_commands.json: ${FILES}
22+
bear -- ${MAKE} clean default
23+
2224
.PHONY: default clean

tests/fixture/subdir/bar.cpp.o

0 Bytes
Binary file not shown.

tests/fixture/subdir/foo.c.o

-16 Bytes
Binary file not shown.

tests/fixture/toplev.c.o

-24 Bytes
Binary file not shown.

tests/test_index.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import shutil
2+
from pathlib import Path
23
from shutil import rmtree
34

45
import pytest
@@ -198,12 +199,18 @@ def test_indexing_adds_source_field_with_dwarfdump(fixture_path, tmp_path):
198199
symbols = list(index.search("path:toplev.c.o"))
199200
assert symbols
200201
for symbol in symbols:
201-
assert symbol.source == fixture_path / "toplev.c"
202+
assert (
203+
symbol.source
204+
== Path("/src") / "tests" / "fixture" / "toplev.c"
205+
)
202206

203207
symbols = list(index.search("path:foo.c.o"))
204208
assert symbols
205209
for symbol in symbols:
206-
assert symbol.source == fixture_path / "subdir" / "foo.c"
210+
assert (
211+
symbol.source
212+
== Path("/src") / "tests" / "fixture" / "subdir" / "foo.c"
213+
)
207214

208215

209216
def test_indexing_adds_source_field_with_compilation_database(

0 commit comments

Comments
 (0)