Merge pull request #1811 from pchaigno/tcpdrop-smoke-test

Smoke test for tcpdrop
diff --git a/introspection/bps.c b/introspection/bps.c
index 4621099..e3db6b7 100644
--- a/introspection/bps.c
+++ b/introspection/bps.c
@@ -32,6 +32,11 @@
   [BPF_PROG_TYPE_LWT_XMIT] = "lwt xmit",
   [BPF_PROG_TYPE_SOCK_OPS] = "sock ops",
   [BPF_PROG_TYPE_SK_SKB] = "sk skb",
+  [BPF_PROG_TYPE_CGROUP_DEVICE] = "cgroup_device",
+  [BPF_PROG_TYPE_SK_MSG] = "sk_msg",
+  [BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint",
+  [BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
+  [BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2",
 };
 
 static const char * const map_type_strings[] = {
@@ -51,6 +56,8 @@
   [BPF_MAP_TYPE_HASH_OF_MAPS] = "hash of maps",
   [BPF_MAP_TYPE_DEVMAP] = "devmap",
   [BPF_MAP_TYPE_SOCKMAP] = "sockmap",
+  [BPF_MAP_TYPE_CPUMAP] = "cpumap",
+  [BPF_MAP_TYPE_SOCKHASH] = "sockhash",
 };
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
diff --git a/src/cc/frontends/clang/tp_frontend_action.cc b/src/cc/frontends/clang/tp_frontend_action.cc
index 3b46a62..c1b654a 100644
--- a/src/cc/frontends/clang/tp_frontend_action.cc
+++ b/src/cc/frontends/clang/tp_frontend_action.cc
@@ -62,7 +62,15 @@
   if (field_pos == string::npos)
     return field_kind_t::invalid;
 
-  auto semi_pos = line.find(';', field_pos);
+  auto field_semi_pos = line.find(';', field_pos);
+  if (field_semi_pos == string::npos)
+    return field_kind_t::invalid;
+
+  auto offset_pos = line.find("offset:", field_semi_pos);
+  if (offset_pos == string::npos)
+    return field_kind_t::invalid;
+
+  auto semi_pos = line.find(';', offset_pos);
   if (semi_pos == string::npos)
     return field_kind_t::invalid;
 
@@ -70,8 +78,16 @@
   if (size_pos == string::npos)
     return field_kind_t::invalid;
 
+  semi_pos = line.find(';', size_pos);
+  if (semi_pos == string::npos)
+    return field_kind_t::invalid;
+
+  auto size_str = line.substr(size_pos + 5,
+                              semi_pos - size_pos - 5);
+  int size = std::stoi(size_str, nullptr);
+
   auto field = line.substr(field_pos + 6/*"field:"*/,
-                           semi_pos - field_pos - 6);
+                           field_semi_pos - field_pos - 6);
   auto pos = field.find_last_of("\t ");
   if (pos == string::npos)
     return field_kind_t::invalid;
@@ -83,6 +99,32 @@
   if (field_name.find("common_") == 0)
     return field_kind_t::common;
 
+  // adjust the field_type based on the size of field
+  // otherwise, incorrect value may be retrieved for big endian
+  // and the field may have incorrect structure offset.
+  if (size == 2) {
+    if (field_type == "char" || field_type == "int8_t")
+      field_type = "s16";
+    if (field_type == "unsigned char" || field_type == "uint8_t")
+      field_type = "u16";
+  } else if (size == 4) {
+    if (field_type == "char" || field_type == "short" ||
+        field_type == "int8_t" || field_type == "int16_t")
+      field_type = "s32";
+    if (field_type == "unsigned char" || field_type == "unsiggned short" ||
+        field_type == "uint8_t" || field_type == "uint16_t")
+      field_type = "u32";
+  } else if (size == 8) {
+    if (field_type == "char" || field_type == "short" || field_type == "int" ||
+        field_type == "int8_t" || field_type == "int16_t" ||
+        field_type == "int32_t")
+      field_type = "s64";
+    if (field_type == "unsigned char" || field_type == "unsiggned short" ||
+        field_type == "unsigned int" || field_type == "uint8_t" ||
+        field_type == "uint16_t" || field_type == "uint32_t")
+      field_type = "u64";
+  }
+
   return field_kind_t::regular;
 }