GDB Printers: Unintialized variable in gdb
Ralf Habacker
ralf.habacker at freenet.de
Fri Aug 27 07:50:15 BST 2021
Am 24.08.21 um 17:27 schrieb Da Viper via Kde-finance-apps:
> But the Sigsegv exception is not a python exceptionÂ
>
> I tried checking if the address is null but it's a valid address.
>
> What I am try to mimick is something similar to the LLDB `SBValue.isValid()`
>
> sbValue is similar to gdb.Value but for lldb
>
The gdb counterpart is the class gdb.Value, which is returned by
gdb.parse_and_eval (expression)
Parse expression, which must be a string, as an expression in the
current language, evaluate it, and return the result as a gdb.Value.
https://sourceware.org/gdb/onlinedocs/gdb/Basic-Python.html
To see if there is another way I used the following testcase, which
defines the pointer `b`, but points to an undefined memory address.
$cat << EOF > test-uninit.cpp
#include <stdio.h>
int main()
{
int *a;
int *b = (int*)0x12334;
printf("%p %p\n", a, b);
}
EOF
$ gcc -o test-uninit test-uninit.cpp
$ cat << EOF > test-parse-and-eval.py
v = gdb.parse_and_eval('a')
print('a',v.dereference())
v = gdb.parse_and_eval('b')
#print('b',v.dereference())
try:
print('b',v.dereference())
except:
print('could not access')
EOF
$gdb test-uninit
(gdb)b 8
(gdb)r
(gdb)source test-parse-and-eval.py
1
*b could not access
That seems to work for me.
Regards
Ralf
More information about the Kde-finance-apps
mailing list