Gecko:Debugging Tools: Difference between revisions

→‎Frame Tree Dump: add link to a page with documentation on layout debugger
(bz's notes on frame and reflow logs)
 
(→‎Frame Tree Dump: add link to a page with documentation on layout debugger)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== .gdbinit ==
[http://web.mit.edu/bzbarsky/www/gdbinit bz's gdbinit]
== GDB pretty printers ==
[http://hg.mozilla.org/users/jblandy_mozilla.com/archer-mozilla/ JS-specific printers]
[http://hg.mozilla.org/users/josh_joshmatthews.net/archer-mozilla/ 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
[http://blog.mozilla.com/cjones/2010/04/30/print-nstarrays-in-gdb/ Chris Jones' handy ptarray command]
== Frame Tree Dump ==
== 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
<bz> for a frame dump, you can use the [https://developer.mozilla.org/en-US/docs/Mozilla/Debugging/Layout_Debugger layout debugger], or... if you're in a debugger and want to examine the tree, you can do


  def frametree
  def frametree
   set $r = ($arg0)->PresContext()->GetPresShell()->GetRootFrame()
   call nsFrame::DumpFrameTree($arg0)
  if ($r)
    call ((class nsIFrameDebug*)(class ViewportFrame*)$r)->List(stderr, 2)
  end
  end
  end


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


== Printing nsIAtoms ==
def pa
  set $atom = $arg0
  if (sizeof(*((&*$atom)->mString)) == 2)
    pu (&*$atom)->mString
  end
end


== Reflow Logs ==
== Reflow Logs ==


See [[http://www.mozilla.org/newlayout/doc/frame_reflow_debug.html Debugging Frame Reflow]]
See [[http://www.mozilla.org/newlayout/doc/frame_reflow_debug.html Debugging Frame Reflow]]
== Printing strings ==
# Define a "ps" command to display subclasses of nsAC?String.  Note that
# this assumes strings as of Gecko 1.9 (well, and probably a few
# releases before that as well); going back far enough will get you
# to string classes that this function doesn't work for.
def ps
  set $str = $arg0
  if (sizeof(*$str.mData) == 1 && ($str.mFlags & 1) != 0)
    print $str.mData
  else
    pu $str.mData $str.mLength
  end
end
# Define a "pu" command to display PRUnichar * strings (100 chars max)
# Also allows an optional argument for how many chars to print as long as
# it's less than 100.
def pu
  set $uni = $arg0
  if $argc == 2
    set $limit = $arg1
    if $limit > 100
      set $limit = 100
    end
  else
    set $limit = 100
  end
  # scratch array with space for 100 chars plus null terminator.  Make
  # sure to not use ' ' as the char so this copy/pastes well.
  set $scratch = "____________________________________________________________________________________________________"
  set $i = 0
  set $scratch_idx = 0
  while (*$uni && $i++ < $limit)
    if (*$uni < 0x80)
      set $scratch[$scratch_idx++] = *(char*)$uni++
    else
      if ($scratch_idx > 0)
set $scratch[$scratch_idx] = '\0'
print $scratch
set $scratch_idx = 0
      end
      print /x *(short*)$uni++
    end
  end
  if ($scratch_idx > 0)
    set $scratch[$scratch_idx] = '\0'
    print $scratch
  end
end
== Dumping the JS Stack ==
def js
  call DumpJSStack()
end
Confirmed users
489

edits