GDB Printers: Unintialized variable in gdb
Ralf Habacker
ralf.habacker at freenet.de
Tue Aug 24 17:34:42 BST 2021
Am 24.08.21 um 17:27 schrieb Da Viper via Kde-finance-apps:
> There is a QDateTime printer that requires calling a method to get
> useful values.
>
> 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.
The gdb Xmethods support may help, from https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html
/Xmethods/ are additional methods or replacements for existing
methods of a C++ class. This feature is useful for those cases
where a method defined in C++ source code could be inlined or
optimized out by the compiler, making it unavailable toGDB.
For such cases, one can define an xmethod to serve as a replacement
for the method defined in the C++ source code.GDB will
then invoke the xmethod, instead of the C++ method, to
evaluate expressions.
>
> Is there a way to check if a variable has been initialised ?
In gdb access to invalid variables is catched
(gdb) x 0
0x0: Cannot access memory at address 0x0
which can also be used by python
(gdb) python gdb.execute('x 0')
Traceback (most recent call last):
File "<string>", line 1, in <module>
gdb.MemoryError: Cannot access memory at address 0x0
0x0: Error while executing Python code.
Wrapping this code with a try/catch block should do this, e.g.
(gdb) python
>try:
> gdb.execute('x 0')
>except:
> print('exception')
>end
0x0: exception
Regards
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-finance-apps/attachments/20210824/5bd60c14/attachment.htm>
More information about the Kde-finance-apps
mailing list