dwarf debugging info
-
- Posts: 284
- Joined: Mar 07, 2018 13:59
- Location: Germany
dwarf debugging info
Hi all,
i keep failing to create an executable (test.exe) with "dwarf" debugging info in 32 bit with the default gas backend. When adding "-gen gcc" in 32 bit to the command tail the executable contains all what´s needed after compiling (gcc for 32 bit must be installed).
Reading the docs there is an assembler command switch " --gdwarf-2", so my commandline for fbc looks like this: "-g -Wa --gdwarf-2". Nevertheless a .stab and .stabstr section are added and "objdump --dwarf=info test.exe > dwarf.txt" doesn´t deliver all the data i get when compiling with "-gen gcc".
What must i do in order to get dwarf debug info when using the gas backened ? (What am i doing wrong ?). Or is it impossible ? (Can fbc 32 with gas backend only add stabs debug info ?)
Any help appreciated - thanks!
JK
i keep failing to create an executable (test.exe) with "dwarf" debugging info in 32 bit with the default gas backend. When adding "-gen gcc" in 32 bit to the command tail the executable contains all what´s needed after compiling (gcc for 32 bit must be installed).
Reading the docs there is an assembler command switch " --gdwarf-2", so my commandline for fbc looks like this: "-g -Wa --gdwarf-2". Nevertheless a .stab and .stabstr section are added and "objdump --dwarf=info test.exe > dwarf.txt" doesn´t deliver all the data i get when compiling with "-gen gcc".
What must i do in order to get dwarf debug info when using the gas backened ? (What am i doing wrong ?). Or is it impossible ? (Can fbc 32 with gas backend only add stabs debug info ?)
Any help appreciated - thanks!
JK
Re: dwarf debugging info
For what target ? Afaik for *nix dwarf should generally be fine (and almost mandatory for 64-bit)
Re: dwarf debugging info
afaik the gas backend always emits STABS debugging info (if it emits debug info at all) and doesn't support other formats (like DWARF). I also don't think that this could be changed by any command line options for the assembler, as the debugging info is already emitted in the assembler source (and GNU "as" would somehow have to convert it if you want a different format).
btw you can simply take a look at the generated assembly code of the gas backend and you'll see the STABS info.
btw you can simply take a look at the generated assembly code of the gas backend and you'll see the STABS info.
-
- Posts: 284
- Joined: Mar 07, 2018 13:59
- Location: Germany
Re: dwarf debugging info
My system is Windows and i´m compiling for Windows.
Stabs returns only 32 bit addresses, which is fine for 32 bit, but in 64 bit there could be problems assuming the upper 32 bit are always &H00000000.
Dwarf returns 32 bit addresses for 32 bit and 64 bit addresses for 64 bit, so no problem here, if it weren´t for gas backend. Of course i could always use "-gen gcc" for 32 bit, but i just wanted to know, if dwarf debug info is possible with gas too.
JK
Stabs returns only 32 bit addresses, which is fine for 32 bit, but in 64 bit there could be problems assuming the upper 32 bit are always &H00000000.
Dwarf returns 32 bit addresses for 32 bit and 64 bit addresses for 64 bit, so no problem here, if it weren´t for gas backend. Of course i could always use "-gen gcc" for 32 bit, but i just wanted to know, if dwarf debug info is possible with gas too.
JK
Re: dwarf debugging info
@Juergen
I'm a bit disappointed as I explained twice how it's working. ;-)
Gas is always used at the end (at least before the linker). What changed is the format of the debugging instructions it receives and handles.
bas --> FBC --> asm + stabs instructions --> GAS --> exe + stabs sections (32bit default)
bas --> FBC --> c + generic debugging data (line number) --> GCC --> asm + dwarf or stabs instructions --> GAS --> exe + stabs or dwarf sections
(32bit or 64bit with option gcc and according debug format selected)
It can be possible to get debug dwarf directly (bas to asm) by changing what FBC generates as debug instructions. But a big job without interest.
eg .loc 1 11 0 instead .stabn 68,0,1,.LM1-.LFBB1 in the asm code. + a lot of other things......
I hope it's clear now :-)
I'm a bit disappointed as I explained twice how it's working. ;-)
Gas is always used at the end (at least before the linker). What changed is the format of the debugging instructions it receives and handles.
bas --> FBC --> asm + stabs instructions --> GAS --> exe + stabs sections (32bit default)
bas --> FBC --> c + generic debugging data (line number) --> GCC --> asm + dwarf or stabs instructions --> GAS --> exe + stabs or dwarf sections
(32bit or 64bit with option gcc and according debug format selected)
It can be possible to get debug dwarf directly (bas to asm) by changing what FBC generates as debug instructions. But a big job without interest.
eg .loc 1 11 0 instead .stabn 68,0,1,.LM1-.LFBB1 in the asm code. + a lot of other things......
I hope it's clear now :-)
-
- Posts: 284
- Joined: Mar 07, 2018 13:59
- Location: Germany
Re: dwarf debugging info
As it seems, the --gdwarf-2 switch for gas works in that it adds line info, which can be retrieved by "objdump --dwarf=decodedline test.exe". Without this switch line info isn´t present in dwarf format.
But all other debug info about procedures, types, variables etc. is still missing despite of "--gdwarf-2". Did i miss something ?
JK
But all other debug info about procedures, types, variables etc. is still missing despite of "--gdwarf-2". Did i miss something ?
JK
-
- Posts: 284
- Joined: Mar 07, 2018 13:59
- Location: Germany
Re: dwarf debugging info
@Sarg,
So it is impossible to get sufficient dwarf debugging info in the resulting executable when using the gas backend in FreeBASIC! (That´s all i wanted to know)
It´s not a problem of gas itself, it´s a "problem" of fbc, which doesn´t add the necessary info for gas when creating code for the default 32 bit backend (.bas to .asm) . If you go the "c way" (.bas to .c) fbc does add the required dwarf info for both 32 and 64 bit.
Did i get this right ?
JK
So it is impossible to get sufficient dwarf debugging info in the resulting executable when using the gas backend in FreeBASIC! (That´s all i wanted to know)
It´s not a problem of gas itself, it´s a "problem" of fbc, which doesn´t add the necessary info for gas when creating code for the default 32 bit backend (.bas to .asm) . If you go the "c way" (.bas to .c) fbc does add the required dwarf info for both 32 and 64 bit.
Did i get this right ?
JK
Re: dwarf debugging info
Partially true :Juergen Kuehlwein wrote:If you go the "c way" (.bas to .c) fbc does add the required dwarf info for both 32 and 64 bit.
Did i get this right ?
fbc just adds instructions like this : #line 24 "dbg_test_stack_64.bas" to indicate the original line number and name of the .bas file.
The other information is added by gcc. So the variable names are those used in the c code. eg prm in basic becomes prm1s1 in c. And there are additionnal work variables..... etc.
Re: dwarf debugging info
@juergen
I though about the 64 bit issue with stabs. It can be easily fixed.
Just by a prog that reads the asm file with stabs data and writes a new one containing the same data but with 64bit adresses.
In the example/test below I changed some stabs lines and data can be retrieved in 2 special sections lolo1 and lolo2 (line number).
Address and offset are on 8 bytes.
Therefore it's possible to create an exe with all data necessary for debugging and no need of objdump.
There is just an additional step :
bas -->FBC --> c --> GCC --> asm --> " stabs addresses modifier" --> asm --> GAS --> exe
What do you think ?
Original
Modified
Original
Original
Modified
D:\laurent_divers\freebasic64bit>objdump -s -j .lolo1 "dbg_test_stack_64_stabs.exe"
dbg_test_stack_64_stabs.exe: file format pei-x86-64
Contents of section .lolo1:
D:\laurent_divers\freebasic64bit>objdump -s -j .lolo2 "dbg_test_stack_64_stabs.exe"
dbg_test_stack_64_stabs.exe: file format pei-x86-64
Contents of section .lolo2:
I though about the 64 bit issue with stabs. It can be easily fixed.
Just by a prog that reads the asm file with stabs data and writes a new one containing the same data but with 64bit adresses.
In the example/test below I changed some stabs lines and data can be retrieved in 2 special sections lolo1 and lolo2 (line number).
Address and offset are on 8 bytes.
Therefore it's possible to create an exe with all data necessary for debugging and no need of objdump.
There is just an additional step :
bas -->FBC --> c --> GCC --> asm --> " stabs addresses modifier" --> asm --> GAS --> exe
What do you think ?
Original
Code: Select all
.stabs "D:/laurent_divers/freebasic64bit/",100,0,2,.Ltext0
.text
.Ltext0:
.stabs "gcc2_compiled.",60,0,0,0
Code: Select all
.Ltext0:
section .lolo1,"dr"
.ascii "D:/laurent_divers/freebasic64bit/,100,0,2"
.quad .Ltext0
.ascii "gcc2_compiled.,60,0,0,0"
.quad 0
Code: Select all
.stabs "vr$1:(0,33)",128,0,40,-8
.stabs "SHARED_VAR4$:S(0,35)",40,0,40,SHARED_VAR4$
.stabs "SHARED_VAR5$:S(0,35)",40,0,40,SHARED_VAR5$
Code: Select all
.section .lolo1,"dr"
.ascii "vr$1:(0,33),128,0,40"
.quad -8
.ascii "SHARED_VAR4$:S(0,35),40,0,40"
.quad SHARED_VAR4$
.ascii "SHARED_VAR5$:S(0,35),40,0,40"
.quad SHARED_VAR5$
.text
Code: Select all
.stabn 68,0,1,.LM1-.LFBB1
Code: Select all
.section .lolo2,"dr"
.ascii ".stabn 68,0,1"
.quad .LM1-.LFBB1
D:\laurent_divers\freebasic64bit>objdump -s -j .lolo1 "dbg_test_stack_64_stabs.exe"
dbg_test_stack_64_stabs.exe: file format pei-x86-64
Contents of section .lolo1:
Code: Select all
409000 443a2f6c 61757265 6e745f64 69766572 D:/laurent_diver
409010 732f6672 65656261 73696336 34626974 s/freebasic64bit
409020 2f2c3130 302c302c 32d01540 00000000 /,100,0,2..@....
409030 00676363 325f636f 6d70696c 65642e2c .gcc2_compiled.,
409040 36302c30 2c302c30 00000000 00000000 60,0,0,0........
409050 76722431 3a28302c 3333292c 3132382c vr$1:(0,33),128,
409060 302c3430 f8ffffff ffffffff 53484152 0,40........SHAR
409070 45445f56 41523424 3a532830 2c333529 ED_VAR4$:S(0,35)
409080 2c34302c 302c3430 a05cc747 00000000 ,40,0,40.\.G....
409090 53484152 45445f56 41523524 3a532830 SHARED_VAR5$:S(0
4090a0 2c333529 2c34302c 302c3430 c0e09e5f ,35),40,0,40..._
4090b0 00000000
D:\laurent_divers\freebasic64bit>objdump -s -j .lolo2 "dbg_test_stack_64_stabs.exe"
dbg_test_stack_64_stabs.exe: file format pei-x86-64
Contents of section .lolo2:
Code: Select all
40a000 2e737461 626e0936 382c302c 31000000 .stabn.68,0,1...
40a010 00000000 002e7374 61626e09 36382c30 ......stabn.68,0
40a020 2c311a00 00000000 00000000 ,1..........
-
- Posts: 284
- Joined: Mar 07, 2018 13:59
- Location: Germany
Re: dwarf debugging info
OK - looks good, but let´s discuss this in private again
JK
JK