English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 17 May 2019, 00:23   #1
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Debug: evaluate a variable built with vbcc

I'm working on the amiga assembly extension for visual studio code.
I've added a feature to step and stop on breakpoints in C code. So it's possible to debug C and ASM in the same editor.

I would like to add the possibility to evaluate a C variable.
Someone has a clue to achieve that ?

My simple program:
Code:
#include <stdio.h>

extern int mul_by_ten(short input);

int main()
{
    short i;
    char* s="My Text";

    for (i = 0; i < 10; i++)
    {
        printf("Line %d\n", i);
        printf("10 * %d = %d\n", i, mul_by_ten(i));
        printf("--------\n");
    }

    return 0;
}

 }
Disassembled
Code:
c14234: 48 e7 20 20               movem.l   d2/a2, -(a7)
c14238: 45 fa 00 7a               lea.l     $94(pc), a2
c1423c: 74 00                     moveq     #$0, d2
c1423e: 60 3e                     bra.b     $5e
c14240: 30 02                     move.w    d2, d0
c14242: 48 c0                     ext.l     d0
c14244: 2f 00                     move.l    d0, -(a7)
c14246: 48 7a 00 44               pea.l     $6c(pc)
c1424a: 4e b9 00 c1 4b 1c         jsr       $c14b1c.l
c14250: 30 02                     move.w    d2, d0
c14252: 48 c0                     ext.l     d0
c14254: 2f 00                     move.l    d0, -(a7)
c14256: 4e b9 00 c0 2f f0         jsr       $c02ff0.l
c1425c: 2f 00                     move.l    d0, -(a7)
c1425e: 30 02                     move.w    d2, d0
c14260: 48 c0                     ext.l     d0
c14262: 2f 00                     move.l    d0, -(a7)
c14264: 48 7a 00 32               pea.l     $78(pc)
c14268: 4e b9 00 c1 4b 1c         jsr       $c14b1c.l
c1426e: 48 7a 00 38               pea.l     $88(pc)
c14272: 4e b9 00 c1 42 bc         jsr       $c142bc.l
c14278: 4f ef 00 1c               lea.l     $1c(a7), a7
c1427c: 52 42                     addq.w    #$1, d2
c1427e: b4 7c 00 0a               cmp.w     #$a, d2
c14282: 6d bc                     blt.b     $20
c14284: 70 00                     moveq     #$0, d0
c14286: 4c df 04 04               movem.l   (a7)+, d2/a2
c1428a: 4e 75                     rts
How do I know that 'i' is in d2?
How do I know the address of 's'?
prb28 is offline  
Old 17 May 2019, 11:26   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
You don't know that without proper source level debugging information in the executable. vbcc can generate DWARF debug sections, which are not easy to parse but include everything you need to know.

DWARF doesn't work very well in hunk format executables though, and there are no debuggers which supports hunk format with DWARF, so we are enabling the -hunkdebug option by default for AmigaOS/68k. -hunkdebug generates SAS/C-style debug information, but only the LINE debug hunks, which I found documented in the Amiga Guru Book. Nothing else. Which means, with hunk format you are currently only getting the line numbers of the original source and nothing about variables.
phx is offline  
Old 17 May 2019, 11:44   #3
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
I’m creating the debugger behavior and the parser, so I can try it...
Do you think the DWARF / hunk format is enough stable to be used?
prb28 is offline  
Old 17 May 2019, 12:18   #4
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
you could also support gcc and its stab (old gcc) debug format^^
bebbo is offline  
Old 17 May 2019, 12:36   #5
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Gcc can be tricky to install on a windows with m68k support, I like the simplicity of vbcc.
But yes, it’s an alternative.
prb28 is offline  
Old 17 May 2019, 12:40   #6
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by prb28 View Post
Gcc can be tricky to install on a windows with m68k support, I like the simplicity of vbcc.
But yes, it’s an alternative.

try http://franke.ms/download/setup-amiga-gcc.exe
bebbo is offline  
Old 17 May 2019, 12:51   #7
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Both gcc and vbcc do DWARF2 and stabs.
Which one is the easiest to parse?
Are stabs and amiga hunk format compatible?
prb28 is offline  
Old 17 May 2019, 12:52   #8
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
@bebbo thanks, I’ll try this install.
prb28 is offline  
Old 17 May 2019, 12:57   #9
MartinW
Registered User
 
Join Date: Mar 2017
Location: Minehead / UK
Posts: 608
@bebbo - does your gcc6 have prebuilt setups for MacOS as well yet?

I use vbcc over gcc because it was far simpler to install in Windows, MacOS and AOS 3.1 / 3.9 (in case I want to do some quick hacking / testing on real hardware).

[EDIT] PS: Very nice to see attention to Amiga C code in the extension. I've been using it for C since I first saw it.
MartinW is offline  
Old 17 May 2019, 13:00   #10
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
I’v seen that stabs is obsolete on vbcc.
I’ll stick with DWARF2 but it should work with gcc.
prb28 is offline  
Old 17 May 2019, 13:45   #11
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
Quote:
Originally Posted by prb28 View Post
I’m creating the debugger behavior and the parser, so I can try it...
Do you think the DWARF / hunk format is enough stable to be used?
Never really tried that. Just remove the -hunkdebug option in the first two lines of your config file (make a copy of it and rename it) for a test. Then vbcc will emit DWARF sections.

I guess one problem will be that sections in a hunk-format executable are unnamed, so you cannot easily find them. And another problem is that they are loaded into memory. Oh, and DWARF uses pointers and relocations at odd addresses, which LoadSeg() doesn't support...

