1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gdb覚書

Last updated at Posted at 2019-12-14

config

# 長い文字列が途切れないように
# default 200
set print elements 0
# 重複も直接表示する
# default 10
set print repeats 0
# 整形して出力
set print pretty on
# 一気に表示する
set pagination off
# オーバーロード解決を無効にする(?) 個人的には無効のほうがちゃんと動く感じがする
set overload-resolution off

generate string

set $fname=(std::string*)((void*(*)(int))malloc)(sizeof(std::string))
call $fname->basic_string()
call $fname->assign("/tmp/hello")

https://stackoverflow.com/questions/41695254/can-gdb-print-64-bit-address/41705611#41705611 によると、ポインタは、正しいシグネチャの関数ポインタにキャストすれば使えるらしい。

なおこのテクニックはPerl_get_context()を渡すときにも使います。

calling shared_ptr

#include <memory>
#include <boost/shared_ptr.hpp>

class obj{
public:
    int fff(int i){return i;}
};

int main(){
    boost::shared_ptr<obj> o(new obj);
    return o->fff(0);
}
# boost
set overload-resolution off
p (*o.px)->fff(1)
# std
set overload-resolution off
p (*o._M_ptr)->fff(1)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?