@@ -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
456490std::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
626660unsigned 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-
666699unsigned 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