The best solution to bring something like DWARF to the Amiga would be to have the linker parse the debug sections and convert them into a more compatible format in a HUNK_DEBUG hunk. Nothing you do on an evening, though...
phx is offline  
Old 17 May 2019, 14:23   #12
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by MartinW View Post
@bebbo - does your gcc6 have prebuilt setups for MacOS as well yet?

off topic: look here: https://github.com/bebbo/amiga-gcc/releases


regarding hunk + dwarf2: is there a magic cookie at start of the debug hunk which can be used to recognize a dwarf2 debug hunk?
bebbo is offline  
Old 17 May 2019, 14:30   #13
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
That looks frightening!
Do vlink preserve the DWARF info in the exe?
prb28 is offline  
Old 17 May 2019, 16:12   #14
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
Quote:
Originally Posted by bebbo View Post
is there a magic cookie at start of the debug hunk which can be used to recognize a dwarf2 debug hunk?
Yes. The convention is to use a four-digit identifier as the first longword in a HUNK_DEBUG hunk. I don't have the Guru Book at hand, but from memory it is:
Code:
 0: HUNK_DEBUG
 4: hunk size in longwords
 8: section offset
12: four-digit ID (e.g. "LINE", for the SAS/C line-debug hunk)
The rest of the debug hunk can be used as you like. The section offset is always 0 in objects and patched by the linker when merging a section from several object files, which all have their own debug hunk. The debug hunks are not merged. There can be many of them for each section.

Quote:
Originally Posted by prb28 View Post
That looks frightening!
Indeed, be very frightened!
Some months ago I implemented DWARF2 and 3 support in vasm, to make it automatically generate DWARF sections for source level debugging. It was... challenging.

Quote:
Do vlink preserve the DWARF info in the exe?
Hunk-format objects have no concept of "debug sections", so they are stored as normal code or data sections with a ".debug_xyz" name. Currently vlink will just preserve those sections, which causes all sorts of problems.
phx is offline  
Old 17 May 2019, 16:44   #15
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by phx View Post
Yes. The convention is to use a four-digit identifier as the first longword in a HUNK_DEBUG hunk. I don't have the Guru Book at hand, but from memory it is:
Code:
 0: HUNK_DEBUG
 4: hunk size in longwords
 8: section offset
12: four-digit ID (e.g. "LINE", for the SAS/C line-debug hunk)
The rest of the debug hunk can be used as you like. The section offset is always 0 in objects and patched by the linker when merging a section from several object files, which all have their own debug hunk. The debug hunks are not merged. There can be many of them for each section.
...


* what is the 4 byte identifier used by vbcc/vlink/dwarf2?



* my gcc fork is using 2 debug sections per object file which are all together merged into one debug section for the binary. If I'd implement dwarf2 debug info for gcc/amiga hunk, I'd do it the same way -> one debug hunk per binary.
bebbo is offline  
Old 17 May 2019, 17:06   #16
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
@bebbo: which debug info format did you use in your gcc fork?
prb28 is offline  
Old 17 May 2019, 17:16   #17
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 681
Quote:
Originally Posted by prb28 View Post
@bebbo: which debug info format did you use in your gcc fork?

the .stab format since it was used back then and easier to re-implement. I changed the intermediate format (hunk objects) but the binary format should be identical to the one at that time.
bebbo is offline  
Old 17 May 2019, 22:30   #18
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
Quote:
Originally Posted by bebbo View Post
* what is the 4 byte identifier used by vbcc/vlink/dwarf2?
It doesn't exist yet. And whether I will ever implement it depends on the demand and if there will be any consumers (i.e. debuggers) for it.
phx is offline  
Old 18 May 2019, 12:16   #19
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Quote:
Originally Posted by MartinW View Post
[EDIT] PS: Very nice to see attention to Amiga C code in the extension. I've been using it for C since I first saw it.
Thanks, hope it helps some nostalgic developers


The preview of 0.17 version already has a step debugging in ASM showing the C source, but you have to step several times for one line of C code and you do not know the variables values.



I don't know if it is already useful as it is without variable value evaluation which is expected for a 'normal' debugger.


As I understand for amigaos there are some build environments for C as:
  • SAS/C
  • Barfly assembler package
  • StormC
  • etc.
They use as debug info:
  • Line debug of SAS/C
  • stabs (for gcc derivatives)
  • other custom formats
I imagine that StormC has a variable evaluation and BDebug (Barfly) not. Is that right ?


Now, for my needs, I've the choice of:
  • vbcc with an experimental DWARF2/Hunk format with possible issues during the execution
  • gcc fork from bebbo with stabs format

I'm reading some docs about these formats to see if it's not a too big investment.


Other alternatives can be the use of 'debug.lib' and listen to serial output, so the developer can send messages that are displayed in the debugger.


Do you have in mind some other alternative?
prb28 is offline  
Old 18 May 2019, 12:22   #20
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
@bebbo: maybe connecting to your gdbserver is a better way.
I'll try it with vscode.
prb28 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable injection? solarmon support.WinUAE 12 20 January 2019 12:05
VBCC problem with standard variable types Crank Coders. C/C++ 11 01 April 2018 19:31
Indy Last Crusade - Help me to DEBUG a Variable and change his value!! DjDiabolik support.Games 0 26 December 2016 03:27
vbcc bind a variable to a register iliak Coders. Asm / Hardware 6 31 July 2016 12:29
Evaluate a location on floppy disk by offset? (t/h/s) andreas Coders. General 11 23 June 2005 12:03

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:04.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10227 seconds with 13 queries