2
votes

So all I am trying to do is get the names of the functions called by call instructions: This is my simple code:

for(Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
                {
            for(BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; ++BI){
                if(isa<CallInst>(&(*BI)) ) {
                        StringRef fname = cast<CallInst>(&(*BI))->getCalledFunction()->getName();
                  }
     }
}

This is the Nasty error:

0 libLLVM-3.4.so.1 0x40f8150f llvm::sys::PrintStackTrace(_IO_FILE*) + 47

1 libLLVM-3.4.so.1 0x40f8177f

2 libLLVM-3.4.so.1 0x40f812ec

3 0x40022400 __kernel_sigreturn + 0

4 libLLVM-3.4.so.1 0x40899c74 llvm::Value::getName() const + 20

5 SkeletonPass.so 0x40027786

Stack dump: 0. Program arguments: /usr/bin/clang -cc1 -triple i386-pc-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -main-file-name test_atomics.cc -mrelocation-model pic -pic-level 2 -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -target-linker-version 2.24 -momit-leaf-frame-pointer -g -coverage-file /home/danish/Desktop/Owl/llvm/llvm-3.4/lib/Transforms/SyncProf/testing/masstree-beta-master/test_atomics.o -resource-dir /usr/bin/../lib/clang/3.4 -dependency-file .deps/test_atomics.d -MT test_atomics.o -sys-header-deps -MP -include config.h -D NDEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D NDEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D NDEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /usr/lib/llvm-3.4/include -I /usr/lib/llvm-3.4/include -I /usr/lib/llvm-3.4/include -internal-isystem /usr/include//c++/4.8 -internal-isystem /usr/include//c++/4.8/i386-linux-gnu -internal-isystem /usr/include//c++/4.8/backward -internal-isystem /usr/include//i386-linux-gnu/c++/4.8 -internal-isystem /usr/bin/../lib/gcc/i686-linux-gnu/4.8/../../../../include/c++/4.8 -internal-isystem /usr/bin/../lib/gcc/i686-linux-gnu/4.8/../../../../include/c++/4.8/i686-linux-gnu -internal-isystem /usr/bin/../lib/gcc/i686-linux-gnu/4.8/../../../../include/c++/4.8/backward -internal-isystem /usr/bin/../lib/gcc/i686-linux-gnu/4.8/../../../../include/i686-linux-gnu/c++/4.8 -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.4/include -internal-externc-isystem /usr/bin/../lib/gcc/i686-linux-gnu/4.8/include -internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Woverloaded-virtual -Wcast-qual -W -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/danish/Desktop/Owl/llvm/llvm-3.4/lib/Transforms/SyncProf/testing/masstree-beta-master -ferror-limit 19 -fmessage-length 80 -fvisibility-inlines-hidden -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -load /home/danish/Desktop/Owl/llvm/llvm-3.4/Release+Asserts/lib/SkeletonPass.so -o test_atomics.o -x c++ test_atomics.cc

  1. parser at end of file

  2. Per-function optimization

  3. Running pass 'Skeleton Pass' on function '@_Z9test_jsonv' clang: error: unable to execute command: Segmentation fault (core dumped) clang: error: clang frontend command failed due to signal (use -v to see invocation) Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) Target: i386-pc-linux-gnu Thread model: posix clang: note: diagnostic msg: PLEASE submit a bug report to http://bugs.debian.org/ and include the crash backtrace, preprocessed source, and associated run script. clang: note: diagnostic msg:


PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/test_atomics-128b00.cpp clang: note: diagnostic msg: /tmp/test_atomics-128b00.sh clang: note: diagnostic msg:


make: *** [test_atomics.o] Error 254

This error appeared when I added the ->getName() part to retrieve the function names. Help!

1
getCalledFunction could return null if the call is an indirect call through a function pointer.Ismail Badawi

1 Answers

1
votes

Yes I think you were right! I added this null check and it worked: Function *func = cast(&(*BI))->getCalledFunction(); if(func != NULL) errs()<getName(); Thank you @IsmailBadawi!