Skip to content
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

Compilation databases for Clang-based tools #1

Open
Naetw opened this issue Aug 10, 2018 · 0 comments
Open

Compilation databases for Clang-based tools #1

Naetw opened this issue Aug 10, 2018 · 0 comments

Comments

@Naetw
Copy link
Owner

Naetw commented Aug 10, 2018

Compilation databases for Clang-based tools

最近弄專題需要把 Compilation Database 來餵給 woboq,看了這篇文章,筆記一下。

  • 動機 - 忠實重現編譯行為

    • Clang tools 使用跟 Clang compiler 相同的前端工具來建構 AST。然而這代表著分析工具在分析原始碼時需要完整的資訊,也就是編譯器所擁有的資訊(以 flags 為例):
      • marco definition (-D) & include directories (-I)
        沒有這些 flags,基本上不可能正確的分析原始碼(畢竟一個標準的 C 編譯器工具鍊都會先用前處理器(preprocessor)來處理上面提到的兩個 flags 所需完成的工作,在編譯器看到時根本不會看到 macro 或是需要尋找 include file 在哪。)
  • Compilation Database

    • 對各個檔案的編譯指令的紀錄
    • Fixed compilation database
      • 類似 hard code,將上面提到一些重要的 flags 在使用工具時一併傳進去,但是很明顯地,若要分析大型專案這樣的做法是非常麻煩且沒效率的。
    • JSON compilation database
      • 就是一串列表,每個包含下列資訊:
        • Directory: 編譯行為被執行的資料夾
        • Command: 編譯行為發生時的完整編譯指令
        • File: 編譯行為所作用的檔案
[
{
  "directory": "/tmp",
  "command": "gcc -DFOO div0.c",
  "file": "/tmp/div0.c"
}
]
  • 產生 Compilation Database(列出作者提到的可用工具)
    • CMake 可以簡單加上 DCMAKE_EXPORT_COMPILE_COMMANDS flag
    • Gyp/Ninja 組合
    • Build EAR
@Naetw Naetw changed the title [WIP] Compilation databases for Clang-based tools Compilation databases for Clang-based tools Aug 12, 2018
@Naetw Naetw added the Note label Dec 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant