-1

In Examine command GDB, x/10xw Address. Can I use a variable in place of repeat count, i.e can I use a variable in place of 10, like x/($var)xw Address?

This is how my .gdbinit looks like. I need to do some calculations and use the variable ( var3 )

define print_sn_list_hex

            set $var1 = $mcache->elem_size
            set $var2 = $mcache->blocking_factor
             set $var3 = ($var1) * ($var2) / 4
    x/$var3xw $sess # I want to pass a variable here 



   end

end

2 Answers2

1

Not directly, but you can use the gdb "eval" command to get this effect, or you can write a Python script to do nearly any kind of formatting that you would desire.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
0

Thank you very much Tom, eval command you mentioned above works perfectly. I was using older version of GDB, so it created problem inititally. its working perfectly fine now. my new code looks like :

define print_sn_list_hex

        set $var1 = $mcache->elem_size
        set $var2 = $mcache->blocking_factor
         set $var3 = ($var1) * ($var2) / 4
         eval "x/%dxw %p",$var3,$sess