0

Sorry for my bad English.

My workflow:

  1. I write simple program for gnu asm (GAS) test_c.s:

        .intel_syntax noprefix
        .globl my_string
        .data
    my_string:
        .ascii "Hello, world!\0"    
        .text
        .globl main
    main:
        push rbp
        mov rbp, rsp
        sub rsp, 32
    
        lea rcx, my_string
        call printf
    
        add rsp, 32
        pop rbp
        ret
    
  2. Compile asm-source with debug symbols:

    gcc -g test_c.s
    
  3. Debug a.exe in GDB:

    gdb a -q
    Reading symbols from C:\a.exe...done.
    (gdb) start
    Temporary breakpoint 1 at 0x4014e4: file test_c.s, line 14.
    Starting program: C:\a.exe
    [New Thread 3948.0x45e4]
    
    Temporary breakpoint 1, main () at test_c.s:14
    14              sub     rsp, 32
    (gdb) whatis my_string
    type = <data variable, no debug info>  <-------------------- why?
    (gdb) info variables
    All defined variables:
    ...
    Non-debugging symbols:
    0x0000000000403000  __data_start__
    0x0000000000403000  __mingw_winmain_nShowCmd
    0x0000000000403010  my_string  <-------------------- why?
    ....
    

    Why 'my_string' is 'no debug info'-variable? How can I recognize, that 'my_string' is user defined variable? Some gcc-flags or gas-directives?

P.S.: The file test_c.s listed above is generated by gcc from simple c application test_c.c:

    #include<stdio.h>

    char my_string[] = "Hello, world!";

    int main(void)
    {
        printf(my_string);
    }

    gcc test_c.c -S -masm=intel

I try to debug this C-application and get expected result:

    gcc -g test_c.c
    gdb a -q
    Reading symbols from C:\a.exe...done.
    (gdb) start
    Temporary breakpoint 1 at 0x4014ed: file test_c.c, line 7.
    Starting program: C:\a.exe
    [New Thread 11616.0x1688]

    Temporary breakpoint 1, main () at test_c.c:7
    7           printf(my_string);
    (gdb) whatis my_string
    type = char [18] <-------------------- OK
    (gdb) info variables
    ...
    File test_c.c:
    char my_string[18]; <-------------------- OK
    ...

The problem is that I need for debug information related to the GAS-source, not C

P.S.S.: MinGW-builds x64 v.4.8.1

1 Answer 1

0

The reason is simple: you should have generated the asm file from the c file with debugging enabled, that is gcc test_c.c -S -masm=intel -g, to have the compiler emit the required information. If you do that, you will notice a section named .debug_info in your asm source, which, unfortunately, isn't user friendly.

Sign up to request clarification or add additional context in comments.

6 Comments

Is there a workaround? Can I add some minimal debug-information about the type of the my_string for GDB?
Of course you can add the same kind of debug info that the compiler does, but it's tedious and you have to know the format (which is dwarf2 in this case I think).
@Jester Is there a way to (from a regular .s source code GAS), only using as and ld (in other words, not using gcc) to generate debugging symbols (and also being able to list the source code) for gdb?
You have to insert the debugging info into the assembly source by hand. From there, yes, as and ld will suffice.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.