Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. ```cpp
  2. static void D() { }
  3. static void Y() { D(); }
  4. static void X() { Y(); }
  5. static void C() { D(); X(); }
  6. static void B() { C(); }
  7. static void S() { D(); }
  8. static void P() { S(); }
  9. static void O() { P(); }
  10. static void N() { O(); }
  11. static void M() { N(); }
  12. static void G() { M(); }
  13. static void A() { B(); G(); }
  14.  
  15. int main() {
  16. A();
  17. }
  18. ```
  19. easy step:
  20. ```
  21. $ clang++ -S -emit-llvm main1.cpp -o - | opt -analyze -dot-callgraph
  22. $ dot -Tpng -ocallgraph.png callgraph.dot
  23. ```
  24.  
  25. filtered step:
  26. ```cpp
  27. #include <vector>
  28.  
  29. struct A {
  30. A(int);
  31. void f(); // not defined, prevents inlining it!
  32. };
  33.  
  34. int main() {
  35. std::vector<A> v;
  36. v.push_back(42);
  37. v[0].f();
  38. }
  39. ```
  40.  
  41. two commands:
  42. ```
  43. $ clang++ -S -emit-llvm main1.cpp -o - |
  44. opt -analyze -std-link-opts -dot-callgraph
  45. $ cat callgraph.dot |
  46. c++filt |
  47. sed 's,>,\\>,g; s,-\\>,->,g; s,<,\\<,g' |
  48. gawk '/external node/{id=$1} $1 != id' |
  49. dot -Tpng -ocallgraph.png
  50. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement