Skip to content

Commit 8632566

Browse files
committed
update generated eBPF program format
1 parent cb93ddf commit 8632566

4 files changed

Lines changed: 575 additions & 219 deletions

File tree

include/DebugInfoUtils.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ namespace pdg
3434
llvm::DIType *getGlobalVarDIType(llvm::GlobalVariable &gv);
3535
llvm::DIType *getFuncRetDIType(llvm::Function &F);
3636
std::string getArrayTypeStr(llvm::DIType &dt);
37+
std::string getRawArrayTypeStr(llvm::DIType &dt, std::string fieldName); // get the array without IDL syntax (array/projection)
3738
std::string getSourceLevelVariableName(llvm::DINode &dt);
38-
std::string getSourceLevelTypeName(llvm::DIType &dt, bool isRaw=false);
39+
std::string getSourceLevelTypeName(llvm::DIType &dt, bool isRaw=false, std::string fieldName = "");
3940
std::string getSourceLevelTypeNameWithNoQualifer(llvm::DIType &dt);
4041
std::string getArgumentName(llvm::Argument &arg);
4142
unsigned computeFieldOffsetInBytes(llvm::DIType &dt);

include/eBPFProgGeneration.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ namespace pdg
1818
void generateArgRefCopyMaps(std::string argName, std::string argTypeName);
1919
std::string createEbpfMapForType(llvm::DIType &dt);
2020
void generatePerfOutput();
21+
void generateHelperFuncs();
2122
void generateEbpfMapOnFunc(llvm::Function &F);
2223
void generateEbpfMapOnArg(Tree &argTree);
24+
void generateEbpfMapForStructPointer(TreeNode *argRootNode);
25+
void generateEbpfMapForNonStructPointer(llvm::DIType *argRootNode);
2326
void generateEbpfKernelEntryProgOnFunc(llvm::Function &F);
2427
void generateEbpfKernelEntryProgOnArg(Tree &argTree, unsigned argIdx);
25-
void updateRefMap(std::string fieldTypeStr, std::string fieldName, std::string fieldHierarchyName, std::string typeCopyMap);
26-
void updateCopyMap(std::string fieldTypeStr, std::string fieldName, std::string fieldHierarchyName, std::string typeCopyMap);
28+
void updateMap(std::string fieldHierarchyName, std::string typeCopyMap);
29+
// void updateRefMap(std::string fieldTypeStr, std::string fieldName, std::string fieldHierarchyName, std::string typeCopyMap);
30+
// void updateCopyMap(std::string fieldTypeStr, std::string fieldName, std::string fieldHierarchyName, std::string typeCopyMap);
2731
void generateEbpfFieldAccRules(Tree &argTree, std::string argUpdatedCopyName, std::string argCopyName);
2832
std::string retriveFieldFromRefMap(std::string fieldTypeStr, std::string fieldName, std::string typeRefMap);
2933
std::string retriveFieldFromCopyMap(std::string fieldTypeStr, std::string fieldName, std::string typeCopyMap);
3034
void generateEbpfAccessChecksOnArg(Tree &argTree, unsigned argIdx);
31-
void generateEbpfKernelExitProg(llvm::Function &F);
35+
void generateEbpfKernelRetProbe(llvm::Function &F);
3236
void generateEbpfUserProg(llvm::Function &F);
3337
void generateUserProgImports(std::string kernelProgFileName);
3438
void generateProbeAttaches(llvm::Function &F);
@@ -38,6 +42,8 @@ namespace pdg
3842
void generateFuncStructDefinition(llvm::Function &F);
3943
void generateStructDefString(TreeNode &structNode);
4044
std::string switchType(const std::string &typeStr);
45+
bool isUnspportedTypes(llvm::DIType &dt);
46+
std::string getMapDefinition(const std::string &mapName);
4147

4248
private:
4349
DataAccessAnalysis *DAA;

src/DebugInfoUtils.cpp

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ std::string pdg::dbgutils::getSourceLevelVariableName(DINode &di_node)
301301
return "";
302302
}
303303

304-
std::string pdg::dbgutils::getSourceLevelTypeName(DIType &dt, bool isRaw)
304+
std::string pdg::dbgutils::getSourceLevelTypeName(DIType &dt, bool isRaw, std::string fieldName)
305305
{
306306
auto type_tag = dt.getTag();
307307
if (!type_tag)
@@ -334,7 +334,7 @@ std::string pdg::dbgutils::getSourceLevelTypeName(DIType &dt, bool isRaw)
334334
}
335335
case dwarf::DW_TAG_array_type:
336336
{
337-
return getArrayTypeStr(dt);
337+
return getRawArrayTypeStr(dt, fieldName);
338338
}
339339
case dwarf::DW_TAG_const_type:
340340
{
@@ -382,7 +382,41 @@ std::string pdg::dbgutils::getSourceLevelTypeName(DIType &dt, bool isRaw)
382382
return "";
383383
}
384384

385-
std::string pdg::dbgutils::getArrayTypeStr(DIType& dt)
385+
std::string pdg::dbgutils::getRawArrayTypeStr(DIType &dt, std::string fieldName)
386+
{
387+
DICompositeType *dct = cast<DICompositeType>(&dt);
388+
auto elements = dct->getElements();
389+
// check element size
390+
if (elements.size() == 1)
391+
{
392+
auto element_dt = getLowestDIType(*dct);
393+
if (element_dt != nullptr)
394+
{
395+
auto total_size = dct->getSizeInBits();
396+
auto element_size = element_dt->getSizeInBits();
397+
auto element_type_name = getSourceLevelTypeName(*element_dt, true);
398+
if (isStructPointerType(*element_dt))
399+
element_type_name = element_type_name + "*";
400+
else if (isStructType(*element_dt))
401+
element_type_name = element_type_name;
402+
403+
if (total_size != 0 && element_size != 0)
404+
{
405+
auto element_count = total_size / element_size;
406+
std::string arr_field_str = element_type_name + " " + fieldName+ "[" + std::to_string(element_count) + "]";
407+
return arr_field_str;
408+
}
409+
else if (total_size == 0)
410+
{
411+
std::string arr_field_str = element_type_name + " " +fieldName + "[0]";
412+
return arr_field_str;
413+
}
414+
}
415+
}
416+
return "array";
417+
}
418+
419+
std::string pdg::dbgutils::getArrayTypeStr(DIType &dt)
386420
{
387421
DICompositeType *dct = cast<DICompositeType>(&dt);
388422
auto elements = dct->getElements();
@@ -455,10 +489,10 @@ DIType *pdg::dbgutils::getFuncRetDIType(Function &F)
455489

456490
std::set<DIType *> pdg::dbgutils::computeContainedStructTypes(DIType &dt)
457491
{
458-
std::set<DIType* > contained_struct_di_types;
492+
std::set<DIType *> contained_struct_di_types;
459493
if (!isStructType(dt))
460494
return contained_struct_di_types;
461-
std::queue<DIType*> type_queue;
495+
std::queue<DIType *> type_queue;
462496
type_queue.push(&dt);
463497
int current_tree_height = 0;
464498
int max_tree_height = 5;
@@ -482,7 +516,7 @@ std::set<DIType *> pdg::dbgutils::computeContainedStructTypes(DIType &dt)
482516
for (unsigned i = 0; i < di_node_arr.size(); i++)
483517
{
484518
DIType *field_di_type = dyn_cast<DIType>(di_node_arr[i]);
485-
DIType* field_lowest_di_type = getLowestDIType(*field_di_type);
519+
DIType *field_lowest_di_type = getLowestDIType(*field_di_type);
486520
if (!field_lowest_di_type)
487521
continue;
488522
if (isStructType(*field_lowest_di_type))
@@ -509,7 +543,7 @@ std::string pdg::dbgutils::getFuncSigName(DIType &dt, Function &F, std::string f
509543
else
510544
func_type_str += getSourceLevelTypeName(*ret_di_ty);
511545

512-
// generate name string for function pointer
546+
// generate name string for function pointer
513547
func_type_str += " (";
514548
if (!funcPtrName.empty())
515549
func_type_str += "*";
@@ -546,7 +580,7 @@ std::string pdg::dbgutils::getFuncSigName(DIType &dt, Function &F, std::string f
546580
auto baseType = dit->getBaseType();
547581
if (!baseType)
548582
{
549-
// if a DIderived type has a null base type, this normally
583+
// if a DIderived type has a null base type, this normally
550584
// represent a void pointer
551585
func_type_str += "void* ";
552586
}
@@ -625,16 +659,16 @@ std::set<DbgInfoIntrinsic *> pdg::dbgutils::collectDbgInstInFunc(Function &F)
625659

626660
unsigned pdg::dbgutils::computeDeepCopyFields(DIType &dt, bool onlyCountPointer)
627661
{
628-
std::queue<DIType*> typeQueue;
629-
std::unordered_set<DIType*> seenTypes;
662+
std::queue<DIType *> typeQueue;
663+
std::unordered_set<DIType *> seenTypes;
630664
unsigned fieldNum = isPointerType(dt) ? 1 : 0;
631665
typeQueue.push(&dt);
632-
666+
633667
while (!typeQueue.empty())
634668
{
635-
DIType* curDt = typeQueue.front();
669+
DIType *curDt = typeQueue.front();
636670
typeQueue.pop();
637-
DIType* lowestDt = getLowestDIType(*curDt);
671+
DIType *lowestDt = getLowestDIType(*curDt);
638672

639673
if (lowestDt == nullptr || !isStructType(*lowestDt))
640674
continue;
@@ -662,11 +696,10 @@ unsigned pdg::dbgutils::computeDeepCopyFields(DIType &dt, bool onlyCountPointer)
662696
return fieldNum;
663697
}
664698

665-
666699
unsigned pdg::dbgutils::computeStructTypeStorageSize(DIType &dt, unsigned depth)
667700
{
668-
std::queue<DIType*> typeQueue;
669-
std::unordered_set<DIType*> seenTypes;
701+
std::queue<DIType *> typeQueue;
702+
std::unordered_set<DIType *> seenTypes;
670703
unsigned storageSize = 0;
671704
typeQueue.push(&dt);
672705

@@ -699,6 +732,6 @@ unsigned pdg::dbgutils::computeStructFieldNum(llvm::DIType &dt)
699732
{
700733
if (!isStructType(dt))
701734
return -1;
702-
auto diNodeArr = dyn_cast<DICompositeType>(&dt)->getElements();
735+
auto diNodeArr = dyn_cast<DICompositeType>(&dt)->getElements();
703736
return diNodeArr.size();
704737
}

0 commit comments

Comments
 (0)