<div dir="ltr"><div><font color="#ff00ff">The gdb Xmethods support may help, from <a href="https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html">https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html</a></font><br></div><div><font color="#ff00ff"><br></font></div><div><font color="#000000">The problem is the inlined method to implement uses a lot of private classes, variables and method that has been optimised out, can can be expensive to reimplement </font></div><font color="#ff00ff"><div><font color="#ff00ff"><br></font></div><div><font color="#ff00ff"><br></font></div>(gdb) x 0<br>0x0: Cannot access memory at address 0x0<br><br>which can also be used by python</font><div><br></div><div>the variable sometimes may contain some data that is randomly assigned to it, so gdb just returns that </div><div><br></div><div><br></div><div>The SIGSENV segmentation fault happens when i try to call a method before the variable is actually initialised. </div><div>( this would also happen in raw gdb without printers). </div><div><br></div><div>there are two ways i thought of solving the problem </div><div><br></div><div>either i catch the segfault signal in python and return the method is not callable </div><div><br></div><div>or i make sure the variable is initialised before calling the method </div><div><br></div><div><br></div><div>if the case of the former, i am not sure how to catch a SIGSENV signal </div><div><br></div><div>i tried </div><div>`set unwindonsignal on`</div><div> <a href="https://sourceware.org/gdb/onlinedocs/gdb/Calling.html">https://sourceware.org/gdb/onlinedocs/gdb/Calling.html</a></div><div>and catch gdb error in the printers like this </div><div><br></div><div>```</div><div> try: </div><div> # gdb.parse_and_eval(call method here)</div><div> except gdb.error:</div><div> return "<not callable>"</div><div>``` </div><div>this works in gdb cli but not in an Ide as it still segfaults </div><div>(maybe it sets unwidowsignal off internall not sure ) </div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 24 Aug 2021 at 17:34, Ralf Habacker via Kde-finance-apps <<a href="mailto:kde-finance-apps@kde.org">kde-finance-apps@kde.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>Am 24.08.21 um 17:27 schrieb Da Viper
via Kde-finance-apps:<br>
</div>
<blockquote type="cite">
<div dir="auto">There is a QDateTime printer that requires
calling a method to get useful values.
<div dir="auto"><br>
</div>
<div dir="auto">The problem is when I call the method from gdb
the printer crashes because the variable does not exist yet
thus the method does not exist in memory.</div>
</div>
</blockquote>
<pre>The gdb Xmethods support may help, from <a href="https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html" target="_blank">https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html</a>
<em>Xmethods</em> are additional methods or replacements for existing
methods of a C<tt>++</tt> class. This feature is useful for those cases
where a method defined in C<tt>++</tt> source code could be inlined or
optimized out by the compiler, making it unavailable to <small>GDB</small>.
For such cases, one can define an xmethod to serve as a replacement
for the method defined in the C<tt>++</tt> source code. <small>GDB</small> will
then invoke the xmethod, instead of the C<tt>++</tt> method, to
evaluate expressions.</pre>
<blockquote type="cite">
<div dir="auto">
<div dir="auto"><br>
</div>
<div dir="auto">Is there a way to check if a variable has been
initialised ? <br>
</div>
</div>
</blockquote>
<p>In gdb access to invalid variables is catched<br>
</p>
<p>(gdb) x 0<br>
0x0: Cannot access memory at address 0x0</p>
<p>which can also be used by python<br>
</p>
<p>(gdb) python gdb.execute('x 0')<br>
Traceback (most recent call last):<br>
File "<string>", line 1, in <module><br>
gdb.MemoryError: Cannot access memory at address 0x0<br>
0x0: Error while executing Python code.</p>
<p>Wrapping this code with a try/catch block should do this, e.g.</p>
<p>(gdb) python<br>
>try:<br>
> gdb.execute('x 0')<br>
>except:<br>
> print('exception')<br>
>end<br>
0x0: exception<br>
</p>
<p>Regards</p>
<p>Ralf<br>
</p>
<p><br>
</p>
</div>
</blockquote></div>