Gecko:Debugging Tools: Difference between revisions

no edit summary
No edit summary
Line 10: Line 10:


== Printing arrays ==
== Printing arrays ==
define ptarray
        if $argc == 0
                help ptarray
        else
                set $size = $arg0.mHdr->mLength
                set $capacity = $arg0.mHdr->mCapacity
                set $size_max = $size - 1
                set $elts = $arg0.Elements()
        end
        if $argc == 1
                set $i = 0
                while $i < $size
                        printf "elem[%u]: ", $i
                        p *($elts + $i)
                        set $i++
                end
        end
        if $argc == 2
                set $idx = $arg1
                if $idx < 0 || $idx > $size_max
                        printf "idx1, idx2 are not in acceptable range: [0..%u].\n", $size_max
                else
                        printf "elem[%u]: ", $idx
                        p *($elts + $idx)
                end
        end
        if $argc == 3
          set $start_idx = $arg1
          set $stop_idx = $arg2
          if $start_idx > $stop_idx
            set $tmp_idx = $start_idx
            set $start_idx = $stop_idx
            set $stop_idx = $tmp_idx
          end
          if $start_idx < 0 || $stop_idx < 0 || $start_idx > $size_max || $stop_idx > $size_max
            printf "idx1, idx2 are not in acceptable range: [0..%u].\n", $size_max
          else
            set $i = $start_idx
                while $i <= $stop_idx
                        printf "elem[%u]: ", $i
                        p *($elts + $i)
                        set $i++
                end
          end
        end
        if $argc > 0
                printf "nsTArray length = %u\n", $size
                printf "nsTArray capacity = %u\n", $capacity
                printf "Element "
                whatis *$elts
        end
end


[http://blog.mozilla.com/cjones/2010/04/30/print-nstarrays-in-gdb/ Chris Jones' handy ptarray command]
[http://blog.mozilla.com/cjones/2010/04/30/print-nstarrays-in-gdb/ Chris Jones' handy ptarray command]
Confirmed users
657

edits