开发者

Investigate an unaligned userspace access with only the Program Counter and the executable

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 o开发者_如何学Gout what's the file and line of my code causing this unaligned access, using Linux tools?

Any input on that?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