dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog codegen/cg_decls.tc codegen/cg_g...


From: Radek Polak
Subject: [dotgnu-pnet-commits] pnet ChangeLog codegen/cg_decls.tc codegen/cg_g...
Date: Wed, 21 Mar 2007 08:37:04 +0000

CVSROOT:        /sources/dotgnu-pnet
Module name:    pnet
Changes by:     Radek Polak <radekp>    07/03/21 08:37:04

Modified files:
        .              : ChangeLog 
        codegen        : cg_decls.tc cg_gen.h cg_rbtree.c cg_rbtree.h 
                         cg_scope.c cg_scope.h cg_stmt.tc 
        engine         : debugger.c 
        image          : debug_reader.c 

Log message:
        local variable names in debug info

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3438&r2=1.3439
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_decls.tc?cvsroot=dotgnu-pnet&r1=1.54&r2=1.55
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_gen.h?cvsroot=dotgnu-pnet&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_rbtree.c?cvsroot=dotgnu-pnet&r1=1.1.1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_rbtree.h?cvsroot=dotgnu-pnet&r1=1.1.1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_scope.c?cvsroot=dotgnu-pnet&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_scope.h?cvsroot=dotgnu-pnet&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/pnet/codegen/cg_stmt.tc?cvsroot=dotgnu-pnet&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/debugger.c?cvsroot=dotgnu-pnet&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pnet/image/debug_reader.c?cvsroot=dotgnu-pnet&r1=1.4&r2=1.5

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3438
retrieving revision 1.3439
diff -u -b -r1.3438 -r1.3439
--- ChangeLog   17 Mar 2007 19:11:37 -0000      1.3438
+++ ChangeLog   21 Mar 2007 08:37:04 -0000      1.3439
@@ -1,3 +1,23 @@
+2007-03-21  Radek Polak  <address@hidden>
+
+       * codegen/cg_decls.tc, codegen/cg_gen.h: Flag to suppress creating extra
+       scope for locals after method declaration.
+
+       * codegen/cg_rbtree.c, codegen/cg_rbtree.h: Function for iterating a red
+       black tree.
+
+       * codegen/cg_scope.c, codegen/cg_scope.h: Function for iterating local
+       variables in scope.
+
+       * codegen/cg_stmt.tc: Output name and index for each local variable
+       declared in scope. Output marks for scope beginning and scope end. Local
+       variable name starts with '_' to workaround bug in ilasm grammar.
+
+       * engine/debugger.c: Implemented local variables names. Do not show 
local
+       variables outside current scope.
+
+       * image/debug_reader.c: Return null if local variable is not in scope.
+
 2007-03-18  Aleksey Demakov  <address@hidden>
 
        * engine/cvm_config.h (IL_NO_REGISTERS_USED, IL_VMCASE_BARRIER): New

Index: codegen/cg_decls.tc
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_decls.tc,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- codegen/cg_decls.tc 9 Jul 2004 00:40:20 -0000       1.54
+++ codegen/cg_decls.tc 21 Mar 2007 08:37:04 -0000      1.55
@@ -862,6 +862,9 @@
                DumpILLocals(info, outstream, node->localVarSig);
        }
 
+       /* Don't create extra scope for locals */
+       info->createLocalsScope = 0;
+
        /* Dump the code within the body of the method */
        if(node->body)
        {

Index: codegen/cg_gen.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_gen.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- codegen/cg_gen.h    7 Jul 2004 23:47:36 -0000       1.45
+++ codegen/cg_gen.h    21 Mar 2007 08:37:04 -0000      1.46
@@ -130,6 +130,7 @@
        unsigned                numTempVars;            /* Number of active 
variables */
        unsigned                maxTempVars;            /* Maximum variables in 
"localVars" */
        unsigned        tempLocalBase;          /* Base for temporary local 
variables */
+       int                             createLocalsScope;      /* Non-zero to 
create scope for local variables */
        ILScope            *currentScope;               /* Current scope for 
declarations */
        ILJavaGenInfo  *javaInfo;                       /* Java-specific 
information */
        long                    unsafeLevel;            /* Number of unsafe 
contexts */

Index: codegen/cg_rbtree.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_rbtree.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- codegen/cg_rbtree.c 13 Aug 2001 05:21:17 -0000      1.1.1.1
+++ codegen/cg_rbtree.c 21 Mar 2007 08:37:04 -0000      1.2
@@ -353,6 +353,122 @@
        }
 }
 
