gdb 笔记[草稿]

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

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 配置项


debug ceph

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


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


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 = "`\262\001\066\307U\000\000\030\000\000\000\000\000\000\000\036", '\000' <repeats 15 times>, "ج\366\065\307U", '\000'
<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 = '\000' <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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,444评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,421评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,363评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,460评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,502评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,511评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,280评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,736评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,014评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,190评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,848评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,531评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,159评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,411评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,067评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,078评论 2 352

推荐阅读更多精彩内容