Bug 960899 - Add debug function and lldb command to print frame state symbolically. r=dbaron

This commit is contained in:
Cameron McCormack 2014-01-18 18:08:22 +11:00
parent 5e56e874e4
commit 9e9c239e34
12 changed files with 135 additions and 0 deletions

View File

@ -63,6 +63,7 @@ UNIFIED_SOURCES += [
'nsFrame.cpp',
'nsFrameList.cpp',
'nsFrameSetFrame.cpp',
'nsFrameState.cpp',
'nsFrameUtil.cpp',
'nsGfxScrollFrame.cpp',
'nsHTMLCanvasFrame.cpp',

View File

@ -35,6 +35,12 @@ NS_DECLARE_FRAME_PROPERTY(FontSizeInflationProperty, nullptr)
NS_IMPL_FRAMEARENA_HELPERS(nsBulletFrame)
#ifdef DEBUG
NS_QUERYFRAME_HEAD(nsBulletFrame)
NS_QUERYFRAME_ENTRY(nsBulletFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsFrame)
#endif
nsBulletFrame::~nsBulletFrame()
{
}

View File

@ -40,6 +40,10 @@ private:
class nsBulletFrame : public nsFrame {
public:
NS_DECL_FRAMEARENA_HELPERS
#ifdef DEBUG
NS_DECL_QUERYFRAME_TARGET(nsBulletFrame)
NS_DECL_QUERYFRAME
#endif
nsBulletFrame(nsStyleContext* aContext)
: nsFrame(aContext)

View File

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* constants for frame state bits and a type to store them in a uint64_t */
#include "nsFrameState.h"
#include "nsBlockFrame.h"
#include "nsBoxFrame.h"
#include "nsBulletFrame.h"
#include "nsGfxScrollFrame.h"
#include "nsIFrame.h"
#include "nsISVGChildFrame.h"
#include "nsImageFrame.h"
#include "nsInlineFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsSVGContainerFrame.h"
#include "nsTableCellFrame.h"
#include "nsTableRowFrame.h"
#include "nsTableRowGroupFrame.h"
#include "nsTextFrame.h"
namespace mozilla {
#ifdef DEBUG
nsCString
GetFrameState(nsIFrame* aFrame)
{
nsCString result;
nsAutoTArray<const char*,3> groups;
nsFrameState state = aFrame->GetStateBits();
if (state == nsFrameState(0)) {
result.AssignLiteral("0");
return result;
}
#define FRAME_STATE_GROUP(name_, class_) \
{ \
class_* frame = do_QueryFrame(aFrame); \
if (frame && (groups.IsEmpty() || strcmp(groups.LastElement(), #name_))) {\
groups.AppendElement(#name_); \
} \
}
#define FRAME_STATE_BIT(group_, value_, name_) \
if ((state & NS_FRAME_STATE_BIT(value_)) && groups.Contains(#group_)) { \
if (!result.IsEmpty()) { \
result.Insert(" | ", 0); \
} \
result.Insert(#name_, 0); \
state = state & ~NS_FRAME_STATE_BIT(value_); \
}
#include "nsFrameStateBits.h"
#undef FRAME_STATE_GROUP
#undef FRAME_STATE_BIT
if (state) {
result.AppendPrintf(" | 0x%0llx", state);
}
return result;
}
void
PrintFrameState(nsIFrame* aFrame)
{
printf("%s\n", GetFrameState(aFrame).get());
}
#endif
} // namespace mozilla

View File

@ -63,4 +63,11 @@ inline nsFrameState& operator^=(nsFrameState& aLeft, nsFrameState aRight)
#define NS_FRAME_IMPL_RESERVED nsFrameState(0xF0000000FFF00000)
#define NS_FRAME_RESERVED ~NS_FRAME_IMPL_RESERVED
namespace mozilla {
#ifdef DEBUG
nsCString GetFrameState(nsIFrame* aFrame);
void PrintFrameState(nsIFrame* aFrame);
#endif
}
#endif /* nsFrameState_h_ */

View File

@ -30,6 +30,11 @@
which group the bit belongs to, value_ is the bit number (0..63),
and name_ is the name of the frame state bit constant.
Note that if you add a new frame state group, you'll need to #include
the header for its frame classes in nsFrameState.cpp and, if they don't
already, add nsQueryFrame implementations (which can be DEBUG-only) to
the frame classes.
******/
#ifndef FRAME_STATE_GROUP

View File

@ -26,6 +26,12 @@ NS_NewPlaceholderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
NS_IMPL_FRAMEARENA_HELPERS(nsPlaceholderFrame)
#ifdef DEBUG
NS_QUERYFRAME_HEAD(nsPlaceholderFrame)
NS_QUERYFRAME_ENTRY(nsPlaceholderFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsFrame)
#endif
/* virtual */ nsSize
nsPlaceholderFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
{

View File

@ -54,6 +54,10 @@ nsIFrame* NS_NewPlaceholderFrame(nsIPresShell* aPresShell,
class nsPlaceholderFrame MOZ_FINAL : public nsFrame {
public:
NS_DECL_FRAMEARENA_HELPERS
#ifdef DEBUG
NS_DECL_QUERYFRAME_TARGET(nsPlaceholderFrame)
NS_DECL_QUERYFRAME
#endif
/**
* Create a new placeholder frame. aTypeBit must be one of the

View File

@ -104,6 +104,12 @@ NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
NS_IMPL_FRAMEARENA_HELPERS(nsBoxFrame)
#ifdef DEBUG
NS_QUERYFRAME_HEAD(nsBoxFrame)
NS_QUERYFRAME_ENTRY(nsBoxFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
#endif
nsBoxFrame::nsBoxFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext,
bool aIsRoot,

View File

@ -32,6 +32,10 @@ class nsBoxFrame : public nsContainerFrame
{
public:
NS_DECL_FRAMEARENA_HELPERS
#ifdef DEBUG
NS_DECL_QUERYFRAME_TARGET(nsBoxFrame)
NS_DECL_QUERYFRAME
#endif
friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext,

View File

@ -84,6 +84,19 @@ called with a smart pointer like nsRefPtr or nsCOMPtr.
11
* pstate EXPR
Shows the frame state bits (using their symbolic names) of a given frame.
EXPR is an expression that is evaluated, and must be an nsIFrame*.
(lldb) p this
(nsTextFrame *) $1 = 0x000000011f470b10
(lldb) p/x mState
(nsFrameState) $2 = 0x0000004080604000
(lldb) pstate this
TEXT_HAS_NONCOLLAPSED_CHARACTERS | TEXT_END_OF_LINE | TEXT_START_OF_LINE | NS_FRAME_PAINTED_THEBES | NS_FRAME_INDEPENDENT_SELECTION
* ptag EXPR
Shows the DOM tag name of a node. EXPR is an expression that is

View File

@ -8,8 +8,13 @@ def frametreelimited(debugger, command, result, dict):
"""Dumps the subtree of a frame tree rooted at the given nsIFrame*."""
debugger.HandleCommand('expr (' + command + ')->DumpFrameTreeLimited()')
def pstate(debugger, command, result, dict):
"""Displays a frame's state bits symbolically."""
debugger.HandleCommand('expr mozilla::PrintFrameState(' + command + ')')
def init(debugger):
debugger.HandleCommand('command script add -f lldbutils.layout.frametree frametree')
debugger.HandleCommand('command script add -f lldbutils.layout.frametreelimited frametreelimited')
debugger.HandleCommand('command alias ft frametree')
debugger.HandleCommand('command alias ftl frametreelimited')
debugger.HandleCommand('command script add -f lldbutils.layout.pstate pstate');