llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.44k stars 11.76k forks source link

how to get cfg #112099

Open 6eanut opened 4 hours ago

6eanut commented 4 hours ago

I am new to llvm. I was recently trying to generate a cfg diagram of a c program using llvm. But there were some problems. environment: ubuntu@ubuntu:~/code$ uname -a Linux ubuntu 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:26:41 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux ubuntu@ubuntu:~/code$ cat /etc/os-release PRETTY_NAME="Ubuntu 24.04.1 LTS" NAME="Ubuntu" VERSION_ID="24.04" VERSION="24.04.1 LTS (Noble Numbat)" VERSION_CODENAME=noble ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=noble LOGO=ubuntu-logo test: i wrote a c program run the command "clang -S -emit-llvm test.c -o test.ll", and then got a test.ll successly ubuntu@ubuntu:~/code$ opt -dot-cfg test.ll opt: Unknown command line argument '-dot-cfg'. Try: 'opt --help' opt: Did you mean '--dot-dom'? or ubuntu@ubuntu:~/code$ opt -passes=dot-cfg test.ll WARNING: You're attempting to print out a bitcode file. This is inadvisable as it may cause display problems. If you REALLY want to taste LLVM bitcode first-hand, you can force output with the-f' option.`

marcauberer commented 3 hours ago

You can dump the callgraph with this command:

opt -passes=dot-callgraph -disable-output test.ll