GDB Printers: Unintialized variable in gdb

Ralf Habacker ralf.habacker at freenet.de
Fri Aug 27 07:52:11 BST 2021


Am 27.08.21 um 08:50 schrieb Ralf Habacker via Kde-finance-apps:
> 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())

For the record: The deference function is documentated at
https://sourceware.org/gdb/onlinedocs/gdb/Values-From-Inferior.html#Values-From-Inferior

Regards
Ralf


More information about the Kde-finance-apps mailing list