+
Skip to content

Remove check for compilation directory matching first file directory. #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

crzysdrs
Copy link
Contributor

@crzysdrs crzysdrs commented Jun 3, 2025

Fix for issue #765.

Use the directory index zero, which is the correct compilation directory and ignore the compilation file provided index.

In the testcase attached to the issue, the directory that the compilation was invoked in was /. The file itself was provided as an absolute path /usr/src/lfr-test/gdb//fibonacci.c. It's not strictly the case that the compilation file will have a directory that matches the compilation directory.

Simplified Compilation instruction invoked from /:

gcc  -gdwarf-5 -fPIC -c -o /tmp/fibonacci.o /usr/src/lfr-test/gdb//fibonacci.c

However, it does appear that the compilation directory being the first entry in the directories list assumption is upheld.

There is no guarantee the first file eixsts directly in the compilation directory.
@crzysdrs crzysdrs changed the title Use compilation file directory index rather than zero Remove check for compilation directory matching first file directory. Jun 4, 2025
@philipc
Copy link
Collaborator

philipc commented Jun 4, 2025

This change is what I tested in #765 (comment) and I don't think it is correct. If you have a source file in /tmp/test and run the gcc command in /tmp/test/build, gcc produces these files:

include_directories[  0] = "/tmp/test/build"
include_directories[  1] = ".."
file_names[  0]:
           name: "fibonacci.c"
      dir_index: 1
file_names[  1]:
           name: "fibonacci.c"
      dir_index: 1

If I then pass that DWARF through gimli with this PR, it results in these files:

include_directories[  0] = "/tmp/test/build"
include_directories[  1] = ".."
file_names[  0]:
           name: "fibonacci.c"
      dir_index: 0
file_names[  1]:
           name: "fibonacci.c"
      dir_index: 1

That first file_names entry is saying that the primary source file is "/tmp/test/build/fibonacci.c", which is wrong.

What we need is an API that lets you specify a separate directories for the working directory and primary source file directory. Currently LineProgram::new assumes these are identical, which is too limiting.

@crzysdrs
Copy link
Contributor Author

crzysdrs commented Jun 4, 2025

Yeah I figured this wasn't the best solution.

@crzysdrs crzysdrs closed this Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载