Skip to content

Commit

Permalink
more progress on getting formal parameter locations
Browse files Browse the repository at this point in the history
note that dyninst is wrong in what it is returning for the
register locations, Tim/Sasha are going to work on it

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed May 11, 2021
1 parent c6f121e commit 5910336
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ find_package(Dyninst REQUIRED)
include_directories(DYNINST_INCLUDE_DIRS)
link_directories(DYNINST_LIBRARIES)


# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.6.0")
CPMAddPackage(
Expand Down Expand Up @@ -55,7 +56,7 @@ set_target_properties(Smeagle PROPERTIES CXX_STANDARD 17)
target_compile_options(Smeagle PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")

# Link dependencies
target_link_libraries(Smeagle PRIVATE fmt::fmt symtabAPI)
target_link_libraries(Smeagle PRIVATE fmt::fmt symtabAPI common instructionAPI)

target_include_directories(
Smeagle PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

all:
cmake --log-level=VERBOSE -DsymtabAPI_DIR=/opt/view/lib/cmake/Dyninst -S all -B build
cmake --build build -DsymtabAPI_DIR=/opt/view/lib/cmake/Dyninst
cmake --build build -DsymtabAPI_DIR=/opt/view/lib/cmake/Dyninst


test:
Expand Down
41 changes: 31 additions & 10 deletions source/corpora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ std::string Corpus::getParamLocationOffset(localVar * param){

// I think we need to do something with these location entries
// https://github.com/dyninst/dyninst/blob/7ce24bf14a7745492754adb5ede560dd343e6585/symtabAPI/src/dwarfWalker.C#L2490
std::string offset;
std::stringstream result;

for (auto i = locs.begin(); i != locs.end(); ++i) {
VariableLocation current = *i;
offset = current.frameOffsetAbs;
//std::cout << current.stClass << std::endl;

// We only want to know where parameter is at the entrypoint
result << std::hex << current.lowPC << " to " << current.hiPC
<< " " << current.mr_reg.name() << " "
<< std::dec << current.frameOffset;

break;
}

return offset;
return result.str();
}


Expand Down Expand Up @@ -173,8 +179,8 @@ void Corpus::toAsp() {
for (auto &typeloc : typelocs) {

std::cout << "abi_typelocation(" << library << ", " << typeloc.parent
<< ", " << typeloc.name << ", " << typeloc.type << ", "
<< typeloc.location << ")" << std::endl;
<< ", " << typeloc.name << ", " << typeloc.type << ", \""
<< typeloc.locoffset << "\")" << std::endl;
}
}

Expand All @@ -186,7 +192,7 @@ void Corpus::toYaml() {

std::cout << " - library: " << library << "\n parent: " << typeloc.parent
<< "\n name: " << typeloc.name << "\n type: " << typeloc.type
<< "\n location: " << typeloc.location << "\n" << std::endl;
<< "\n location: " << typeloc.locoffset << "\n" << std::endl;
}
}

Expand All @@ -206,9 +212,8 @@ void Corpus::toJson() {
}
std::cout << "{\"library\": \"" << library << "\", \"parent\": \""
<< typeloc.parent << "\", \"name\": \"" << typeloc.name << "\", \"type\": \""
<< typeloc.type << "\", \"location\": \"" << typeloc.location
<< "\"}" << endcomma << std::endl;

<< typeloc.type << "\", \"location\": \"" << typeloc.locoffset << "\"}"
<< endcomma << std::endl;
}
std::cout << "]}" << std::endl;

Expand All @@ -226,6 +231,17 @@ void Corpus::parseFunctionABILocation(Symbol *symbol) {
// The function name looks equivalent to the symbol name
std::string fname = func->getName();

// This is for debugging
// auto frange = func->getRanges();
// std::cout << fname << std::endl;

// This is for debugging
// for (auto &range : frange) {
// std::cout << " " << std::hex << range.low() << " to " << range.high() << std::endl << std::endl;
//}

// TODO filter out to just global linkage

// Get parameters with types and names
if (func->getParams(params)) {
// We need to keep track of the order
Expand All @@ -238,6 +254,11 @@ void Corpus::parseFunctionABILocation(Symbol *symbol) {
// Get param location offset (e.g, framebase+x)
std::string locoffset = getParamLocationOffset(param);

// This is for debugging
// std::cout << " " << paramName << std::endl;
// std::cout << " " << paramType << std::endl;
// std::cout << " " << locoffset << std::endl;

// Create a new typelocation to parse later
TypeLocation typeloc;
typeloc.name = paramName;
Expand Down

0 comments on commit 5910336

Please sign in to comment.