Bug 831307, add additional logging. r=cjones, a=blocking-tef+.
authorBen Turner <bent.mozilla@gmail.com>
Wed, 23 Jan 2013 16:02:52 -0800
changeset 118286 ae48617d7ff6ea00b7e010fae8bf939a78ef02a7
parent 118285 d04a8081ae0dfb14b97f1b1c81191b9dd1c9145b
child 118287 1ea93193e006fac3a84bfd06a5dc250effc5da8c
push id330
push userbturner@mozilla.com
push dateThu, 24 Jan 2013 00:02:56 +0000
reviewerscjones, blocking-tef
bugs831307
milestone18.0
Bug 831307, add additional logging. r=cjones, a=blocking-tef+.
ipc/ipdl/ipdl/lower.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -306,18 +306,20 @@ function would return true for |Actor[]|
                      and _hasVisibleActor(ipdltype.basetype))))
 
 def _abortIfFalse(cond, msg):
     return StmtExpr(ExprCall(
         ExprVar('NS_ABORT_IF_FALSE'),
         [ cond, ExprLiteral.String(msg) ]))
 
 def _runtimeAbort(msg):
-    return StmtExpr(ExprCall(ExprVar('NS_RUNTIMEABORT'),
-                                     [ ExprLiteral.String(msg) ]))
+    if isinstance(msg, str):
+        msg = ExprLiteral.String(msg)
+    return StmtExpr(
+        ExprCall(ExprVar('NS_RUNTIMEABORT'), args=[ msg ]))
 
 def _autoptr(T):
     return Type('nsAutoPtr', T=T)
 
 def _autoptrGet(expr):
     return ExprCall(ExprSelect(expr, '.', 'get'))
 
 def _autoptrForget(expr):
@@ -439,17 +441,17 @@ def errfnSendDtor(msg):
 def errfnRecv(msg, errcode=_Result.ValuError):
     return [
         _fatalError(msg),
         StmtReturn(errcode)
     ]
 
 # used in Read() methods
 def errfnRead(msg):
-    return [ _protocolErrorBreakpoint(msg), StmtReturn.FALSE ]
+    return [ _fatalError(msg), StmtReturn.FALSE ]
 
 def _destroyMethod():
     return ExprVar('ActorDestroy')
 
 class _DestroyReason:
     @staticmethod
     def Type():  return Type('ActorDestroyReason')
 
@@ -3203,49 +3205,61 @@ class _GenerateProtocolActorCode(ipdl.as
                 ExprSelect(p.channelVar(), '.', 'UnblockChild'))))
 
             self.cls.addstmts([ blockchild, unblockchild, Whitespace.NL ])
 
         ## private methods
         self.cls.addstmt(Label.PRIVATE)
 
         ## FatalError()       
-        msgvar = ExprVar('msg')
+        msgparam = ExprVar('aMsg')
+        msgvar = ExprVar('formattedMessage')
+        actorname = _actorName(p.name, self.side)
         fatalerror = MethodDefn(MethodDecl(
             'FatalError',
-            params=[ Decl(Type('char', const=1, ptrconst=1), msgvar.name) ],
+            params=[ Decl(Type('char', const=1, ptrconst=1), msgparam.name) ],
             const=1, virtual=1))
         fatalerror.addstmts([
             Whitespace('// Virtual method to prevent inlining.\n', indent=1),
             Whitespace('// This give us better error reporting.\n', indent=1),
             Whitespace('// See bug 589371\n\n', indent=1),
-            _printErrorMessage('IPDL error:'),
-            _printErrorMessage(msgvar),
-            _protocolErrorBreakpoint(msgvar),
-            Whitespace.NL
+            _protocolErrorBreakpoint(msgparam),
+            Whitespace.NL,
+            StmtDecl(Decl(Type('nsAutoCString'), msgvar.name),
+                     initargs=[ExprLiteral.String('IPDL error [' + actorname +
+                                                  ']: \\"')]),
+            StmtExpr(ExprCall(ExprSelect(msgvar, '.', 'AppendASCII'),
+                              args=[msgparam]))
         ])
-        actorname = _actorName(p.name, self.side)
         if self.side is 'parent':
             # if the error happens on the parent side, the parent
             # kills off the child
             fatalerror.addstmts([
-                _printErrorMessage(
-                    '['+ actorname +'] killing child side as a result'),
-                Whitespace.NL
+                StmtExpr(ExprCall(ExprSelect(msgvar, '.', 'AppendLiteral'),
+                                  args=[ExprLiteral.String('\\". Killing ' +
+                                                           'child side as a ' +
+                                                           'result.')])),
+                Whitespace.NL,
+                _printErrorMessage(ExprCall(ExprSelect(msgvar, '.', 'get'))),
             ])
 
             ifkill = StmtIf(ExprNot(_killProcess(p.callOtherProcess())))
             ifkill.addifstmt(
-                _printErrorMessage("  may have failed to kill child!"))
-            fatalerror.addstmt(ifkill)
+                _printErrorMessage("May have failed to kill child!"))
+            fatalerror.addstmts([Whitespace.NL, ifkill])
         else:
             # and if it happens on the child side, the child commits
             # seppuko
