util::pdbg functions for path, position, and target type

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I4f4a5b1aa6ab13f60e61d77a866cfc24c7854677
diff --git a/analyzer/analyzer_main.cpp b/analyzer/analyzer_main.cpp
index cf3d195..cf78149 100644
--- a/analyzer/analyzer_main.cpp
+++ b/analyzer/analyzer_main.cpp
@@ -24,22 +24,6 @@
 
 //------------------------------------------------------------------------------
 
-uint8_t __attrType(pdbg_target* i_trgt)
-{
-    uint8_t attr = 0;
-    pdbg_target_get_attribute(i_trgt, "ATTR_TYPE", 1, 1, &attr);
-    return attr;
-}
-
-uint32_t __attrFapiPos(pdbg_target* i_trgt)
-{
-    uint32_t attr = 0;
-    pdbg_target_get_attribute(i_trgt, "ATTR_FAPI_POS", 4, 1, &attr);
-    return attr;
-}
-
-//------------------------------------------------------------------------------
-
 const char* __attn(libhei::AttentionType_t i_attnType)
 {
     const char* str = "";
@@ -69,10 +53,8 @@
 
 uint32_t __trgt(const libhei::Signature& i_sig)
 {
-    auto trgt = (pdbg_target*)i_sig.getChip().getChip();
-
-    uint8_t type = __attrType(trgt);
-    uint32_t pos = __attrFapiPos(trgt);
+    uint8_t type = util::pdbg::getTrgtType(i_sig.getChip());
+    uint32_t pos = util::pdbg::getChipPos(i_sig.getChip());
 
     // Technically, the FapiPos attribute is 32-bit, but not likely to ever go
     // over 24-bit.
@@ -96,7 +78,7 @@
     // TODO: Will need to grab the model/level from the target attributes when
     //       they are available. For now, use ATTR_TYPE to determine which
     //       currently supported value to use supported.
-    uint8_t attrType = __attrType(i_trgt);
+    uint8_t attrType = util::pdbg::getTrgtType(i_trgt);
     switch (attrType)
     {
         case 0x05: // PROC
diff --git a/analyzer/hei_user_interface.cpp b/analyzer/hei_user_interface.cpp
index ee87f79..0f4a441 100644
--- a/analyzer/hei_user_interface.cpp
+++ b/analyzer/hei_user_interface.cpp
@@ -10,6 +10,7 @@
 #include <stdio.h>
 
 #include <hei_user_interface.hpp>
+#include <util/pdbg.hpp>
 #include <util/trace.hpp>
 
 namespace libhei
@@ -58,7 +59,7 @@
         default:
             trace::err("Unsupported register type: trgt=%s regType=0x%02x "
                        "addr=0x%0" PRIx64,
-                       pdbg_target_path(i_procTrgt), i_regType, i_address);
+                       util::pdbg::getPath(i_procTrgt), i_regType, i_address);
             assert(0); // an unsupported register type
     }
 
@@ -87,7 +88,7 @@
         default:
             trace::err("Unsupported register type: trgt=%s regType=0x%02x "
                        "addr=0x%0" PRIx64,
-                       pdbg_target_path(i_obmcTrgt), i_regType, i_address);
+                       util::pdbg::getPath(i_obmcTrgt), i_regType, i_address);
             assert(0);
     }
     */
@@ -102,10 +103,9 @@
 {
     bool accessFailure = false;
 
-    auto trgt = (pdbg_target*)(i_chip.getChip());
+    auto trgt = util::pdbg::getTrgt(i_chip);
 
-    uint8_t trgtType = 0;
-    pdbg_target_get_attribute(trgt, "ATTR_TYPE", 1, 1, &trgtType);
+    uint8_t trgtType = util::pdbg::getTrgtType(trgt);
 
     switch (trgtType)
     {
@@ -119,14 +119,14 @@
 
         default:
             trace::err("Unsupported target type: trgt=%s trgtType=0x%02x",
-                       pdbg_target_path(trgt), trgtType);
+                       util::pdbg::getPath(trgt), trgtType);
             assert(0);
     }
 
     if (accessFailure)
     {
         trace::err("%s failure: trgt=%s addr=0x%0" PRIx64, __regType(i_regType),
-                   pdbg_target_path(trgt), i_address);
+                   util::pdbg::getPath(trgt), i_address);
         o_value = 0; // just in case
     }
 
diff --git a/util/pdbg.cpp b/util/pdbg.cpp
index 14768c0..53c8020 100644
--- a/util/pdbg.cpp
+++ b/util/pdbg.cpp
@@ -1,6 +1,3 @@
-
-#include <libpdbg.h>
-
 #include <util/pdbg.hpp>
 
 namespace util
@@ -11,9 +8,49 @@
 
 //------------------------------------------------------------------------------
 
+pdbg_target* getTrgt(const libhei::Chip& i_chip)
+{
+    return (pdbg_target*)i_chip.getChip();
+}
+
+//------------------------------------------------------------------------------
+
+const char* getPath(pdbg_target* i_trgt)
+{
+    return pdbg_target_path(i_trgt);
+}
+
 const char* getPath(const libhei::Chip& i_chip)
 {
-    return pdbg_target_path((pdbg_target*)i_chip.getChip());
+    return getPath(getTrgt(i_chip));
+}
+
+//------------------------------------------------------------------------------
+
+uint32_t getChipPos(pdbg_target* i_trgt)
+{
+    uint32_t attr = 0;
+    pdbg_target_get_attribute(i_trgt, "ATTR_FAPI_POS", 4, 1, &attr);
+    return attr;
+}
+
+uint32_t getChipPos(const libhei::Chip& i_chip)
+{
+    return getChipPos(getTrgt(i_chip));
+}
+
+//------------------------------------------------------------------------------
+
+uint8_t getTrgtType(pdbg_target* i_trgt)
+{
+    uint8_t attr = 0;
+    pdbg_target_get_attribute(i_trgt, "ATTR_TYPE", 1, 1, &attr);
+    return attr;
+}
+
+uint8_t getTrgtType(const libhei::Chip& i_chip)
+{
+    return getTrgtType(getTrgt(i_chip));
 }
 
 //------------------------------------------------------------------------------
diff --git a/util/pdbg.hpp b/util/pdbg.hpp
index 2ee1c61..58af138 100644
--- a/util/pdbg.hpp
+++ b/util/pdbg.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <libpdbg.h>
+
 #include <hei_main.hpp>
 
 namespace util
@@ -8,12 +10,27 @@
 namespace pdbg
 {
 
-/**
- * @param  A chip.
- * @return A string representing the chip's devtree path.
- */
+/** @return The target associated with the given chip. */
+pdbg_target* getTrgt(const libhei::Chip& i_chip);
+
+/** @return A string representing the given target's devtree path. */
+const char* getPath(pdbg_target* i_trgt);
+
+/** @return A string representing the given chip's devtree path. */
 const char* getPath(const libhei::Chip& i_chip);
 
+/** @return The absolute position of the given target. */
+uint32_t getChipPos(pdbg_target* i_trgt);
+
+/** @return The absolute position of the given chip. */
+uint32_t getChipPos(const libhei::Chip& i_chip);
+
+/** @return The target type of the given target. */
+uint8_t getTrgtType(pdbg_target* i_trgt);
+
+/** @return The target type of the given chip. */
+uint8_t getTrgtType(const libhei::Chip& i_chip);
+
 } // namespace pdbg
 
 } // namespace util