因此,我有这个使用-g选项编译的可执行文件,它会触发加载未对齐的用户空间访问警告。
Unaligned userspace access in "softtest" pid=1407 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x004148c2 ins=0x012e
Unaligned userspace access in "softtest" pid=1407 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1407 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x004148c2 ins=0x012e
Unaligned userspace access in "softtest" pid=1407 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x004148c2 ins=0x012e
Unaligned userspace access in "softtest" pid=1407 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1407 pc=0x0041515c ins=0x011e
Unaligned userspace access in "softtest" pid=1406 pc=0x004148c2 ins=0x012e错误消息提供了一些信息:程序计数器和指令,但我不知道如何将PC转换为代码中的文件和行。
我可以察觉到这是在一个循环中执行一些内存复制之类的操作,因为地址经常是相同的。
那么问题是:如何使用Linux工具找出导致这种未对齐访问的代码文件和代码行?
对此有什么意见吗?
发布于 2011-06-07 18:08:23
看一看addr2line实用程序
DESCRIPTION
addr2line translates addresses into file names and line numbers.
Given an address in an executable or an offset in a section of a
relocatable object, it uses the debugging information
to figure out which file name and line number are associated with it.一个简单的c-示例:
1 #include <stdio.h>
2
3 int main() {
4 int* a = 0;
5
6 printf("%d", *a);
7 return 0;
8 }使用以下命令编译它
gcc -Wall -ggdb3 g.cgdb给出以下输出:
$ gdb -q a.out
Reading symbols from /tmp/tmp.M0766CSHGm/a.out...done.
(gdb) r
Starting program: /tmp/tmp.M0766CSHGm/a.out
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400538 in main () at g.c:6
6 printf("%d", *a);将该地址与addr2line一起使用:
$ addr2line 0x0000000000400538
/tmp/tmp.M0766CSHGm/g.c:6https://stackoverflow.com/questions/6263663
复制相似问题