flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Programming Language Design > getting DEBUG info from fasmg ?

Author
Thread Post new topic Reply to topic
jmg



Joined: 18 Sep 2016
Posts: 62
getting DEBUG info from fasmg ?
I can find some mention of DEBUG output from fasm, but nothing for fasmg.

To usefully operate an in circuit debug, you do need some Debug info.

This might be Intel OMF, ELF or some other format.
A good ASCII-format debug example, is the SDCC .CDB file, designed for C, but a subset can be used for ASM operation.
http://sdcc.sourceforge.net/mediawiki/index.php/CDB_File_Format

In the simplest form, you need SourceFile:LineNumber to AbsCodeAdr mapping
(SourceFile should be include-file capable)
and Const or VariableName to Code or DataAddress mapping.

Additions like Type tags and endian information can speed watch-allocate, if the debugger also supports that.

Are there any examples of how to generate Debug info, from fasmg ?
Post 19 Sep 2016, 00:17
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6305
Location: Kraków, Poland
Since with fasmg any output format is generated by macros, the debug info appropriate for given format also has to be generated by these macros. I imagine that a variant of "proc" macro written to supplement ELF or COFF formatting macros could generate the debug info records in a right format for given output. The ELF formatter that comes with fasmg examples is currently limited to options compatible with fasm's built-in formatter, but these macros can be easily extended. The COFF formatting macros do not yet exist, but I plan to include at least basic fasm-compatible variant in the examples.

When a debug info format needs to be written as a separate file, the auxiliary output files would come in handy, but I still haven't decided how should they work in fasmg. Thus currently the only auxiliary output is to stdout with "display" directive (that's what the simple listing macro does).

For example, the following macro would list all the symbols defined with "label":

Code:
macro label? name
        label name
        display 'Symbol ',`name,' defined in ',__FILE__
        repeat 1,l:__LINE__
                display '[',`l,']'
        end repeat
        display ' with value '
        disphex name,8
        display 13,10
end macro

macro disphex number*,digits:8
        repeat digits
                digit = ((numbershr ((%%-%shl 2)) and 0Fh
                if digit < 10
                        display '0'+digit
                else
                        display 'A'+digit-10
                end if
        end repeat
end macro

Doing the same for symbols defined with "struc" syntax is more problematic, because in fasmg "struc" has no access to the textual representation of its "." label. I'm still considering if it requires some language extension... The workaround is to intercept all lines with "macro ?" (this has to be done anyway when more complete debug info needs to be generated, with full listing etc.).

This is just a basic example, as "disphex" will only display addresses that are plain numbers. When an address contains some variable terms (like in ELF output where the addresses are relative to sections/symbols) special handling is needed. The appropriate debug info generators need to be adapted and weaved into the macros that comprise the given framework (x86 ELF output, for example).
Post 19 Sep 2016, 07:37
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62
Thanks.
Thanks, so it is still work in progress...
If you need info on the OMF51, that can be found here
http://plit.de/asem-51/omfspec.htm

I think many debug downloads can only support OMF51 _or_ Hex, which makes simplest OMF51 for ASM, slightly more complex, as you need to include
a) Symbol Segments & address info, for VAR watch
b) Source line to absolute code info, for Break / Step, across various files.
c) Binary code, for download.
Post 19 Sep 2016, 08:57
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6305
Location: Kraków, Poland
I'm certainly not going to write all the macro packages myself (I still have the AVX macros and COFF output to write and even this may take long time, as I don't it as much myself), so it depends if there are people that would like to work on some specific macro package. And the basic fasmg package is going to contain only elementary examples anyway.

Current list of projects is listed in dedicated thread, but it does not include some works in progress. For instance, shoorick is working on a larger package that focuses on various 8-bit processors and microcontrollers with BIN/HEX output and Akeo is working on EBC assembler for UEFI.

