Difference between revisions of "Gecko:Debugging Tools"

From MozillaWiki
Jump to: navigation, search
(Frame Tree Dump)
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]

Revision as of 03:13, 4 April 2012

.gdbinit

bz's gdbinit

GDB pretty printers

JS-specific printers

General gecko printers

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

Chris Jones' handy ptarray command

Frame Tree Dump

<bz> for a frame dump, you can use the layout debugger, or... if you're in a debugger and want to examine the tree, you can do

def frametree
  call nsFrame::DumpFrameTree($arg0)
end


<bz> That should work when called on any nsIFrame to dump the tree it belongs to

Printing nsIAtoms

<bz> To print an nsIAtom, you see what concrete type it is using "set print object on", then cast it to that type, etc

<bz> if it's an nsStaticAtom:

 def satom
   p *((class nsStaticAtomWrapper*)$arg0)->mStaticAtom
 end

<bz> to be used as: satom content->Tag() or satom frame->GetType()

<bz> for nsGkAtoms it'll work great

Reflow Logs

See [Debugging Frame Reflow]