- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想创建程序执行的完整指令跟踪,以收集一些统计数据等。我首先尝试使用 linux 的 ptrace 功能逐步执行程序(使用教程 here)。这将创建两个进程,跟踪进程和调试器,它们通过信号进行通信。我每秒只能收到大约 16K 条指令(在 1.6GHz Atom 上),所以这对于任何重要的事情来说都太慢了。
我认为通过信号进行的进程间通信太慢,所以我尝试在与执行相同的进程中设置调试:设置陷阱标志,并创建信号处理程序。当使用软件中断进行系统调用时,应该保存陷阱标志,内核会使用它自己的标志——我是这么想的。但是我的程序不知何故被信号 SIGTRAP 杀死了。
这是我设置的:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
int cycle = 0;
void trapHandler(int signum) {
if (cycle % 262144 == 0) {
write(STDOUT_FILENO," trap\n",6);
}
cycle += 1;
}
void startTrace() {
// set up signal handler
signal(SIGTRAP, trapHandler);
// set trap flag
asm volatile("pushfl\n"
"orl $0x100, (%esp)\n"
"popfl\n"
);
}
void printRock() {
char* s = "Rock\n";
asm(
"movl $5, %%edx\n" // message length
"movl %0, %%ecx\n" // message to write
"movl $1, %%ebx\n" // file descriptor (stdout)
"movl $4, %%eax\n" // system call number (sys_write)
"int $0x80\n" // sycall
: // no output regs
: "r"(s) // input text
: "edx","ecx","ebx","eax"
);
}
int main() {
startTrace();
// some computation
int x = 0;
int i;
for (i = 0; i < 100000; i++) {
x += i*2;
}
printRock();
write(STDOUT_FILENO,"Paper\n",6);
write(STDOUT_FILENO,"Scissors\n",9);
}
运行时,这会给出:
trap
trap
trap
Rock
Paper
trap
Trace/breakpoint trap (core dumped)
所以现在我们每秒获得大约 250K 条指令,速度仍然很慢,但可以执行非平凡的指令。但是在两次写入调用之间似乎发生了核心转储。在 GDB 中,我们看到它发生的位置:
Dump of assembler code for function __kernel_vsyscall:
0xb76f3414 <+0>: push %ecx
0xb76f3415 <+1>: push %edx
0xb76f3416 <+2>: push %ebp
0xb76f3417 <+3>: mov %esp,%ebp
0xb76f3419 <+5>: sysenter
0xb76f341b <+7>: nop
0xb76f341c <+8>: nop
0xb76f341d <+9>: nop
0xb76f341e <+10>: nop
0xb76f341f <+11>: nop
0xb76f3420 <+12>: nop
0xb76f3421 <+13>: nop
0xb76f3422 <+14>: int $0x80
=> 0xb76f3424 <+16>: pop %ebp
0xb76f3425 <+17>: pop %edx
0xb76f3426 <+18>: pop %ecx
0xb76f3427 <+19>: ret
回溯:
Program terminated with signal SIGTRAP, Trace/breakpoint trap.
#0 0xb77c5424 in __kernel_vsyscall ()
#1 0xb76d0553 in __write_nocancel () at ../sysdeps/unix/syscall-template.S:81
#2 0x0804847d in trapHandler (signum=5) at count.c:8
#3 <signal handler called>
#4 0xb77c5424 in __kernel_vsyscall ()
#5 0xb76d0553 in __write_nocancel () at ../sysdeps/unix/syscall-template.S:81
#6 0x08048537 in main () at count.c:49
似乎通过 int 80
发生的系统调用很好,但是写调用以某种方式使用内核的 VIDSO/vsyscall 中断(我不知道这个功能,更详细地描述了 here )。这可能与使用 sysenter
而不是 int 80
有关,也许陷阱标志在进入内核时仍然存在。我不太明白递归 __kernel_vsyscall
调用是怎么回事。我也不明白为什么 __kernel_vsyscall
函数中有一个 int 80
调用。
有没有人建议发生了什么事,以及如何解决这个问题?也许可以禁用 VDSO/vsyscall?或者是否可以使用 int 80
而不是 sysenter
覆盖 __kernel_vsyscall
函数?
最佳答案
回答自己的问题。我没有弄清楚发生了什么或详细解释它,但我找到了一个解决方法:禁用 VDSO。这可以通过
sudo sysctl vm.vdso_enabled=0
有了这个,整个程序的单步执行就可以工作了,包括跨系统调用。免责声明:如果事情变糟,请不要怪我。
编辑:更新我的 Linux(32 位 x86)之后,这个错误不再发生。也许这是一个已修复的错误。
关于c - 尝试使用陷阱标志和陷阱信号处理程序单步执行程序,在 vsyscall 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27080741/
我有两个维度 DimFlag 和 DimPNL 以及一个事实表 FactAmount 。我正在寻找:当 pnl 是 stat(Is Stat=1) 时:sum (Actual x FlagId)对于
我试图弄清楚登录模块标志在 JAAS 中是如何工作的(使用 JBoss 5.1 EAP),我遇到了一个令人费解的情况,我希望有人能为我澄清一下。 对于背景,我的 login-config.xml 如下
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我正在通过 gradle 使用 doclet 运行 javadoc,当我运行 javadoc/doclet 任务时,我收到下一个错误: error - invalid flag: -doctitle
我尝试使用sqoop --where标志将特定的行从MySQL表导入到HDFS,但是结果不符合预期。 命令: sqoop import \ --connect "jdbc:mysql://XXXX
我有一个语言面板,其中有一个图像 (main-image),显示页面加载时的情况。我还有三个额外的图像,它们在页面加载时隐藏。 问题是当点击附加图像之一时如何切换主图像。我需要使用单击的 image
奇怪...在 StackOverflow 上有很多关于此 attr 的问题,但没有人回答我的以下问题: 我有一个span(仅作为示例),其中启用了ContentEditable。我只想保存更改的元素(
我正在使用 ChartJS 2.0 在 UI 上绘制图表。而且我能够呈现饼图。但我希望鼠标悬停时显示数据以及“%”符号。我如何追加 % 因此,如果在鼠标悬停时我得到 Rented: 93 我想看到 R
我使用的是 Servlet 3.0,我想用 HttpOnly 标志保护我的 cookie。我的 web.xml 是 true
我有一个简单的服务: public class TestService extends Service { final String LOG_TAG = "myLogs"; public void o
我正在尝试将 wget 与包含“#”符号的 url 一起使用。无论我做什么来逃避这个角色,它都不起作用。我用过\、' 和 "。但它们都不起作用。有人有什么建议吗? 谢谢! 最佳答案 如果您真的想让它有
我正在尝试创建一个数据库,但我不知道如何转义数据库名称中的 - 符号。 mysql> create database happy-face; 给我一个错误 mysql> create databa
我为我的计算机科学类(class)编写了一个程序,它读取一个文件并导入数据,然后只添加数字,但它似乎添加了一个额外的加号。 import java.io.*; //necessary for File
可能是个愚蠢的问题,但我怎样才能在与某些文本看到图像相同的行中获取图像(在本例中为标志)? 到目前为止我的 HTML 代码: FRA 最佳答案 试试这个: img { height:20px
我需要一些有关 clone() 系统调用的帮助。我试图将它与标志 CLONE_CHILD_CLEARTID 一起使用,但我看不到我指定为参数的字段值有任何变化。这是一个简单的代码: int the_c
查看 mySQL 转储时,我遇到了一些东西,想知道它们是什么。 我明白了: /*!50001 DROP TABLE IF EXISTS `xxx` */; flag 50001是什么意思,有什么意思的
是否可以传递任何 Java 编译器标志来告诉编译器不允许使用原始类型?也就是说,对于任何泛型类,让编译器强制使用参数化版本,否则抛出编译错误? 最佳答案 JDK7 (b38) 介绍 -Xlint:ra
[Flags] public enum MyEnum { None = 0, Setting1 = (1 GetAllEnums() where T : struct
我正在浏览 PackageManager API。我发现定义了以下常量: 1) GET_DISABLED_COMPONENTS 2) GET_DISABLED_UNTIL_USED_COMPONENT
我编写了一个 Go 程序来模拟按键操作。为此,我必须使用 cgo 和不同的 C 代码片段,具体取决于正在编译 Go 代码的操作系统。我编写的代码如下所示: package keyboard /* #i
我是一名优秀的程序员,十分优秀!