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

发布于 2024-11-14 19:02:30 字数 1304 浏览 3 评论 0原文

因此,我有这个使用 -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 工具找出导致这种未对齐访问的文件和代码行?

有什么意见吗?

So I have this executable, compiled with the -g options, that triggers loads of unaligned userspace access warnings.

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

The error message provides some information: the program counter and the instruction, but I don't know how to translate the PC into a file and line in my code.

I can sniff this as being in a loop performing some memory copying or something, since the address is very often the same.

So question: how can I find out what's the file and line of my code causing this unaligned access, using Linux tools?

Any input on that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2024-11-21 19:02:30

看一下 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 }

使用 gdb 编译它

gcc -Wall -ggdb3 g.c

会给出以下输出:

$ 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:6

Have a look at the addr2line utility

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.

A Simple c-example:

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

compile it using

gcc -Wall -ggdb3 g.c

gdb gives this output:

$ 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);

Using that address with addr2line:

$ addr2line 0x0000000000400538
/tmp/tmp.M0766CSHGm/g.c:6
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文