<div dir="auto"><div>Hello Charlie and thanks for the comments. I ended up by implementing my own Infodwrf unit. </div><div dir="auto"><br></div><div dir="auto">Matias<br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On 18 Jul 2017 11:48 p.m., "Karoly Balogh (Charlie/SGR)" <<a href="mailto:charlie@scenergy.dfmk.hu">charlie@scenergy.dfmk.hu</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<div class="quoted-text"><br>
On Mon, 17 Jul 2017, Matias Vara wrote:<br>
<br>
> Hello everyone, I am trying to port the code for backtrace, e.g.,<br>
> GetLineInfo(), to my freepascal kernel in order to print a backtrace<br>
> when an exception happens.<br>
<br>
</div>Slightly off topic, but make sure when you copy code from (or even study<br>
the source of) the RTL, that your resulting code is license compatible.<br>
<div class="quoted-text"><br>
> The drawback now is that I am not sure where the source is. I think it<br>
> is the unit lnfodwrf.pp however I am not sure.<br>
<br>
</div>The backtrace/stack traversal code itself is in system unit, see<br>
FPC_PushExceptObject and surrounding code. To print the frames collected<br>
there, the system unit will just use BackTraceStrFunc as implemented by<br>
various debuginfo units to print lineinfo strings based on information by<br>
the different debug/symbol formats.<br>
<br>
You just have to implement your own debug info parser and custom<br>
BackTraceStrFunc, then the RTL should handle the rest. You can check the<br>
various locations where BackTraceStrFunc is called in system unit for<br>
further reference.<br>
<div class="quoted-text"><br>
> From the code, it seems that this unit is opening the executable to get<br>
> the debug section, is this correct? is it not getting the name of the<br>
> symbols from memory? In my case, the debug symbols must be taken from<br>
> memory since there is no disk access.<br>
<br>
</div>The lnfodwrf unit just gets the symbol name for a given address, stored in<br>
DWARF debug info sections in an executable, and injects it's own<br>
BackTraceStrFunc in the RTL to return that.. The same with lineinfo unit<br>
for STABS debug info format, actually. Opening a file and loading it is<br>
not a requirement, as long as your tables are in the memory anyway. But<br>
normally these are not loaded by the executable loader of OSes, hence<br>
these units will load/parse them.<br>
<br>
If they're in memory in your case already, you can just skip the loading,<br>
and implement your own customized version of lnfodwrf unit, etc.<br>
<br>
BackTraceStrFunc is the key really, as it's quite universal. And the<br>
default implementation is quite simple, see SysBackTraceStr.<br>
<br>
Hope this was helpful,<br>
--<br>
Charlie<br>
______________________________<wbr>_________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.<wbr>org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">http://lists.freepascal.org/<wbr>cgi-bin/mailman/listinfo/fpc-<wbr>pascal</a></blockquote></div><br></div></div></div>