+/*
+ * This function returns next node of a binary tree. Result is computed from
+ * current node and previous action.
+ *
+ * Below is picture of actions with example iteration:
+ *
+ *       4
+ *      / \
+ *     /   \
+ *    /     \
+ *   2       5
+ *  / \
+ * 1   3
+ *
+ * current node                4       2       1       1       2       2       
3       3       4       4       5       5       4
+ * action                      LD      LD      RET     RU      RET     LD      
RET     RU      RET     RD      RET     LU      RET
+ * next node           2       1       1       2       2       3       3       
4       4       5       5       4       0
+ *
+ * Actions (or directions from node if you want):
+ *
+ * LU    RU
+ *   \  /
+ *   RET
+ *   /  \
+ * LD    RD
+ *
+ */
+ILRBTreeNode *ILRBTreeIterNext(ILRBTree *tree, ILRBTreeNode *node, int *iter)
+{
+       ILRBTreeNode *tmp;
+
+       if(node == 0)
+       {
+               /* Initialize iteration */
+               *iter = IL_RB_TREE_ITER_LD;
+               tmp = ILRBTreeGetRoot(tree);
+               if(tmp)
+               {
+                       tmp->_iterParent = 0;
+                       return ILRBTreeIterNext(tree, tmp, iter);
+               }
+               return 0;
+       }
+
+       switch(*iter)
+       {
+               case IL_RB_TREE_ITER_RD:
+               {
+                       *iter = IL_RB_TREE_ITER_LD;
+               }
+               case IL_RB_TREE_ITER_LD:
+               {
+                       /* Process left-down node if exists otherwise return 
curr. node */
+                       tmp = ILRBTreeGetLeft(tree, node);
+                       if(tmp)
+                       {
+                               tmp->_iterParent = node;
+                               return ILRBTreeIterNext(tree, tmp, iter);
+                       }
+                       else
+                       {
+                               *iter = IL_RB_TREE_ITER_RET;
+                               return node;
+                       }
+               }
+               break;
+
+               case IL_RB_TREE_ITER_RET:
+               {
+                       /* Process right-down if exist otherwise move up the 
tree */
+                       tmp = ILRBTreeGetRight(tree, node);
+                       if(tmp)
+                       {
+                               tmp->_iterParent = node;
+                               *iter = IL_RB_TREE_ITER_RD;
+                               return ILRBTreeIterNext(tree, tmp, iter);
+                       }
+               }
+               case IL_RB_TREE_ITER_LU:
+               {
+                       /* Process up-left or up-right */
+                       if(node->_iterParent)
+                       {
+                               tmp = ILRBTreeGetRight(tree, node->_iterParent);
+                               if(node == tmp)
+                               {
+                                       *iter = IL_RB_TREE_ITER_LU;
+                                       return ILRBTreeIterNext(tree, 
node->_iterParent, iter);
+                               }
+                               else
+                               {
+                                       *iter = IL_RB_TREE_ITER_RU;
+                                       return ILRBTreeIterNext(tree, 
node->_iterParent, iter);
+                               }
+                       }
+                       else
+                       {
+                               return 0;
+                       }
+               }
+               break;
+
+               case IL_RB_TREE_ITER_RU:
+               {
+                       *iter = IL_RB_TREE_ITER_RET;
+                       return node;
+               }
+               break;
+
+               default:
+               {
+                       return 0;
+               }
+       }
+}
+
 #ifdef __cplusplus
 };
 #endif

Index: codegen/cg_rbtree.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_rbtree.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- codegen/cg_rbtree.h 13 Aug 2001 05:21:17 -0000      1.1.1.1
+++ codegen/cg_rbtree.h 21 Mar 2007 08:37:04 -0000      1.2
@@ -31,7 +31,7 @@
 typedef struct _tagILRBTreeNode ILRBTreeNode;
 struct _tagILRBTreeNode
 {
-       ILRBTreeNode   *_left, *_right;
+       ILRBTreeNode   *_left, *_right, *_iterParent;
        int                             _red : 1;
        int                             _duplicate : 1;
        int                             _continue : 1;
@@ -61,6 +61,12 @@
 
 } ILRBTree;
 
