English Amiga Board


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

 
 
Thread Tools
Old 11 April 2021, 16:48   #1
carrion
Registered User
 
carrion's Avatar
 
Join Date: Dec 2016
Location: Warsaw area
Posts: 152
vbcc memwatch, debugging, symbols

Hi All!
Im switching to VBCC (from Blitz Basic and some simple Asm code) with some good results so far (thanks to other thread about vbcc and Photon's tutorials in C). I'm using vbcc + fs-uae on Mac and on this setup I want to use internal fs-uae debugger which looks that has all I need.
I have some questions regarding debugging:
- how do I enable memwatch?
- how to use Zf Zl Zc commands of the fs-uae debugger?
- how to generate symbols and how to import them to debugger?
- can fs-uae import all needed symbols automatically or it needs to be loaded manually by me?

that's for a start
I plan to develop mostly in C with some ASM functions here and there. So far I can't find options or tutorials how to generate symbols from C source file and use them in debugger.
Thanks In Advance for any help/hints
carrion is offline  
Old 11 April 2021, 23:05   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by carrion View Post
- how do I enable memwatch?
I never used FS-UAE, but may be the 'w' command.

Quote:
- how to use Zf Zl Zc commands of the fs-uae debugger?
Never heard of those.

Quote:
- how to generate symbols and how to import them to debugger?
- can fs-uae import all needed symbols automatically or it needs to be loaded manually by me?
I have no idea. There might be an interface in WinUAE, which is used by prb28's great VSCode Amiga Assembly environment:
https://github.com/prb28/vscode-amiga-assembly
But this doesn't help you with your Mac, of course. Maybe you find more answers in an FS-UAE support thread?

vasm and vbcc can generate standard Amiga symbol hunks and LINE debug hunks (for source level debugging), like SAS/C and other Amiga compilers.

Just as a hint: if you want to set a breakpoint for UAE in your source, insert a very rare opcode which has no effect, like
exg a7,a7
. Then let the UAE debugger break on this opcode:
fi cf4f
. You can also do that in C:
__asm("\tdc.w\t$cf4f");
phx is offline  
Old 12 April 2021, 09:04   #3
carrion
Registered User
 
carrion's Avatar
 
Join Date: Dec 2016
Location: Warsaw area
Posts: 152
thanks for quick reply.
I actually started using this __asm("\tdc.w\t$cf4f"); trick.
but what I want to do is a way to show memory or disassemble parts of my program with commands like:

Code:
m pictureData
m copperList
or

Code:
d myProcedure
instead of using addresses that these symbols point to.

Im not sure I understand the debug hunk and/orthe line debug options.
am I supposed to get additional files with symbols debug data after compiling. Or is it combined within the compiled files?
carrion is offline  
Old 12 April 2021, 17:45   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
When your program doesn't kill the OS I would try a real AmigaOS debugger, which offers all you need. I'm using BDebug (Aminet, comes with the Barfly assembler), which handles symbols and source-level debugging just fine. But then you have to compile the source on the same Amiga to get useful source-path information. Symbols will work in any case.

Quote:
Originally Posted by carrion View Post
Im not sure I understand the debug hunk and/orthe line debug options.
Compile with -g to get both.

Quote:
am I supposed to get additional files with symbols debug data after compiling. Or is it combined within the compiled files?
Symbols and other debug information are always included in the generated executable. There are special hunk-types, like HUNK_SYMBOL or HUNK_DEBUG for that purpose, which are part of the file but not loaded into memory when the program is executed. The debugger has to read that extra information from the file.
phx is offline  
Old 12 April 2021, 19:00   #5
carrion
Registered User
 
carrion's Avatar
 
Join Date: Dec 2016
Location: Warsaw area
Posts: 152
I use -g option for vc.
So you say I should see the symbols in debugger? hmmm. will try in a moment.

but I did some tests before with and without -g and file size after compiling is the same. Is this ok? I assumed that -g option is not working.
So assuming I have all the symbols in the compiled file is my approach possible to show parts of memory with "m" command and using symbol names like mentioned before?
Code:
m copperList
carrion is offline  
Old 13 April 2021, 00:47   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by carrion View Post
but I did some tests before with and without -g and file size after compiling is the same. Is this ok?
No. The file size must differ. Otherwise your configuration is broken. Example:
Code:
frank@nerthus cat helloamiga.c
#include <proto/dos.h>
int main()
{
  BPTR out = Output();
  Write(out,"Hello World\n",12);
  return 0;
}
frank@nerthus vc +aos68k -o helloamiga helloamiga.c
frank@nerthus ll helloamiga
-rwxr-xr-x  1 frank  users  1240 Apr 13 00:29 helloamiga
frank@nerthus vc +aos68k -g -o helloamiga helloamiga.c
frank@nerthus ll helloamiga
-rwxr-xr-x  1 frank  users  1884 Apr 13 00:29 helloamiga
Quote:
I assumed that -g option is not working.
-g is an option of the "vc" frontend, which skips the "-ldnodb" line from your config file (aos68k in this case). In my config file it is
-ldnodb=-s -Rshort
, which are options passed to vlink meaning: strip all symbols (-s) and use short relocs, when possible (-Rshort). These are not present when calling "vc" with "-g" option.

You can check that by compiling with -v (verbose). Without -g, vlink is called with -s and -Rshort:

Code:
frank@nerthus vc +aos68k -o helloamiga helloamiga.c -v
vc frontend for vbcc (c) in 1995-2020 by Volker Barthelmann
vbccm68k -quiet -hunkdebug "helloamiga.c" -o= "/tmp/tmp.0.asm"  -O=1 -I$VBCC/targets/m68k-amigaos/include -I/usr/local/vbcc/sdk/NDK_3.9/include_h
vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 "/tmp/tmp.0.asm" -o "/tmp/tmp.0.o"
vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib -mrel $VBCC/targets/m68k-amigaos/lib/startup.o "/tmp/tmp.0.o"   -s -Rshort -L$VBCC/targets/m68k-amigaos/lib -lvc -o helloamiga
rm -f "/tmp/tmp.0.asm"
rm -f "/tmp/tmp.0.o"
When compiling with -g these options are missing, and the executables become larger because of the debugging symbols:
Code:
frank@nerthus vc +aos68k -g -o helloamiga helloamiga.c -v
vc frontend for vbcc (c) in 1995-2020 by Volker Barthelmann
vbccm68k -quiet -hunkdebug "helloamiga.c" -o= "/tmp/tmp.0.asm" -g  -O=1 -I$VBCC/targets/m68k-amigaos/include -I/usr/local/vbcc/sdk/NDK_3.9/include_h
vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 "/tmp/tmp.0.asm" -o "/tmp/tmp.0.o"
vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib -mrel $VBCC/targets/m68k-amigaos/lib/startup.o "/tmp/tmp.0.o"   -L$VBCC/targets/m68k-amigaos/lib -lvc -o helloamiga
rm -f "/tmp/tmp.0.asm"
rm -f "/tmp/tmp.0.o"
Quote:
So assuming I have all the symbols in the compiled file is my approach possible to show parts of memory with "m" command and using symbol names like mentioned before?
Code:
m copperList
Theoretically yes. Depends on the debugger. Some have other commands than "m", or use a GUI. I'm not talking about the UAE-internal debugger. I don't know how this would work. Maybe Toni or Frode would know, but I doubt that they read this thread.
Note: Also remember when referencing C-symbols in a debugger or from an assembler program you have to add a leading underscore: _copperList.
phx is offline  
Old 13 April 2021, 10:50   #7
carrion
Registered User
 
carrion's Avatar
 
Join Date: Dec 2016
Location: Warsaw area
Posts: 152
ah yes... -s option was used in my vlink commnandline from makefile.
thanks for a hint!

so now I can see the symbols in the file and after loading it into BDebug I can also move around by using symbols. and yes... _coperList is right way to use the C symbols in BDebug

I have to get used to Debug for now before I figure out how to setup this in internal debugger of fs-uae. I will ask on proper thread now. I think I've found one.

Thanks a lot for help!
carrion is offline  
Old 14 April 2021, 16:34   #8
nyteshade
Registered User
 
Join Date: Mar 2020
Location: Boulder Creek / USA
Posts: 43
Coming from sas/c does anybody know if vbcc has the following like sas/c?

- auto open libraries
- a function that executes when the program starts
- a function that executes before the program exits

Sorry for being off topic
nyteshade is offline  
Old 17 April 2021, 11:43   #9
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by nyteshade View Post
- auto open libraries
Yes. Link with -lauto (or -lautos for small data).

Quote:
- a function that executes when the program starts
Yes. These functions must have the name
_INIT_<pri>_<name>
. Where <pri> is a priority between 1 and 9. 1 is called first. <name> is an optional function name. For example the clib-stdio is initialized on startup within
void _INIT_2_stdio(void)
. If you need stdio in your constructor, don't use a priority < 3. Library auto-open functions have a default priority of 5.

Quote:
- a function that executes before the program exits
See above. But functions are called
_EXIT_<pri>_<name>
. Destructor functions are called in reverse order (priority 9 first). They are called after the registered ISO-C atexit-functions.
phx 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
UAE debugger updates (executable debugging, segment tracking, symbols and more) Toni Wilen support.WinUAE 171 02 December 2023 15:49
Debugging vbcc code tolkien Coders. C/C++ 5 14 February 2015 06:45
Memwatch functions in Action Replay III don't work in WinUAE Galahad/FLT support.WinUAE 12 11 May 2014 13:42
Memwatch+Arcadia thor support.WinUAE 4 28 December 2013 17:28
Winuae - (debugger) Memwatch Problem barny support.WinUAE 2 03 October 2005 12:30

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 16:37.

Top

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