<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Am 24.08.21 um 17:27 schrieb Da Viper
via Kde-finance-apps:<br>
</div>
<blockquote type="cite"
cite="mid:CAEtKUfhf0034HQfQmcSG3qMb0RnDFH--Q2+hpnZq=mJm_Gm9eQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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 class="moz-txt-link-freetext" href="https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html">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"
cite="mid:CAEtKUfhf0034HQfQmcSG3qMb0RnDFH--Q2+hpnZq=mJm_Gm9eQ@mail.gmail.com">
<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>
</body>
</html>