+#define IL_RB_TREE_ITER_LD             0
+#define IL_RB_TREE_ITER_LU             1
+#define IL_RB_TREE_ITER_RD             2
+#define IL_RB_TREE_ITER_RU             3
+#define IL_RB_TREE_ITER_RET            4
+
 /*
  * Initialize a red-black tree to empty.
  */
@@ -101,6 +107,13 @@
 ILRBTreeNode *ILRBTreeGetLeft(ILRBTree *tree, ILRBTreeNode *node);
 ILRBTreeNode *ILRBTreeGetRight(ILRBTree *tree, ILRBTreeNode *node);
 
+/*
+ * Return next node from a red-black tree.
+ * Start iteration by calling with node=NULL.
+ * Nodes are returned in sorted order.
+ */
+ILRBTreeNode *ILRBTreeIterNext(ILRBTree *tree, ILRBTreeNode *node, int *iter);
+
 #ifdef __cplusplus
 };
 #endif

Index: codegen/cg_scope.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_scope.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- codegen/cg_scope.c  29 Feb 2004 00:44:31 -0000      1.18
+++ codegen/cg_scope.c  21 Mar 2007 08:37:04 -0000      1.19
@@ -923,6 +923,22 @@
        return scope->parent;
 }
 
+ILScopeData *ILScopeLocalsIter(ILScope *scope, ILScopeData *prev, int *iter,
+                                                          unsigned long 
*index, const char **name)
+{
+       while((prev = (ILScopeData *) ILRBTreeIterNext(&(scope->nameTree),
+                                                                               
                (ILRBTreeNode *)prev, iter)))
+       {
+               if(prev->rbnode.kind == IL_SCOPE_LOCAL)
+               {
+                       *index = (unsigned int) prev->data;
+                       *name = prev->name;
+                       return prev;
+               }
+       }
+       return 0;
+}
+
 #ifdef __cplusplus
 };
 #endif

Index: codegen/cg_scope.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_scope.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- codegen/cg_scope.h  29 Feb 2004 00:44:31 -0000      1.14
+++ codegen/cg_scope.h  21 Mar 2007 08:37:04 -0000      1.15
@@ -217,6 +217,14 @@
  */
 ILScope *ILScopeGetParent(ILScope *scope);
 
+/*
+ * Return next local variable in scope.
+ * Call with prev=NULL to begin iteration.
+ */
+ILScopeData *ILScopeLocalsIter(ILScope *scope, ILScopeData *prev, int *iter,
+                                                          unsigned long 
*index, const char **name);
+
+
 #ifdef __cplusplus
 };
 #endif

Index: codegen/cg_stmt.tc
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/codegen/cg_stmt.tc,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- codegen/cg_stmt.tc  8 May 2004 09:44:22 -0000       1.43
+++ codegen/cg_stmt.tc  21 Mar 2007 08:37:04 -0000      1.44
@@ -22,6 +22,7 @@
  */
 
 #include <codegen/cg_nodes.h>
+#include <codegen/cg_scope.h>
 #include "il_dumpasm.h"
 
 /*
@@ -1687,6 +1688,32 @@
  */
 ILNode_GenDiscard(ILNode_NewScope)
 {
+       ILScopeData *data = 0;
+       int iter;
+       unsigned long index;
+       const char *name;
+       int dumpScope = 0;
+
+       /* Dump local variable debug section */
+       if(info->debugFlag)
+       {
+               /* Locals scope is suppressed after method declaration */
+               dumpScope = info->createLocalsScope;
+               info->createLocalsScope = 1;
+               if(dumpScope)
+               {
+                       fputs("{\n", info->asmOutput);
+               }
+               while((data = ILScopeLocalsIter(node->scope, data, &iter, 
&index,
+                                                                               
                                                        &name)))
+               {
+                       /* TODO: fix ilasm so that it can compile local 
variables with same
+                          name as IL opcode. Now it fails e.g. when local 
variable is
+                          named "box" */
+                       fprintf(info->asmOutput, ".locals <_%s=%lu>\n", name, 
index);
+               }
+       }
+
        if(info->hasGotoScopes)
        {
                /* Enter a new scope */
@@ -1706,6 +1733,12 @@
                /* Generate the code within the scope */
                ILNode_GenDiscard(node->stmt, info);
        }
+
+       /* End of local variable scope */
+       if(dumpScope)
+       {
+               fputs("}\n", info->asmOutput);
+       }
 }
 
 /*

Index: engine/debugger.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/debugger.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- engine/debugger.c   10 Mar 2007 21:54:57 -0000      1.15
+++ engine/debugger.c   21 Mar 2007 08:37:04 -0000      1.16
@@ -29,6 +29,7 @@
 #include "il_dumpasm.h"
 #include "engine.h"
 #include "cvm.h"
+#include "lib_defs.h"
 #include "debugger.h"
 
 #ifdef IL_USE_JIT
@@ -1077,7 +1078,8 @@
 /*
  * Update locals in DebuggerHelper class.
  */
