Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB - Accessing real and imaginary parts of a complex number

When debugging a program which uses (either C or C++), gdb displays complex numbers as _M_value = xxx + yyy*I (with a type of complex double).

While debugging, I need to print that number multiplied by a factor.

The following does not work:

print a * 8.0

I get Argument to arithmetic operation not a number or boolean.

Also, I cannot access the real and imaginary parts so that I can write a gdb macro to do the above. My current solution is to write a C function for manipulating complex values and arrays, and calling that function from gdb. Somehow, this just doesn't feel right.

like image 484
nimrodm Avatar asked Jan 03 '11 11:01

nimrodm


1 Answers

If you use the standard C++ complex template then complex::real() and complex::imaj() should work.

my2c

Note : Was a comment ^^

like image 190
neuro Avatar answered Nov 14 '22 22:11

neuro