title: What is the best or proper way to allow debugging of generated code?
body: <p>For various reasons, in one project I generate executable code by means of generating AST from various source files the compiling that to bytecode (though the question could also work for cases where the bytecode is generated directly I guess).</p>
  <p>From some experimentation, it looks like the debugger more or less just uses the <code>lineno</code> information embedded in the AST alongside the filename passed to <code>compile</code> in order to provide a representation for the debugger's purposes, however this assumes the code being executed comes from a single on-disk file.</p>
  <p>That is not necessarily the case for my project, the executable code can be pieced together from multiple sources, and some or all of these sources may have been fetched over the network, or been retrieved from non-disk storage (e.g. database).</p>
  <p>And so my Y questions, which may be the wrong ones (hence the background):</p>
  <ul>
  <li>is it possible to provide a memory buffer of some sort, or is it necessary to generate a singular on-disk representation of the &quot;virtual source&quot;?</li>
  <li>how well would the debugger deal with jumping around between the different bits and pieces if the virtual source can't or should not be linearised<sup><sup>[0]</sup></sup></li>
  <li>and just in case, is the assumption of Python only supporting a single contiguous source file correct or can it actually be fed multiple sources somehow?</li>
  </ul>
  <p><sup><sup>[0]</sup></sup> for instance a <a href="https://en.wikipedia.org/wiki/Literate_programming" rel="nofollow noreferrer">web-style literate program</a> would be debugged in its original form, jumping between the code sections, not in the so-called &quot;tangled&quot; form</p>