当前位置: 首页 > news >正文

毕业设计做APP好还是网站商铺营销推广方案

毕业设计做APP好还是网站,商铺营销推广方案,做网站网上怎么挂公告,wordpress集成paypal〇、前言 终于来到令人激动的源代码 level 了,这里将会有一些很有意思的算法,来实现源代码级别的调试,这将会非常有趣。 一、使用 libelfin 库 我们不可能直接去读取整个 .debug info 段来进行设置,这是没有必要的,…

〇、前言

终于来到令人激动的源代码 level 了,这里将会有一些很有意思的算法,来实现源代码级别的调试,这将会非常有趣。

一、使用 libelfin 库

我们不可能直接去读取整个 .debug info 段来进行设置,这是没有必要的,可以使用现成的库。首先初始化 debugger 对象:

class debugger {
public:debugger (std::string prog_name, pid_t pid): m_prog_name{std::move(prog_name)}, m_pid{pid} {auto fd = open(m_prog_name.c_str(), O_RDONLY);m_elf = elf::elf{elf::create_mmap_loader(fd)};m_dwarf = dwarf::dwarf{dwarf::elf::create_loader(m_elf)};}//...private://...dwarf::dwarf m_dwarf;elf::elf m_elf;
};

不必太过关注这里函数的细节,只需要关注它们做了什么。事实上,m_dwarf、m_elf 和 文件名 m_prog_name 关联起来了,然后就交给它们进行处理了。我们还需要知道 load_addr,这非常重要,因为debuf info 只会提供静态的信息,load_addr 取决于运行时,因此得想办法在 /proc 中获取:

void Debugger::initialise_load_address() {if (m_elf.get_hdr().type == elf::et::dyn) {std::ifstream map("/proc/" + std::to_string(m_pid) + "/maps");//Read the first address from the filestd::string addr;std::getline(map, addr, '-');m_load_address = std::stoi(addr, 0, 16);}
}

二、获取信息

通过一个 pc 怎么获取函数名呢?注意这个 pc 是一个 offset addr,传参的时候一定要转换。思路很简单,首先遍历所有的 cu,然后判断 culow_pchigh_pc,如果在这个 cu 符合,那么就通过 cu 拿到 cu.rootcu.root 是一个根 die,通过它可以遍历所有的 die。之后再判断 dietag 是不是一个函数,如果是且包含 pc,那么就是我们要找的函数。实现如下:

dwarf::die Debugger::get_function_from_pc(std::intptr_t pc) {for (auto &cu : m_dwarf.compilation_units()) { // 循环遍历所有cuif (die_pc_range(cu.root()).contains(pc)) {for (const auto &die :cu.root()) { if (die.tag ==dwarf::DW_TAG::subprogram) { if (die_pc_range(die).contains(pc)) {return die;}}}}}throw std::out_of_range{"Cannot find function"};
}

接着通过 pc 来获取 line entry:

dwarf::line_table::iterator Debugger::get_line_entry_from_pc(uint64_t pc) {for (auto &cu : m_dwarf.compilation_units()) {if (die_pc_range(cu.root()).contains(pc)) {auto &lt = cu.get_line_table();auto it = lt.find_address(pc);if (it == lt.end()) {throw std::out_of_range{"Cannot find line entry"};}else {return it;}}}throw std::out_of_range{"Cannot find line entry"};
}

接着我们打印源代码。思路是通过 debug info 中的源代码路径和 line table 来获取,好消息是,我们不必做更多的底层实现:

void Debugger::print_source(const std::string& file_name, unsigned line, unsigned n_lines_context) {std::ifstream file {file_name};auto start_line = line <= n_lines_context ? 1 : line - n_lines_context;auto end_line = line + n_lines_context + (line < n_lines_context ? n_lines_context - line : 0) + 1;char c{};auto current_line = 1u;while (current_line != start_line && file.get(c)) {if (c == '\n') {++current_line;}}std::cout << (current_line==line ? "> " : "  ");while (current_line <= end_line && file.get(c)) {std::cout << c;if (c == '\n') {++current_line;std::cout << (current_line==line ? "> " : "  ");}}std::cout << std::endl;
}

三、测试

minidbg> break 0x555555555191
Set breakpoint at address 0x555555555191
minidbg> conti
Hit breakpoint at adsress 0x555555555191#include <iostream>int main() {
>   std::cerr << "hello,world0.\n";return 0;}

我们确实成功的打印出了源代码。上述基本的信息获取,基本思路就是对 DWARF 的理解,然后利用库函数接口获取我们想要的信息。

http://www.tj-hxxt.cn/news/54242.html

相关文章:

  • 长春建筑网站软文网站平台
  • 专业网站制作公司地址百度推广效果怎么样
  • 装饰设计网站模板海外域名
  • 网站没备案长沙seo推广
  • 个人可以做行业网站吗西安seo外包优化
  • 百度收录网站名seo数据监控平台
  • 用织梦模板做网站杭州网络优化公司排名
  • 上不了国外网站怎么做外贸十大网站管理系统
  • 南宁市网站开发建设seo排名优化软件免费
  • wordpress 菜单平铺深圳专业seo外包
  • 建设局网站查询个人信息360摄像头海澳門地区限制解除
  • 网络营销专员是干嘛的seo一般包括哪些内容
  • 做图片网站用什么程序关键词的作用
  • go语言做的网站广东seo快速排名
  • wordpress 文章的各种调用seo优化教程视频
  • 闵行营销型网站建设公司百度关键词搜索指数查询
  • 网站建设要写代码吗门户网站
  • 网站建设价值合肥关键词排名推广
  • 基于php房产网站开发四川游戏seo整站优化
  • 垦利县建设局网站搜索 引擎优化
  • 广西远伟网络科技有限公司seo的基础是什么
  • 做哪种网站流量上的快石家庄
  • 网站解除域名绑定seo优化靠谱吗
  • 1688外贸平台seo排名优化推广
  • 大连网站制作的公司哪家好网站优化提升排名
  • 网站哪里可以查到做ddos搭建网站多少钱
  • 做ebay需要的图片外链网站上海培训机构排名榜
  • 网络营销推广的核心是什么百色seo外包
  • 网站建设总结ppt软文营销写作技巧有哪些?
  • 中国机械加工网1717崇左seo