Menu

Gdb user defined macros

vasek
2008-02-22
2012-09-15
  • vasek

    vasek - 2008-02-22

    Hi all,
    I started using gdb recently and wrote the following macros for it.
    It defines macros dm, dme, and dv. Example of use:
    (gdb) dm A
    dm A
    [1.000000,-0.500000,]
    [1.000000,0.000000,]

    Perhaps someone will find it useful. If there is a better way, please let me know, its my very first day with gdb.

    Vasek

    file gdb_itpp:

    This file defines handy gdb macros for printing out ITPP types

    To use it, add this line to your ~/.gdbinit :

    source gdb_itpp

    define dm
    set $i=0

    set $M = $arg0
    set $rs = $M.no_rows
    set $col = $M.no_cols

    while $i < $rs
    set $j=0
    printf "["
    while $j< $col
    printf "%f,", $M.data[$j*$col+$i]

    set $j++
    end
    printf "]"
    printf "\n"
    set $i++
    end
    end

    define dme
    set $i=0

    set $M = $arg0
    set $rs = $M.no_rows
    set $col = $M.no_cols

    while $i < $rs
    set $j=0
    printf "["
    while $j< $col
    printf "%e,", $M.data[$j*$col+$i]

    set $j++
    end
    printf "]"
    printf "\n"
    set $i++
    end
    end

    define dv
    print $arg0.data[0]@($arg0.datasize)
    end

     
    • vasek

      vasek - 2008-03-13

      Hi Adam,
      in the end, I did not used "print" but "output" which has some automatic for showing different types. See feature request.
      Now, the macros work even with complex numbers, though the output does not look very nice. I did not find a way how to tell gdb how to display std::complex in a better way.

      Best,
      Vasek

       
      • Adam Piątyszek

        Adam Piątyszek - 2008-03-13

        Unfortunately, the not built-in type "bin" causes problems. I tried to display some bmat contents and it looked like this:
        (gdb) dm cc_punct_mat
        [{b = 1 '\001'} ]
        [{b = 1 '\001'} ]

        Besides, dv does not insert the line break at the end:
        (gdb) dv cc_gen
        {369, 491}(gdb)

        I have not tested all combinations yet, but I think that the previous version (with "print") worked a little bit better.

        /Adam

         
  • hanhnga

    hanhnga - 2009-11-12

    Hi,

    Has anyone tested the debug mode in MSVC? How can we monitor the values of
    elements of a vec (mat) variable?

    Thanks in advance.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.