gdb使用

背景:C++开发环境下,掌握gdb的使用很有必要。

通过gdb调用初始化函数。

REG_DRV_MOD_INSTANCE(DRV_MODULE_ID_FNPR_PA_TBL, dha_fnpr_pa_tbl);

dha_fnpr_pa_tbl *g_pa_tbl_ptr = nullptr;
err_t dha_fnpr_pa_tbl::drv_initialize(uint32_t step)
{
  g_pa_tbl_ptr = this;
  if (step == INIT_WITH_OTHER) {
    dha_fnpr_tbl_adapter_ptr adapter(DRV_MODULE_ID_DDM_TBL_RW, pool_);
    if (adapter != nullptr) {
      for (auto item : table_id_) {
        adapter->reg_tbl(item, DRV_MODULE_ID_FNPR_PA_TBL);
      }
    }
  }
  if (step == INIT_CHIP) {
    DCHIP_WARN(("pa init start")(step));
    DRV_RESET_INIT_EXE_ACL(dnid())
    DCHIP_WARN(("hard init pa tbl")(dnid()));
    //auto ret = init_pa();
    //if (ret != UTFP_ERR_SUCCESS)
      //DCHIP_WARN(("init_pa fail")(ret));
  }
  return UTFP_ERR_SUCCESS;
}

err_t dha_fnpr_pa_tbl::write(const ddm_table_ctrldata* ctrldata)
{
  if (!table_id_valid(ctrldata->tbl_id()))
    return UTFP_ERR_SUCCESS;

  auto data = dynamic_cast<const ddm_fnpr_pa_ctrldata*>(ctrldata);
  if (data == nullptr)
    return UTFP_ERR_FAILURE;

  if (data->opcode() == DDM_TABLE_OPCODE_ERASE)
    return del_pa(data);

  if (data->data().key_data.valid == 0)
    return UTFP_ERR_SUCCESS;

  std::pair<uint8_t, std::function<err_t(const ddm_fnpr_pa_ctrldata* data)>> msg_func_tbl[] =
  {
    { FNPR_PA_KEY_ETH, [this](const ddm_fnpr_pa_ctrldata* _data) -> err_t
      { return add_eth_pa(_data); }
    },
  };

  for (const auto& item : msg_func_tbl) {
    if (item.first == data->data().key_data.key_type)
      return (item.second)(data);
  }

  return UTFP_ERR_FAILURE;
}

void init_pa_test(uint32_t step)
{
  g_pa_tbl_ptr->init_pa(step);
}

err_t dha_fnpr_pa_tbl::init_pa(uint32_t step)
{
  ddm_fnpr_painfo_encap painfo(pool_);
  if (!painfo.valid)
    return UTFP_ERR_FAILURE;

  if (step == 0) {
    std::pair<uint8_t, std::function<err_t(const ddm_fnpr_pa_entry& entry,
      uint32_t* key, uint32_t* mask, uint32_t* ad)>> msg_func_tbl[] =
    {
      { FNPR_PA_KEY_ETH, [this](const ddm_fnpr_pa_entry& _entry,
        uint32_t* _key, uint32_t* _mask, uint32_t* _ad) -> err_t
        { return set_eth_pa_key_mask_ad(_entry, _key, _mask, _ad); }
      },
    };

    for (const auto& item : painfo.data.pa_info) {
      uint32_t key[FPI588X_PA_TCAM_ETH_ENTRY_32BIT_WIDTH];
      uint32_t mask[FPI588X_PA_TCAM_ETH_ENTRY_32BIT_WIDTH];
      uint32_t ad[FPI588X_PA_ART_ENTRY_32BIT_WIDTH];
      memset_s(&key[0], sizeof(key), 0, sizeof(key));
      memset_s(&mask[0], sizeof(mask), 0, sizeof(mask));
      memset_s(&ad[0], sizeof(ad), 0, sizeof(ad));

      for (const auto& tbl_item : msg_func_tbl) {
        if ((tbl_item.first == item.key_data.key_type)
          && (item.key_data.valid != 0)) {
          (tbl_item.second)(item, &key[0], &mask[0], &ad[0]);

          FNPR_ADD_TCAM_ENTRY(0, TBL_ID_HPA3, item.tbl_idx,
            key, mask, ad);
        }
      }
    }

  }

 

posted @ 2019-03-15 19:44  CS408  阅读(195)  评论(0编辑  收藏  举报