lostfox
lostfox

Reputation: 9

Ada listing files.... what are the right compiler in GNAT to get them to come out

I am used to getting nice listing files from C code where I can see lovely source code intertwined with opcodes and hex offsets for debugging as seen here: List File In C (.LST) List File In C (.LST)

And the -S directive gets me the assembler code only from g++ for Ada.... but I can't seem to get it to give up the good stuff so I can debug a nasty elaboration crash.

Any thoughts on the GNAT compiler switches to send in?

Upvotes: 1

Views: 322

Answers (2)

Jeffrey R. Carter
Jeffrey R. Carter

Reputation: 3358

You might want to look at the section on debugging control in the top-secret GNAT documentation, especially the -gnatG switch.

Upvotes: 2

DeeDee
DeeDee

Reputation: 5941

Maybe this helps. The next command generates something similar to what you refer to:

$ gnatmake -g main.adb -cargs -Wa,-adhln > main.lst

The -cargs (a so-called mode switch) causes gnatmake to pass the subsequent arguments to the compiler. The compiler subsequently passes the -adhln switches to the assembler (see here). But you might as wel use objdump -d -S main.o to see the assembly/source code after build.

main.adb

with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
begin
   Put_Line ("Hello, world!");
end Main;

output (main.lst)

   1                    .file   "main.adb"
   2                    .text
   3                .Ltext0:
   4                    .section    .rodata
   5                .LC1:
   6 0000 48656C6C      .ascii  "Hello, world!"
   6      6F2C2077 
   6      6F726C64 
   6      21
   7 000d 000000        .align 8
   8                .LC0:
   9 0010 01000000      .long   1
  10 0014 0D000000      .long   13
  11                    .text
  12                    .align 2
  13                    .globl  _ada_main
  15                _ada_main:
  16                .LFB1:
  17                    .file 1 "main.adb"
   1:main.adb      **** with Ada.Text_IO; use Ada.Text_IO;
   2:main.adb      **** 
   3:main.adb      **** procedure Main is
  18                    .loc 1 3 1
  19                    .cfi_startproc
  20 0000 55            pushq   %rbp
  21                    .cfi_def_cfa_offset 16
  22                    .cfi_offset 6, -16
  23 0001 4889E5        movq    %rsp, %rbp
  24                    .cfi_def_cfa_register 6
  25 0004 53            pushq   %rbx
  26 0005 4883EC08      subq    $8, %rsp
  27                    .cfi_offset 3, -24
  28                .LBB2:
   4:main.adb      **** begin
   5:main.adb      ****    Put_Line ("Hello, world!");
  29                    .loc 1 5 4
  30 0009 B8000000      movl    $.LC1, %eax
  30      00
  31 000e BA000000      movl    $.LC0, %edx
  31      00
  32 0013 4889C1        movq    %rax, %rcx
  33 0016 4889D3        movq    %rdx, %rbx
  34 0019 4889D0        movq    %rdx, %rax
  35 001c 4889CF        movq    %rcx, %rdi
  36 001f 4889C6        movq    %rax, %rsi
  37 0022 E8000000      call    ada__text_io__put_line__2
  37      00
  38                .LBE2:
   6:main.adb      **** end Main;
  39                    .loc 1 6 5
  40 0027 4883C408      addq    $8, %rsp
  41 002b 5B            popq    %rbx
  42 002c 5D            popq    %rbp
  43                    .cfi_def_cfa 7, 8
  44 002d C3            ret
  45                    .cfi_endproc
  46                .LFE1:
  48                .Letext0:

Upvotes: 2

Related Questions