远程调试leveldb
0)安装snappy
#apt install -y gdb ubuntu-snappy
yum install -y gdb snappy
1)修改编译
修改编译配置Makefile第五行
OPT ?= -O0 -gdwarf-2 -g3
2)调试代码
参考https://blog.csdn.net/a1165741556/article/details/104028855
g++ demo.cpp -o demo out-static/libleveldb.a -lpthread -g -I./include -lsnappy
#include <cassert> #include <iostream> #include <string> #include <leveldb/db.h> int main() { leveldb::DB* db; leveldb::Options options; options.create_if_missing = true; leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db); assert(status.ok()); std::string key = "test_key"; std::string value = "test_value"; std::string get; leveldb::Status s = db->Put(leveldb::WriteOptions(), key, value); if (s.ok()) s = db->Get(leveldb::ReadOptions(), key, &get); if (s.ok()) std::cout << "key=" << key << "\nvalue=" << get << std::endl; else std::cout << "failed to find the key!" << std::endl; delete db; return 0; }
gdb --args ./demo
3)远程调试
gdbserver :1234 ./demo
配置映射
配置对应关系
mapping