added analyzer traces for debug

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I2ff65de0cbf6893359c5dbc5096c7382749fb4da
diff --git a/analyzer/analyzer_main.cpp b/analyzer/analyzer_main.cpp
index b84153b..d374fb6 100644
--- a/analyzer/analyzer_main.cpp
+++ b/analyzer/analyzer_main.cpp
@@ -13,10 +13,6 @@
 namespace analyzer
 {
 
-/** @brief Chip types that coorelate device tree nodes to chip data files */
-static constexpr uint8_t chipTypeOcmb[4] = {0x00, 0x20, 0x0d, 0x16};
-static constexpr uint8_t chipTypeProc[4] = {0x49, 0xa0, 0x0d, 0x12};
-
 /**
  * @brief send chip data file to isolator
  *
@@ -64,6 +60,74 @@
 
 //------------------------------------------------------------------------------
 
+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* __path(const libhei::Chip& i_chip)
+{
+    return pdbg_target_path((pdbg_target*)i_chip.getChip());
+}
+
+const char* __attn(libhei::AttentionType_t i_attnType)
+{
+    const char* str = "";
+    switch (i_attnType)
+    {
+        case libhei::ATTN_TYPE_CHECKSTOP:
+            str = "CHECKSTOP";
+            break;
+        case libhei::ATTN_TYPE_UNIT_CS:
+            str = "UNIT_CS";
+            break;
+        case libhei::ATTN_TYPE_RECOVERABLE:
+            str = "RECOVERABLE";
+            break;
+        case libhei::ATTN_TYPE_SP_ATTN:
+            str = "SP_ATTN";
+            break;
+        case libhei::ATTN_TYPE_HOST_ATTN:
+            str = "HOST_ATTN";
+            break;
+        default:
+            trace::err("Unsupported attention type: %u", i_attnType);
+            assert(0);
+    }
+    return str;
+}
+
+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);
+
+    // Technically, the FapiPos attribute is 32-bit, but not likely to ever go
+    // over 24-bit.
+
+    return type << 24 | (pos & 0xffffff);
+}
+
+uint32_t __sig(const libhei::Signature& i_sig)
+{
+    return i_sig.getId() << 16 | i_sig.getInstance() << 8 | i_sig.getBit();
+}
+
+//------------------------------------------------------------------------------
+
 // Returns the chip model/level of the given target. Also, adds the chip
 // model/level to the list of type types needed to initialize the isolator.
 libhei::ChipType_t __getChipType(pdbg_target* i_trgt,
@@ -75,11 +139,8 @@
     // 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.
-    char* attrType = new char[1];
-
-    pdbg_target_get_attribute(i_trgt, "ATTR_TYPE", 1, 1, attrType);
-
-    switch (attrType[0])
+    uint8_t attrType = __attrType(i_trgt);
+    switch (attrType)
     {
         case 0x05: // PROC
             type = 0x120DA049;
@@ -90,11 +151,9 @@
             break;
 
         default:
-            trace::err("Unsupported ATTR_TYPE value: 0x%02x", attrType[0]);
+            trace::err("Unsupported ATTR_TYPE value: 0x%02x", attrType);
             assert(0);
     }
-
-    delete[] attrType;
     // END WORKAROUND
 
     o_types.push_back(type);
@@ -133,7 +192,13 @@
         }
     }
 
-    // Make sure the model/level list is of unique values only.
+    // For debug, trace out all of the chips found.
+    for (const auto& chip : o_chips)
+    {
+        trace::inf("chip:%s type:0x%0" PRIx32, __path(chip), chip.getType());
+    }
+
+    // Make sure the model/level list contains unique values only.
     auto itr = std::unique(o_types.begin(), o_types.end());
     o_types.resize(std::distance(o_types.begin(), itr));
 }
@@ -176,6 +241,13 @@
 // analysis failed.
 void __filterRootCause(std::vector<libhei::Signature>& io_list)
 {
+    // For debug, trace out the original list of signatures before filtering.
+    for (const auto& sig : io_list)
+    {
+        trace::inf("Signature: %s 0x%0" PRIx32 " %s", __path(sig.getChip()),
+                   __sig(sig), __attn(sig.getAttnType()));
+    }
+
     // Special and host attentions are not supported by this user application.
     auto newEndItr =
         std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) {
@@ -208,19 +280,24 @@
 {
     bool attnFound = false;
 
+    trace::inf(">>> enter analyzeHardware()");
+
     // Get the active chips to be analyzed and their types.
     std::vector<libhei::Chip> chipList;
     std::vector<libhei::ChipType_t> chipTypes;
     __getActiveChips(chipList, chipTypes);
 
     // Initialize the isolator for all chip types.
+    trace::inf("Initializing isolator: # of types=%u", chipTypes.size());
     __initializeIsolator(chipTypes);
 
     // Isolate attentions.
+    trace::inf("Isolating errors: # of chips=%u", chipList.size());
     libhei::IsolationData isoData{};
     libhei::isolate(chipList, isoData);
 
-    // Filter signatures to determine root cause.
+    // Filter signatures to determine root cause. We'll need to make a copy of
+    // the list so that the original list is maintained for the log.
     std::vector<libhei::Signature> sigList{isoData.getSignatureList()};
     __filterRootCause(sigList);
 
@@ -237,16 +314,19 @@
         trace::inf("Active attentions found: %d", sigList.size());
 
         libhei::Signature root = sigList.front();
-        trace::inf("Root cause attention: %p 0x%04x%02x%02x %d",
+        trace::inf("Root cause attention: %p 0x%04x%02x%02x %s",
                    root.getChip().getChip(), root.getId(), root.getInstance(),
-                   root.getBit(), root.getAttnType());
+                   root.getBit(), __attn(root.getAttnType()));
 
         // TODO: generate log information
     }
 
     // All done, clean up the isolator.
+    trace::inf("Uninitializing isolator");
     libhei::uninitialize();
 
+    trace::inf("<<< exit analyzeHardware()");
+
     return attnFound;
 }