linux 使用ptrace函数时找不到头文件 .h 或者找不到某个宏的解决方法
例如:
#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h> /* For constants
ORIG_EAX etc */
int main()
{ pid_t child;
long orig_eax;
child = fork();
if(child == ) {
ptrace(PTRACE_TRACEME, , NULL, NULL);
execl("/bin/ls", "ls", NULL);
}
else {
wait(NULL);
orig_eax = ptrace(PTRACE_PEEKUSER,
child, * ORIG_EAX,
NULL);
printf("The child made a "
"system call %ld\n", orig_eax);
ptrace(PTRACE_CONT, child, NULL, NULL);
}
return ;
}
在linux的某些版本是运行不了,报错:找不到某个头文件或者某个宏。(上面的代码是基于i386,我试过了好几个linux的版本,还是运行出问题)
最后发现问题了。解决如下:
linux如何查找一个宏或者函数定义的位置:
以宏定义ORIG_EAX为例:
在终端输入
第一种方法:
find /usr/include/ -name *.h | xargs grep 'ORIG_EAX'
结果:
/usr/include/i386-linux-gnu/asm/ptrace-abi.h:#define ORIG_EAX 11 /usr/include/i386-linux-gnu/sys/reg.h:# define ORIG_EAX
第二种方法:
grep -nr ORIG_EAX /usr/include/
这种方法可以知道在第几行定义宏
结果:
/usr/include/i386-linux-gnu/asm/ptrace-abi.h::#define ORIG_EAX 11 /usr/include/i386-linux-gnu/sys/reg.h::# define ORIG_EAX
最后修改后,成功运行:
#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/reg.h> /* For constants
ORIG_EAX etc */
int main()
{ pid_t child;
long orig_eax;
child = fork();
if(child == ) {
ptrace(PTRACE_TRACEME, , NULL, NULL);
execl("/bin/ls", "ls", NULL);
}
else {
wait(NULL);
orig_eax = ptrace(PTRACE_PEEKUSER,
child, * ORIG_EAX,
NULL);
printf("The child made a "
"system call %ld\n", orig_eax);
ptrace(PTRACE_CONT, child, NULL, NULL);
}
return ;
}
运行结果:
The child made a system call
后面还有ls命令出现的目录清单
linux 使用ptrace函数时找不到头文件 .h 或者找不到某个宏的解决方法的更多相关文章
- Xshell连接linux(deepin)时提示ssh服务器拒绝了密码,请再试一次解决方法
用Xshell root连接时显示ssh服务器拒绝了密码,应该是应该是sshd的设置不允许root用户用密码远程登录 修改 /etc/ssh/sshd_config文件,注意,安装了openssh才会 ...
- IAR 编译时找不到头文件的解决方法
Fatal Error[Pe1696]: cannot open source file "x.h" 那是因为头文件路径没有找对 到报错的.c源文件 选中右键 选择options ...
- Cocoapods - pod install 成功后找不到头文件解决
问题描述:使用Cocoapods时,import 找不到头文件. 问题原因:这是因为还没设置头文件的目录. 解决办法:在项目的Target的里设置一下,添加cocoapods头文件目录:目录路径直接写 ...
- 编译C++,找不到头文件(fatal error: string: No such file or directory)
在androidproject中编译C++时,找不到头文件,报错例如以下: fatal error: string: No such file or directory 解决该问题须要在Android ...
- CodeBlocks "no such file or directory" 错误解决方案(创建类找不到头文件)
在CodeBlocks下,有时候需要自己定义类,当然就要添加相应的头文件,但添加进去的头文件明明包含在项目中了, 但编译时还是会报错:no such file or directory;这是为什么呢? ...
- #include <sys/socket.h>找不到头文件
ubuntu下socket编程涉及到头文件sys/socket.h 和sys/types.h.我是用的codeblocks编辑器,当我想查看socket,h头文件时编辑器提示找不到头文件. 我就想可能 ...
- 当Android工程中提示你找不到头文件,但你已经设置头文件路径了
虽然在Android.mk文件中,配置了LOCAL_C_INCLUDES路径,但是工程中的红色叉号一直提示找不到头文件 这时,你在工程树目录中展开Includes项,捣鼓捣鼓,重新build下,或许就 ...
- pod JONSKit.h MBProgress.h 找不到头文件,怎么办?
这时你看项目pod部分,多了JSONKit库.好了,第三方库就这么神奇的加进来. 头文件路径 那试试看使用JONSKit.h,在ViewController.m里引用下.找不到头文件,怎么办?还没设置 ...
- windows下vscode修复c++找不到头文件
因为原博客太长将部分内容分开 vscode找不到头文件的问题是由于windows下vscode默认的编译器是微软的MSVC(vs使用的编译器)的头文件路径 如果你没有安装vs肯定会因为找不到头文件而报 ...
随机推荐
- centos6 下用yum 安装 nginx
以下操作在Cento6.4 系统下实现 一.更新使用163的库 vi /etc/yum.repos.d/CentOS-Base.repo yum update [base] name=CentOS-$ ...
- Struts2+Spring4+Hibernate4整合超详细教程
Struts2.Spring4.Hibernate4整合 超详细教程 Struts2.Spring4.Hibernate4整合实例-下载 项目目的: 整合使用最新版本的三大框架(即Struts2.Sp ...
- python MySQLdb、socket与进线程
1 centos下 安装MySQLdb模块 a 首先需要先安装 setuptool b yum install -y mysql_devel 头文件 c yum install -y python_d ...
- V9 二次开发技术篇之 模型数据库
应V9粉丝的建议,本人今天讲一下 MVC中的M 数据库模型 首先 在 phpcms\model 建一个模型文件test_model.class.php <?phpdefined('IN_PHP ...
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...
- idHTTP最简洁的修改和取得Cookie例子
procedure TForm1.Button1Click(Sender: TObject); var HTTP: TidHTTP; html, s: string; i: integer; begi ...
- [LeetCode 112 113] - 路径和I & II (Path Sum I & II)
问题 给出一棵二叉树及一个和值,检查该树是否存在一条根到叶子的路径,该路径经过的所有节点值的和等于给出的和值. 例如, 给出以下二叉树及和值22: 5 / \ 4 8 ...
- CMake快速入门教程-实战
http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/ http://blog.csdn.net/dbzhang800/article/detai ...
- COJ 0979 WZJ的数据结构(负二十一)
WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...
- css实现居中的各种方法
css垂直居中有很多种方法,可以参考下这个网站