Gemini 3 answer:
Based on the src/compiler/hbcmplib.c source code and the existing Harbour architecture, here is a proposal for the hb_HrbDoFromBuf implementation.
This solution addresses your need to lazily write the source file to disk only when the debugger is active, preserving the performance benefits of in-memory compilation (HB_CompileFromBuf) while ensuring ALTD() and breakpoints work correctly.
Proposed ImplementationYou can implement hb_HrbDoFromBuf as a wrapper that checks the debugger state before executing the HRB.
/* * Proposed helper function: hb_HrbDoFromBufhb_vmIsDebug(): This is the critical check. By calling this (or checking hb_stackBase()->pDebugInfo if the function isn't public), you ensure the file is only written when the debugger is attached and listening. In production (Release builds) or when the debugger is off, this returns false, skipping the hb_fs* calls completely.
hb_fsCreate / hb_fsWriteLarge: These are the native Harbour file system APIs. Using hb_fsWriteLarge ensures safe handling of large source files (bigger than 32KB/64KB).
Virtual Filename: The cFileName passed here must match the one provided to HB_CompileFromBuf( ..., cVirtualFileName ). This links the in-memory debug symbols to the physical file we just created.
You also mentioned an API to "get the source" (like hb_ProcFileBuffer). This is architecturally cleaner because it avoids disk I/O entirely.
Instead of writing to disk, you could implement a Debugger Source Provider:
Proposal: hb_dbgSetSourceProvider( HB_BOOL (*callback)( const char * cName, char ** cBuf, HB_SIZE * nLen ) )
Mechanism: When the debugger hits an ALTD() and needs to display virtual_code.prg, it calls this callback. Your application checks its in-memory map, finds the buffer for virtual_code.prg, and returns it directly to the debugger.
Benefit: This makes the "Virtual File" truly virtual. The debugger reads directly from RAM, eliminating the need for hb_HrbDoFromBuf to write temporary files.
The hb_HrbDoFromBuf function effectively patches the gap between HB_CompileFromBuf and the file-based debugger. By wrapping the file write in a hb_vmIsDebug() check, you satisfy the requirement for zero-overhead in normal execution while ensuring seamless debugging when needed.

--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-devel/e97f9da4-8bdd-4e2b-be98-669043aa0199n%40googlegroups.com.