-static void UpdateLocals(FILE *stream, ILExecThread *thread, ILMethod *method)
+static void UpdateLocals(FILE *stream, ILExecThread *thread, ILMethod *method,
+                                                ILUInt32 offset)
 {
 #ifdef IL_USE_JIT
        ILMethodCode code;
@@ -1087,6 +1089,8 @@
        ILUInt32 i;
        ILLocalWatch *local;
        ILType *type;
+       const char *name = 0;
+       ILDebugContext *dbgc = 0;
 
        /* Clear locals in helper class */
        DebuggerHelper_ClearLocals(thread);
@@ -1108,6 +1112,16 @@
                num = 0;
        }
 
+       /* Debug context for local variable names */
+       if(ILDebugPresent(ILProgramItem_Image(method)))
+       {
+               /* Get the symbol debug information */
+               if((dbgc = ILDebugCreate(ILProgramItem_Image(method))) == 0)
+               {
+                       ILDbOutOfMemory();
+               }
+       }
+
        /* Add local variables in current frame */
        current = 0;
        for(i = 0; i < thread->numWatches && num > 0; i++)
@@ -1119,14 +1133,27 @@
                {
                        continue;
                }
-               type = ILTypeGetLocal(signature, current);
 
-               /* TODO: local variable name */
-               DebuggerHelper_AddLocal(thread, 0, type, local->addr);
+               type = ILTypeGetLocal(signature, current);
+               if(dbgc)
+               {
+                       name = ILDebugGetVarName(dbgc, ILMethod_Token(method), 
offset, i);
+                       if(name == 0)
+                       {
+                               continue;
+                       }
+               }
+               /* TODO: fix ilasm and remove starting '_' from locals names */
+               DebuggerHelper_AddLocal(thread, name + 1, type, local->addr);
 
                current++;
                num--;
        }
+
+       if(dbgc)
+       {
+               ILDebugDestroy(dbgc);
+       }
 #endif
 }
 
@@ -1151,7 +1178,7 @@
 
        /* Update locals in DebuggerHelper class */
        UpdateLocals(stream, debugger->dbthread->execThread,
-                                                                               
                debugger->dbthread->method);
+                       debugger->dbthread->method, (ILUInt32) 
debugger->dbthread->offset);
 
        str = DebuggerHelper_ShowLocals(debugger->dbthread->execThread);
        if(str)
@@ -1290,7 +1317,7 @@
 
        /* Update locals in DebuggerHelper class */
        UpdateLocals(stream, debugger->dbthread->execThread,
-                                                                               
                debugger->dbthread->method);
+                       debugger->dbthread->method, (ILUInt32) 
debugger->dbthread->offset);
 
        fputs("<Watches>\n", stream);
 
@@ -1588,7 +1615,7 @@
 /*
  * Return directory where image was linked.
  */
-static const char * GetLinkDir(ILImage *image)
+static const char *GetLinkDir(ILImage *image)
 {
        ILDebugContext *dbgc;
        ILToken token;

Index: image/debug_reader.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/image/debug_reader.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- image/debug_reader.c        22 Jul 2002 11:32:13 -0000      1.4
+++ image/debug_reader.c        21 Mar 2007 08:37:04 -0000      1.5
@@ -434,10 +434,13 @@
                        {
                                scopeStart = tempStart;
                                scopeEnd = tempEnd;
+                               if(offset >= scopeStart && offset < scopeEnd)
+                               {
                                name = ILDebugGetString(dbg, tempName);
                        }
                }
        }
+       }
 
        /* Return the innermost name that we found */
        return name;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]