1*387f9dfdSAndroid Build Coastguard Worker /* 2*387f9dfdSAndroid Build Coastguard Worker * Copyright (c) 2017 Facebook, Inc. 3*387f9dfdSAndroid Build Coastguard Worker * 4*387f9dfdSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*387f9dfdSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*387f9dfdSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*387f9dfdSAndroid Build Coastguard Worker * 8*387f9dfdSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*387f9dfdSAndroid Build Coastguard Worker * 10*387f9dfdSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*387f9dfdSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*387f9dfdSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*387f9dfdSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*387f9dfdSAndroid Build Coastguard Worker * limitations under the License. 15*387f9dfdSAndroid Build Coastguard Worker */ 16*387f9dfdSAndroid Build Coastguard Worker 17*387f9dfdSAndroid Build Coastguard Worker #include "bpf_module.h" 18*387f9dfdSAndroid Build Coastguard Worker #include "frontends/clang/loader.h" 19*387f9dfdSAndroid Build Coastguard Worker 20*387f9dfdSAndroid Build Coastguard Worker namespace ebpf { 21*387f9dfdSAndroid Build Coastguard Worker 22*387f9dfdSAndroid Build Coastguard Worker class SourceDebugger { 23*387f9dfdSAndroid Build Coastguard Worker public: SourceDebugger(llvm::Module * mod,sec_map_def & sections,ProgFuncInfo & prog_func_info,const std::string & mod_src,std::map<std::string,std::string> & src_dbg_fmap)24*387f9dfdSAndroid Build Coastguard Worker SourceDebugger(llvm::Module *mod, sec_map_def §ions, 25*387f9dfdSAndroid Build Coastguard Worker ProgFuncInfo &prog_func_info, const std::string &mod_src, 26*387f9dfdSAndroid Build Coastguard Worker std::map<std::string, std::string> &src_dbg_fmap) 27*387f9dfdSAndroid Build Coastguard Worker : mod_(mod), 28*387f9dfdSAndroid Build Coastguard Worker sections_(sections), 29*387f9dfdSAndroid Build Coastguard Worker prog_func_info_(prog_func_info), 30*387f9dfdSAndroid Build Coastguard Worker mod_src_(mod_src), 31*387f9dfdSAndroid Build Coastguard Worker src_dbg_fmap_(src_dbg_fmap) {} 32*387f9dfdSAndroid Build Coastguard Worker // Only support dump for llvm 6.x and later. 33*387f9dfdSAndroid Build Coastguard Worker // 34*387f9dfdSAndroid Build Coastguard Worker // The llvm 5.x, but not earlier versions, also supports create 35*387f9dfdSAndroid Build Coastguard Worker // a dwarf context for source debugging based 36*387f9dfdSAndroid Build Coastguard Worker // on a set of in-memory sections with slightly different interfaces. 37*387f9dfdSAndroid Build Coastguard Worker // FIXME: possibly to support 5.x 38*387f9dfdSAndroid Build Coastguard Worker // 39*387f9dfdSAndroid Build Coastguard Worker #if LLVM_VERSION_MAJOR >= 6 40*387f9dfdSAndroid Build Coastguard Worker void dump(); 41*387f9dfdSAndroid Build Coastguard Worker 42*387f9dfdSAndroid Build Coastguard Worker private: 43*387f9dfdSAndroid Build Coastguard Worker void adjustInstSize(uint64_t &Size, uint8_t byte0, uint8_t byte1); 44*387f9dfdSAndroid Build Coastguard Worker std::vector<std::string> buildLineCache(); 45*387f9dfdSAndroid Build Coastguard Worker void dumpSrcLine(const std::vector<std::string> &LineCache, 46*387f9dfdSAndroid Build Coastguard Worker const std::string &FileName, uint32_t Line, 47*387f9dfdSAndroid Build Coastguard Worker uint32_t &CurrentSrcLine, llvm::raw_ostream &os); 48*387f9dfdSAndroid Build Coastguard Worker void getDebugSections( 49*387f9dfdSAndroid Build Coastguard Worker llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> &DebugSections); 50*387f9dfdSAndroid Build Coastguard Worker #else dump()51*387f9dfdSAndroid Build Coastguard Worker void dump() { 52*387f9dfdSAndroid Build Coastguard Worker } 53*387f9dfdSAndroid Build Coastguard Worker #endif 54*387f9dfdSAndroid Build Coastguard Worker 55*387f9dfdSAndroid Build Coastguard Worker private: 56*387f9dfdSAndroid Build Coastguard Worker llvm::Module *mod_; 57*387f9dfdSAndroid Build Coastguard Worker const sec_map_def §ions_; 58*387f9dfdSAndroid Build Coastguard Worker ProgFuncInfo &prog_func_info_; 59*387f9dfdSAndroid Build Coastguard Worker const std::string &mod_src_; 60*387f9dfdSAndroid Build Coastguard Worker std::map<std::string, std::string> &src_dbg_fmap_; 61*387f9dfdSAndroid Build Coastguard Worker }; 62*387f9dfdSAndroid Build Coastguard Worker 63*387f9dfdSAndroid Build Coastguard Worker } // namespace ebpf 64