bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Global Metadata Missing - FIX FOUND #624

Closed Scaremonger closed 1 year ago

Scaremonger commented 1 year ago

Reported on Discord by @mingw Fix found and posted on Discord by me.

Bug Report

This simple test program shows the issue.

Framework BRL.Reflection
Import BRL.StandardIO
DebugStop

Type Test
    Global Tx1:Int { test="hello!" }
    Field Tx2:Int { testing="Hi" }
End Type

Local tid:TTypeId=TTypeId.ForName( "Test" )

Local g:TGlobal=tid.FindGlobal( "Tx1" )
Local f:TField=tid.FindField( "Tx2" )

Print g.name()
Print g.MetaData( "test" )

Print f.name()
Print f.MetaData( "testing" )

Expected Behavior

Should print both Field metadata and Global metadata

Executing:Reflection-Global-Metadata
Tx1
hello!
Tx2
Hi

Process complete

Actual Behavior

Only prints Field metadata

Executing:Reflection-Global-Metadata
Tx1

Tx2
Hi

Process complete

Solution

If you edit ctranslator.bmx in the src/bcc folder and search for Method EmitGlobalDebugScope, then update the line that emits TransDebugScopeType() so it includes metadata like this:

    Method EmitGlobalDebugScope( decl:TGlobalDecl, scopeIndex:Int )
        Emit "{"
        Emit "BBDEBUGDECL_GLOBAL,"
        Emit Enquote(decl.ident) + ","

        ' ## METADATA FIX ##
        'Emit Enquote(TransDebugScopeType(decl.ty)) + ","
        Emit Enquote(TransDebugScopeType(decl.ty) + TransDebugMetaData(decl.metadata.metadataString)) + ","
        ' ## METADATA FIX ##

        If decl.IsThreaded() Then
            Emit ".var_address=0"
            decl.scopeIndex = scopeIndex
        Else
            Emit ".var_address=(void*)&" + decl.munged
        End If
        Emit "},"
    End Method

Environment

LInux, x64 bcc[ng] Release Version 0.136