首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅使用Program计数器和可执行文件调查未对齐的用户空间访问

仅使用Program计数器和可执行文件调查未对齐的用户空间访问
EN

Stack Overflow用户
提问于 2011-06-07 18:05:18
回答 1查看 1.9K关注 0票数 1

因此,我有这个使用-g选项编译的可执行文件,它会触发加载未对齐的用户空间访问警告。

代码语言:javascript
复制
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工具找出导致这种未对齐访问的代码文件和代码行?

对此有什么意见吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-07 18:08:23

看一看addr2line实用程序

代码语言:javascript
复制
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-示例:

代码语言:javascript
复制
1 #include <stdio.h>
2 
3 int main() {
4     int* a = 0;
5 
6     printf("%d", *a);
7     return 0;
8 }

使用以下命令编译它

代码语言:javascript
复制
gcc -Wall -ggdb3 g.c

gdb给出以下输出:

代码语言:javascript
复制
$ 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一起使用:

代码语言:javascript
复制
$ addr2line 0x0000000000400538
/tmp/tmp.M0766CSHGm/g.c:6
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6263663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档