-            fatalerror.addstmt(
-                _runtimeAbort('['+ actorname +'] abort()ing as a result'))
+            fatalerror.addstmts([
+                StmtExpr(ExprCall(ExprSelect(msgvar, '.', 'AppendLiteral'),
+                                  args=[ExprLiteral.String('\\". abort()ing ' +
+                                                           'as a result.')])),
+                Whitespace.NL,
+                _runtimeAbort(ExprCall(ExprSelect(msgvar, '.', 'get'))),
+            ])
         self.cls.addstmts([ fatalerror, Whitespace.NL ])
 
         ## DestroySubtree(bool normal)
         whyvar = ExprVar('why')
         subtreewhyvar = ExprVar('subtreewhy')
         kidsvar = ExprVar('kids')
         ivar = ExprVar('i')
         ithkid = ExprIndex(kidsvar, ivar)
@@ -4115,17 +4129,18 @@ class _GenerateProtocolActorCode(ipdl.as
         # if (!Read(id, msg))
         #   return false
         # if (FREED_ID == id
         #     || NULL_ID == id && !nullable)
         #   return false
         read.addstmts([
             StmtDecl(Decl(_actorIdType(), idvar.name)),
             self.checkedRead(None, ExprAddrOf(idvar),
-                             self.msgvar, self.itervar, errfnRead),
+                             self.msgvar, self.itervar, errfnRead,
+                             'id\' for \'' + cxxtype.name),
         ])
 
         ifbadid = StmtIf(ExprBinary(
             ExprBinary(_FREED_ACTOR_ID, '==', idvar),
             '||',
             ExprBinary(ExprBinary(_NULL_ACTOR_ID, '==', idvar),
                        '&&',
                        ExprNot(nullablevar))))
@@ -4208,23 +4223,26 @@ class _GenerateProtocolActorCode(ipdl.as
         read = MethodDefn(self.readMethodDecl(outtype, var))
         avar = ExprVar('a')
         forread = StmtFor(init=ExprAssn(Decl(Type.UINT32, ivar.name),
                                         ExprLiteral.ZERO),
                           cond=ExprBinary(ivar, '<', lenvar),
                           update=ExprPrefixUnop(ivar, '++'))
         forread.addstmt(
             self.checkedRead(eltipdltype, ExprAddrOf(ExprIndex(avar, ivar)),
-                             msgvar, itervar, errfnRead))
+                             msgvar, itervar, errfnRead,
+                             eltipdltype.name() + '[i]'))
         read.addstmts([
             StmtDecl(Decl(_cxxRefType(arraytype, self.side), avar.name),
                      init=ExprDeref(var)),
             StmtDecl(Decl(Type.UINT32, lenvar.name)),
             self.checkedRead(None, ExprAddrOf(lenvar),
-                             msgvar, itervar, errfnRead),
+                             msgvar, itervar, errfnRead,
+                             'length\' (' + Type.UINT32.name + ') of \'' +
+                             arraytype.name()),
             Whitespace.NL,
             StmtExpr(_callCxxArraySetLength(var, lenvar, '->')),
             forread,
             StmtReturn.TRUE
         ])
 
         self.cls.addstmts([ write, Whitespace.NL, read, Whitespace.NL ])
 
@@ -4335,21 +4353,22 @@ class _GenerateProtocolActorCode(ipdl.as
 
         write = MethodDefn(self.writeMethodDecl(intype, var))
         read = MethodDefn(self.readMethodDecl(outtype, var))        
 
         def get(sel, f):
             return ExprCall(f.getMethod(thisexpr=var, sel=sel))
 
         for f in sd.fields:
+            desc = f.getMethod().name + '\' (' + f.ipdltype.name() + \
+                   ') member of \'' + intype.name
             writefield = StmtExpr(self.write(f.ipdltype, get('.', f), msgvar))
             readfield = self.checkedRead(f.ipdltype,
                                          ExprAddrOf(get('->', f)),
-                                         msgvar, itervar,
-                                         errfn=errfnRead)
+                                         msgvar, itervar, errfnRead, desc)
             if f.special and f.side != self.side:
                 writefield = Whitespace(
                     "// skipping actor field that's meaningless on this side\n", indent=1)
                 readfield = Whitespace(
                     "// skipping actor field that's meaningless on this side\n", indent=1)
             write.addstmt(writefield)
             read.addstmt(readfield)
 
