Source correlation using assembly Listing in C ++

Analysis of a core dump in a retail assembly often requires correlation of objdumpany particular module and source. Usually, correlation from the dump of the assembly with the source becomes a pain if the function is fully involved. Today I tried to create assembly listingone specific module (with a compilation option -S), expecting me to see a source of alternation with an assembly or some correlation. Unfortunately, the list was not friendly enough to correlate, so I was wondering

  • Given a core dump from which I can determine the location of the crash
  • objdumpfailed module. Listing assembly by recompiling
  • with option -S.

Is it possible to make a one-to-one correspondence with the source?

As an example, I see the assembly list as

.LBE7923:
        .loc 2 4863 0
        movq    %rdi, %r14
        movl    %esi, %r12d
        movl    696(%rsp), %r15d
        movq    704(%rsp), %rbp
.LBB7924:
        .loc 2 4880 0
        testq   %rdx, %rdx
        je      .L2680
.LVL2123:
        testl   %ecx, %ecx
        jle     .L2680
        movslq  %ecx,%rax
        .loc 2 4882 0
        testl   %r15d, %r15d
        .loc 2 4880 0
        leaq    (%rax,%rax,4), %rax
        leaq    -40(%rdx,%rax,8), %rdx
        movq    %rdx, 64(%rsp)

but could not understand how to interpret type labels .LVL2123and type directives.loc 2 4863 0

Note As you can see from the answers, reading through the assembly source and intuitively defining a pattern based on characters (such as function calls, branches, a return statement) is what I usually do. I do not deny that this will not work, but when the function is fully used, reading pages in the Assembly listing is a pain, and often you find yourself in a list that rarely matches either because the functions in which the optimizers are inserted or are simply threw the code at their discretion. I have a feeling how effectiveValgrind Windows WinDBG , -, . , . , , , , , , .loc . , , , , - Windows Mini-, WinDBG Linux Coredumps. , , , .

+5
3

?

A: , . ( ) , , , .


, , . ,

.LBB7924:
        .loc 2 4880 0
        testq   %rdx, %rdx
        je      .L2680

, %rdx , 4880. , , , %rdx.

.LVL2123:
        testl   %ecx, %ecx
        jle     .L2680

, , , , , %rdx %ecx . :

if (a && b) {

, , :

if (!a || !b) {

...

- , , , , . , , - , , , %rdx : - ? , , , .

!

+4

.loc - , . # 4863, 4880 .. ( 4880 , ). .loc , , . :

.loc <file> <line> <column>
+4

, - .

, . , , foo() open(), ioctl(), read(), , , foo. ( dump-on linux, ltrace strace)

, , , . - . , , , , .

, , , , , .

+1

All Articles