处理输入
- void debugger::handle_command(const std::string& line) {
- auto args = split(line,' ');
- auto command = args[0];
- if (is_prefix(command, "continue")) {
- continue_execution();
- }
- else {
- std::cerr << "Unknown command\n";
- }
- }
split 和 is_prefix 是一对有效的小法度榜样:
- std::vector<std::string> split(const std::string &s, char delimiter) {
- std::vector<std::string> out{};
- std::stringstream ss {s};
- std::string item;
- while (std::getline(ss,item,delimiter)) {
- out.push_back(item);
- }
- return out;
- }
- bool is_prefix(const std::string& s, const std::string& of) {
- if (s.size() > of.size()) return false;
- return std::equal(s.begin(), s.end(), of.begin());
- }
我们会把 continue_execution 函数添加到 debuger 类。
- void debugger::continue_execution() {
- ptrace(PTRACE_CONT, m_pid, nullptr, nullptr);
- int wait_status;
- auto options = 0;
- waitpid(m_pid, &wait_status, options);
- }
如今我们的 continue_execution 函数会用 ptrace 告诉过程持续履行,然后用 waitpid 等待直到收到旌旗灯号。
总结
如今你应当编译一些 C 或者 C++ 法度榜样,然后用你的调试器运行它们,看它是否能在函数人口暂停、大年夜调试器中持续履行。鄙人一篇文┞仿中,我们会进修若何让我们的调试器设置断点。如不雅你碰到了任何问题,鄙人面的评论框中告诉我吧!
你可以在这里找到该项目标代码。
【编辑推荐】
- Linux+Apache+Mysql+PHP优化技能
- 2017十大年夜最佳用于隐私和安然保护的Linux发行版
- Linux常用机能分析敕令
- Linux过程间通信——应用消息队列
- Linux中高效编写Bash脚本的10个技能
推荐阅读
人工智能与万物互联已成为智能化、网联化迈入纵深的使能技巧,为集成电路家当带来四大年夜计谋机会:形成计谋新需求、开辟技巧新偏向、构建研发新模式、塑造竞争新格局。我国正处于家当晋升的关键时代,应充分把握新形>>>详细阅读
本文标题:开发一个Linux调试器(一):准备环境
地址:http://www.17bianji.com/lsqh/35868.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示