@@ -4427,17 +4446,18 @@ class _GenerateProtocolActorCode(ipdl.as
             writeswitch
         ])
 
         read = MethodDefn(self.readMethodDecl(outtype, var))
         read.addstmts([
             uniontdef,
             StmtDecl(Decl(Type.INT, typevar.name)),
             self.checkedRead(
-                None, ExprAddrOf(typevar), msgvar, itervar, errfnRead),
+                None, ExprAddrOf(typevar), msgvar, itervar, errfnRead,
+                typevar.name + '\' (' + Type.INT.name + ') of union \'' + uniontype.name()),
             Whitespace.NL,
             readswitch,
         ])
 
         self.cls.addstmts([ write, Whitespace.NL, read, Whitespace.NL ])
 
 
     def writeMethodDecl(self, intype, var, template=None):
@@ -4914,31 +4934,32 @@ class _GenerateProtocolActorCode(ipdl.as
         if 0 == len(md.params):
             return stmts
 
         start, decls, reads = 0, [], []
         if isctor:
             # return the raw actor handle so that its ID can be used
             # to construct the "real" actor
             handlevar = self.handlevar
-            decls = [ StmtDecl(Decl(Type('ActorHandle'), handlevar.name)) ]
+            handletype = Type('ActorHandle')
+            decls = [ StmtDecl(Decl(handletype, handlevar.name)) ]
             reads = [ self.checkedRead(None, ExprAddrOf(handlevar), msgexpr,
                                        ExprAddrOf(self.itervar),
-                                       errfn) ]
+                                       errfn, handletype.name) ]
             start = 1
 
         stmts.extend((
             [ StmtDecl(Decl(Type.VOIDPTR, self.itervar.name),
                      init=ExprLiteral.NULL) ]
             + decls + [ StmtDecl(Decl(p.bareType(side), p.var().name))
                       for p in md.params ]
             + [ Whitespace.NL ]
             + reads + [ self.checkedRead(p.ipdltype, ExprAddrOf(p.var()),
                                          msgexpr, ExprAddrOf(itervar),
-                                         errfn)
+                                         errfn, p.bareType(side).name)
                         for p in md.params[start:] ]
             + [ self.endRead(msgvar, itervar) ]))
 
         return stmts
 
 
     def deserializeReply(self, md, replyexpr, side, errfn):
         stmts = [ Whitespace.NL,
@@ -4950,17 +4971,17 @@ class _GenerateProtocolActorCode(ipdl.as
         itervar = self.itervar
         stmts.extend(
             [ Whitespace.NL,
               StmtDecl(Decl(Type.VOIDPTR, itervar.name),
                        init=ExprLiteral.NULL) ]
             + [ self.checkedRead(r.ipdltype, r.var(),
                                  ExprAddrOf(self.replyvar),
                                  ExprAddrOf(self.itervar),
-                                 errfn)
+                                 errfn, r.bareType(side).name)
                 for r in md.returns ]
             + [ self.endRead(self.replyvar, itervar) ])
 
         return stmts
 
 
     def sendAsync(self, md, msgexpr, actor=None):
         sendok = ExprVar('__sendok')
@@ -5088,19 +5109,19 @@ class _GenerateProtocolActorCode(ipdl.as
                 ExprVar(self.protocol.name +'::Transition'),
                 args=[ stateexpr,
                        ExprCall(ExprVar('Trigger'),
                                 args=[ action, ExprVar(msgid) ]),
                        ExprAddrOf(stateexpr) ])))
         ifbad.addifstmts(_badTransition())
         return [ ifbad ]
 
-    def checkedRead(self, ipdltype, expr, msgexpr, iterexpr, errfn):
+    def checkedRead(self, ipdltype, expr, msgexpr, iterexpr, errfn, paramtype):
         ifbad = StmtIf(ExprNot(self.read(ipdltype, expr, msgexpr, iterexpr)))
-        ifbad.addifstmts(errfn('error deserializing (better message TODO)'))
+        ifbad.addifstmts(errfn('Error deserializing \'' + paramtype + '\''))
         return ifbad
 
     def endRead(self, msgexpr, iterexpr):
         return StmtExpr(ExprCall(ExprSelect(msgexpr, '.', 'EndRead'),
                                  args=[ iterexpr ]))
 
 class _GenerateProtocolParentCode(_GenerateProtocolActorCode):
     def __init__(self):