Skip to content

Commit

Permalink
Reproduce crash when including system headers
Browse files Browse the repository at this point in the history
The following
    $ ./includegraph.py examples/example1/build/ -l DEBUG
    2022-04-15 11:42:46,871 - ./includegraph.py - DEBUG - Successfully loaded compilation database from build directory 'examples/example1/build/'
    2022-04-15 11:42:46,872 - ./includegraph.py - DEBUG - Getting headers for /home/nots/Documents/includegraph/examples/example1/src/example1.cpp
    /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/istream
        /../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/istream.tcc

Crashes in clang.cindex.File.name, which calls clang_getFileName() from
the cdll loaded libclang.so

    #0  0x00007f21db0106ba in clang_getFileName () from /home/nots/Documents/includegraph/.venv/lib/python3.8/site-packages/clang/native/libclang.so
    #1  0x00007f21de1ecff5 in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
    #2  0x00007f21de1ec40a in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
    #3  0x00007f21dd752306 in _ctypes_callproc () from /usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so

It _doesn't_ crash if you comment out the File.name accesses, but if you
do this, then it breaks the graph generation.
  • Loading branch information
Notgnoshi committed Apr 19, 2022
1 parent 8e6d30d commit 690cc9c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/example1/src/circular.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#pragma once
#include "private.h"
#include <string>
1 change: 1 addition & 0 deletions examples/example1/src/example1.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <example1/foo.h>
#include <example1/bar.h>
#include "private.h"
#include <iostream>
1 change: 1 addition & 0 deletions examples/example1/src/private.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#pragma once
#include "circular.h"
#include <vector>
6 changes: 3 additions & 3 deletions includegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def build_header_dependency_graph(includes: Iterable[FileInclusion]) -> Dict:
graph = collections.defaultdict(list)
file_include: FileInclusion
for file_include in includes:
logging.debug("Found header inclusion: %s", file_include)
source = file_include.source.name
included_file = file_include.include.name
# logging.debug("Found header inclusion: %s -> %s", file_include.source, file_include.include)
source = file_include.source#.name
included_file = file_include.include#.name
graph[source].append(included_file)

return graph
Expand Down

0 comments on commit 690cc9c

Please sign in to comment.