gdb 笔记[草稿]

内容分享4天前发布
1 0 0

debug python

~/go/src/ceph/build (heads/v16.2.13 ✗) gdb -ex -r --args python bin/ceph -s
.....
(gdb) b Objecter::_calc_target
Function "Objecter::_calc_target" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (Objecter::_calc_target) pending.
(gdb) b librados_c.cc:285
No symbol table is loaded.  Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (librados_c.cc:285) pending.
(gdb) run

  • Debugging with Gdb
  • Debugging “C” And “C++” Programs Using “gdb”

Quitting GDB

quit [expression]
exit [expression]
q

To exit GDB, use the quit command (abbreviated q), the exit command, or type an end-of-file character (usually Ctrl-d). If you do not supply expression, GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.

An interrupt (often Ctrl-c) does not exit from GDB, but rather terminates the action of any GDB command that is in progress and returns to GDB command level. It is safe to type the interrupt character at any time because GDB does not allow it to take effect until a time when it is safe.

If you have been using GDB to control an attached process or device, you can release it with the detach command (see Debugging an Already-running Process.


build ceph

更新 ceph build 配置项

  • Commit

debug ceph

  • Ceph源码编译和调试之vstart方式
  • 深入理解ceph crush(3)—Object至PG映射源码分析

ctl + x + a 可以切换到 TUI界面

info args 打印函数参数
info break 打印断点
info sharedlibrary provides information about currently loaded shared libraries (DLLs).
info sources provides information about the source files recognized by GDB
info threads
print *my_array@len 打印数组
(gdb) x/19dc <char*> 打印字符数组
print (char[len])*char
set print object on When displaying a pointer to an object, identify the actual (derived) type of the object rather than the declared type, using the virtual function table.
set history save on
set print pretty on
set print vtbl on 打印虚函数表
ptype, whatis, and explore 打印类型信息
(gdb) attach <pid> attach 到指定的 pid

  • gdb print settings
  • gdb cheat sheet

debug subsystem

--debug-<subsystem>

radosgw-admin user list --debug-rados=20

common/subsys.h


docker

if you want to simply detach, without stoping the container, which would allow you to reattach at a later time

(docker)# CTRL+P CTRL+Q


CMAKE

  • cmake管理Ceph编译+Ceph工程目录+cmake 实战学习

break points

Objecter::_calc_target
crush_do_rule

OSDMap::object_locator_to_pg
OSDMap::map_to_pg
OSDMap::_pg_to_up_acting_osds
OSDMap::_pg_to_raw_osds
find_rule ?
crush_choose_firstn
Objecter::_get_session
connect_to
Objecter::_send_op
ProtocolV2::send_message

ProtocolV2::write_message



Objecter::_send_op
ProtocolV2::read
Objecter::_op_submit
RadosClient::connect
AsyncConnection::process


(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00007faee7e1c1a4 in RGWPutObj::pre_exec() at /root/go/src/ceph/src/rgw/rgw_op.cc:3798
2       breakpoint     keep y   0x00007faee7e1da1e in RGWPutObj::execute(optional_yield) at /root/go/src/ceph/src/rgw/rgw_op.cc:3919
3       breakpoint     keep y   0x00007faee78b913a in RGWOp::complete() at /root/go/src/ceph/src/rgw/rgw_op.h:199
RGWRados::get_obj_state

rgw::putobj::MultipartObjectProcessor::prepare
RGWPutObj_ObjStore_S3::get_data
RGWObjManifest::generator::create_next
RGWPutObj::execute

rgw::sal::RGWRadosObject::RadosWriteOp::write_meta
RGWRados::Bucket::UpdateIndex::prepare
RGWRados::Bucket::UpdateIndex::complete


RWG

args = {
      str = "partNumber=1&uploadId=2~vvN6qChbC8MzcIpN_Gqa0kj1MV4XnfD",
      empty_str = "",
      val_map = std::map with 2 elements = {
        ["partNumber"] = "1",
        ["uploadId"] = "2~vvN6qChbC8MzcIpN_Gqa0kj1MV4XnfD"
      },
      sys_val_map = std::map with 0 elements,
      sub_resources = std::map with 2 elements = {
        ["partNumber"] = "1",
        ["uploadId"] = "2~vvN6qChbC8MzcIpN_Gqa0kj1MV4XnfD"
    }
    dialect = "s3",
  req_id = "9e36213f-fd8f-49f2-836a-b1119c7788be.14158.14613913365004085002",
  trans_id = "tx00000cacf0cc71366e70a-00649e98bd-374e-default",
  id = 14613913365004085002,

placement_pools

$6 = std::map with 1 element = {
  ["default-placement"] = {
    index_pool = {
      name = "default.rgw.buckets.index",
      ns = ""
    },
    data_extra_pool = {
      name = "default.rgw.buckets.non-ec",
      ns = ""
    },
    storage_classes = {
      m = std::map with 1 element = {
        ["STANDARD"] = {
          data_pool = {
            <boost::optional_detail::optional_base<rgw_pool>> = {
              <boost::optional_detail::optional_tag> = {<No data fields>},
              members of boost::optional_detail::optional_base<rgw_pool>:
              m_initialized = true,
              m_storage = {
                dummy_ = {
                  data = "`2620166307U0000300000000000000036",  00  <repeats 15 times>, "ج36665307U",  00 
<repeats 25 times>,
                  aligner_ = {<No data fields>}
                }
              }
            }, <No data fields>},
          compression_type = {
            <boost::optional_detail::optional_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >> = {
              <boost::optional_detail::optional_tag> = {<No data fields>},
              members of boost::optional_detail::optional_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
>:
              m_initialized = false,
              m_storage = {
                dummy_ = {
                  data =  00  <repeats 31 times>,
                  aligner_ = {<No data fields>}
                }
              }
            }, <No data fields>}
        }
      },
      standard_class = 0x55c735f6aca0
    },
    index_type = rgw::BucketIndexType::Normal
  }
}

en.create_begin

(gdb) p stripe_obj
$72 = {
  pool = {
    name = "default.rgw.buckets.data",
    ns = ""
  },
  oid = "5052d818-1167-4317-9c9f-ead6970e16ed.4333.1__multipart_17M.2~F0cIhW4n1t2YGvBG2R-jeGHBJBiluvY.1",
  loc = ""
}

(gdb) p head_obj
$73 = (rgw::sal::RGWRadosObject) {
  <rgw::sal::RGWObject> = {
    _vptr.RGWObject = 0x7f5b22cb7380 <vtable for rgw::sal::RGWRadosObject+16>,
    key = {
      name = "17M.2~F0cIhW4n1t2YGvBG2R-jeGHBJBiluvY.1",
      instance = "",
      ns = "multipart"
    },
    bucket = 0x55da1ebd0d00,
    index_hash_source = "17M",
    obj_size = 0,

set_stripe_obj /root/go/src/ceph/src/rgw/rgw_putobj_processor.cc

(gdb) p stripe_obj
$106 = {
  rados_svc = 0x55da1cba2f90,
  ref = {
    pool = {
      rados_svc = 0x55da1cba2f90,
      pool = {
        name = "default.rgw.buckets.data",
        ns = ""
      },
      state = {
        ioctx = {
          io_ctx_impl = 0x0
        }
      }
    },
    obj = {
      pool = {
        name = "default.rgw.buckets.data",
        ns = ""
      },
      oid = "5052d818-1167-4317-9c9f-ead6970e16ed.4333.1__multipart_17M.2~SHO9VFCctN-eNn3Ywd7WMJDSTVq3rvN.1",
      loc = ""
    }
  }
}

rgw get object

(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>         
1.1                         y     0x00007f95406c16d0 <RGWRados::iterate_obj(DoutPrefixProvider const*, RGWObjectCtx&, RGWBucketInfo const&, rgw_obj const&, long, long, unsigned long, int (*)(DoutPrefixProvider const*, rgw_raw_obj const&, long, long, long, bool, RGWObjState*, void*), void*, optional_yield)@plt>
1.2                         y     0x00007f9540f4ce1a in RGWRados::iterate_obj(DoutPrefixProvider const*, RGWObjectCtx&, RGWBucketInfo const&, rgw_obj const&, long, long, unsigned long, int (*)(DoutPrefixProvider const*, rgw_raw_obj const&, long, long, long, bool, RGWObjState*, void*), void*, optional_yield) at /root/go/src/ceph/src/rgw/rgw_rados.cc:6532
2       breakpoint     keep y   <MULTIPLE>         
2.1                         y     0x00007f95406ee6c0 <RGWRados::get_obj_iterate_cb(DoutPrefixProvider const*, rgw_raw_obj const&, long, long, long, bool, RGWObjState*, void*)@plt>
2.2                         y     0x00007f9540f4c0fb in RGWRados::get_obj_iterate_cb(DoutPrefixProvider const*, rgw_raw_obj const&, long, long, long, bool, RGWObjState*, void*) at /root/go/src/ceph/src/rgw/rgw_rados.cc:6459
3       breakpoint     keep y   <MULTIPLE>         
3.1                         y     0x00007f95406f1b30 <RGWGetObj_ObjStore_S3::send_response_data(ceph::buffer::v15_2_0::list&, long, long)@plt>
3.2                         y     0x00007f9540fe9e82 in RGWGetObj_ObjStore_S3::send_response_data(ceph::buffer::v15_2_0::list&, long, long) 
                                                   at /root/go/src/ceph/src/rgw/rgw_rest_s3.cc:219

  • RGWGetObj::execute src/rgw/rgw_op.cc

    • read_op->iterate 其中 RGWRadosObject::RadosReadOp

      • RGWRados::Object::Read::iterate 其中 iterate 中会传入客户端回调函数 _get_obj_iterate_cb,本质上是调用 RGWRados::get_obj_iterate_cb,最后实际上是调用客户端回调函数 send_response_data 将数据发送到 client。 src/rgw/rgw_rados.cc

        • RGWRados::iterate_obj

          • obj_to_raw 获取 head obj 信息

          • get_obj_state 获取 obj state 信息

          • _get_obj_iterate_cb

            • RGWRados::get_obj_iterate_cb

              • RGWGetObj_ObjStore_S3::send_response_data src/rgw/rgw_rest_s3.cc

                • dump_header
                • dump_body

先获取 head obj 信息

(gdb) p head_obj
$2 = {
  pool = {
    name = "default.rgw.buckets.data",
    ns = ""
  },
  oid = "58b780c2-c21f-4b13-ba4c-01bf15dc4c23.4330.1_1024/1024M",
  loc = ""
}

获取 obj state 信息,主要是为了获取 manifest 信息

(gdb) p astate->manifest
$7 = std::optional<RGWObjManifest> = {
  [contained value] = {
    explicit_objs = false,
    objs = std::map with 0 elements,
    obj_size = 1073741824,
    obj = {
      bucket = {
        tenant = "",
        name = "test",
        marker = "58b780c2-c21f-4b13-ba4c-01bf15dc4c23.4330.1",
        bucket_id = "58b780c2-c21f-4b13-ba4c-01bf15dc4c23.4330.1",
        explicit_placement = {
          data_pool = {
            name = "",
            ns = ""
          },
          data_extra_pool = {
            name = "",
            ns = ""
          },
          index_pool = {
            name = "",
            ns = ""
          }
        }
      },
      key = {
        name = "1024/1024M",
        instance = "",
        ns = ""
      },
      in_extra_data = false,
      index_hash_source = ""
    },
    head_size = 0,
    head_placement_rule = {
      name = "default-placement",
      storage_class = ""
    },
    max_head_size = 0,
    prefix = "1024/1024M.2~20zrWDEQdihqYRpj5Q64NRD8smS5Q4-",
    tail_placement = {
      placement_rule = {
        name = "default-placement",
        storage_class = ""
      },
      bucket = {
        tenant = "",
        name = "test",
        marker = "58b780c2-c21f-4b13-ba4c-01bf15dc4c23.4330.1",
        bucket_id = "58b780c2-c21f-4b13-ba4c-01bf15dc4c23.4330.1",
        explicit_placement = {
          data_pool = {
            name = "",
            ns = ""
          },
          data_extra_pool = {
            name = "",
            ns = ""
          },
          index_pool = {
            name = "",
            ns = ""
          }
        }
      }
    },
    rules = std::map with 2 elements = {
      [0] = {
        start_part_num = 1,
        start_ofs = 0,
        part_size = 15728640,
        stripe_max_size = 4194304,
        override_prefix = ""
      },
      [1069547520] = {
        start_part_num = 69,
        start_ofs = 1069547520,
        part_size = 4194304,
        stripe_max_size = 4194304,
        override_prefix = ""
      }
    },
    tail_instance = ""
  }
}

(gdb) p read_obj
$3 = {
  pool = {
    name = "default.rgw.buckets.data",
    ns = ""
  },
  oid = "58b780c2-c21f-4b13-ba4c-01bf15dc4c23.4330.1__multipart_1024/1024M.2~6cS9fAXKYh6CcB7MOKFZG-SSt8UCoUb.1",
  loc = ""
}


Reference

  • 5.2 Continuing and Stepping
  • break command
  • Quitting GDB
© 版权声明

相关文章

暂无评论

none
暂无评论...