If you'd like to contribute in some way, I'm always willing to help with technical details of how to achieve various things with fasmg - in fact, my focus is now more on advising and writing supplementary documentation that on implementing new things. I know that I'm never going to achieve much by working on this alone, therefore I feel that my time spent on tutoring and advising others may actually be better spent than the time used to write new macros myself. Thus you will find that I often provide small snippets that demonstrate some idea, but do not handle all the corner cases. That's because I prefer to make a simplified sample that is quick to write and relatively easy to understand. But I usually try to add notes that explain where it lacks and how can it be extended to become a "real thing".
Post 19 Sep 2016, 09:40
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6305
Location: Kraków, Poland

Tomasz Grysztar wrote:
Doing the same for symbols defined with "struc" syntax is more problematic, because in fasmg "struc" has no access to the textual representation of its "." label. I'm still considering if it requires some language extension...

I have found a syntax that I like and implemented an additional variant of "struc" definition that allows to declare parameter that should contain the exact text that was used to define label.
Using this new extension I prepared an example that displays values of all symbols defined with struc-like constructions (this includes labels defined with ":" and variables defined with "=" or "equ"):

Code:
struc (label? definition&
        label definition
        display 'Symbol ',`label,' defined in ',__FILE__
        repeat 1,l:__LINE__ 
                display '[',`l,']' 
        end repeat 
        display ' with value ' 
        disphex .,8
        display 13,10 
end struc

macro disphex number*,digits:8 
        repeat digits 
                digit = ((numbershr ((%%-%shl 2)) and 0Fh 
                if digit < 10 
                        display '0'+digit 
                else 
                        display 'A'+digit-10 
                end if 
        end repeat 
end macro

The name displayed is the exact text that was used to define symbol and it tries to display the value as a hexadecimal number even though some symbols may have values that cannot be presented this way. This would require a lot of tweaking to adapt to any specific situation, but the kind of tweaking needed highly depends on the framework it would have to operate in.
Post 21 Sep 2016, 14:31
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62

Tomasz Grysztar wrote:
The name displayed is the exact text that was used to define symbol and it tries to display the value as a hexadecimal number even though some symbols may have values that cannot be presented this way.


Extract of Symbol and Value/Address in hex is a good start, but some debuggers also need the memory segment.

When you watch a variable, Name and Address are part of the info, the memory area is also needed, (in HLL also a Type, and Endian info )

Some debuggers do allow user over-ride of memory area & type, but that is patchy, and they tend to forget such changes on the next session.

I'll try to add some example map/report files, created from Debug files + Source files.


Description: DEB for Mod51
Download
Filename: Mod51_ManyMOD_DEB.txt
Filesize: 38.77 KB
Downloaded: 27 Time(s)

Post 22 Sep 2016, 22:06
View user's profile Send private message Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62
and another one


Description: DEB for SDCC OMF51
Download
Filename: blink2_deb.txt
Filesize: 11.57 KB
Downloaded: 27 Time(s)

Post 22 Sep 2016, 22:08
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6305
Location: Kraków, Poland
As I said, this macro would require tweaking to adapt to displaying addresses that are not a plain numbers. While it could be modified to display any linear polynomial in general, this may not be useful for specific purposes, since you may need something fitting to a selected type of output and macro framework.

The structure and meaning of the addresses may vary wildly in general. In my introductory document* I show on simple examples how to mark the area of a label (like instructions memory or data memory) by adding a plain variable term to the base address. The same method can be used by some formats to generate relocations (PE/ELF in x86 examples do it like that). When the frame uses multiple numbered segments, a setting like:

Code:
element segment?
org segment*7C0h + 0

may be used, and this would be a two-dimensional value to display. In some cases polynomials with even more terms may occur in the address of a label - in case of x86 with relocatable format an address may contain a term for relocatable base and terms for registers, where the latter ones may have coefficients larger than 1. In EBC support I recently discussed with Akeo we tried an option of implementing label addresses within structures that contained a term counting natural words (something like "12*natural + 24"), this is again a two-dimensional addressing that could have another term for relocation base, and so on.

Thus the examples I provide show just some basic ideas how to tackle the problem, but any actual implementation needs to also take into consideration specific features of macro framework and output format that these macros implement.

* Note that this document is not concluded and it is still slowly growing as I try to discuss more and more problems and use cases there.
Post 23 Sep 2016, 06:11
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.