From 36a69fbbb460b75bd43d1881fd9c09b54c912cf7 Mon Sep 17 00:00:00 2001 From: Tim Haines Date: Wed, 10 Jan 2024 10:49:49 -0600 Subject: [PATCH] Add parseAPI/simpleParser (#24) This is both a good sanity check for PRs and can be used as a larger system-level parser for things like running through /usr/lib. --- parseAPI/CMakeLists.txt | 5 +++++ parseAPI/simpleParser.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 parseAPI/simpleParser.cpp diff --git a/parseAPI/CMakeLists.txt b/parseAPI/CMakeLists.txt index a36db4d..79d08df 100644 --- a/parseAPI/CMakeLists.txt +++ b/parseAPI/CMakeLists.txt @@ -2,3 +2,8 @@ project(parseAPI) add_executable(parseAPI_includes includes.cpp) target_link_libraries(parseAPI_includes PRIVATE Dyninst::parseAPI) + +add_executable(simpleParser simpleParser.cpp) +target_link_libraries(simpleParser PRIVATE Dyninst::parseAPI) +add_test(NAME parseAPI_simpleParser + COMMAND sh -c "./simpleParser simpleParser") \ No newline at end of file diff --git a/parseAPI/simpleParser.cpp b/parseAPI/simpleParser.cpp new file mode 100644 index 0000000..62b75ca --- /dev/null +++ b/parseAPI/simpleParser.cpp @@ -0,0 +1,23 @@ +#include "CFG.h" +#include "CodeObject.h" +#include + +namespace dp = Dyninst::ParseAPI; +int main(int argc, char* argv[]) { + if(argc < 2 || argc > 3) { + std::cerr << "Usage: " << argv[0] << " file\n"; + return -1; + } + + try { + auto* sts = new dp::SymtabCodeSource(argv[1]); + auto* co = new dp::CodeObject(sts); + co->parse(); + } catch(std::exception &e) { + std::cerr << e.what() << '\n'; + return -1; + } catch(...) { + std::cerr << "unknown exception occurred\n"; + return -1; + } +}