2001-07-17 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Wed, 18 Jul 2001 02:48:19 +0000 (02:48 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 18 Jul 2001 02:48:19 +0000 (02:48 -0000)
* metadata.h: Fixed Paolo's quick hack.  Put the documnentation
from get.c here.

2001-07-17  Miguel de Icaza  <miguel@ximian.com>

* main.c (usage): Print out all the arguments.

* get.c, main.c, dump.c: Remove `expand', `get_encoded_value',
`get_blob_encoded_size' and replaced with the proper functions
from metadata.c

:

svn path=/trunk/mono/; revision=218

12 files changed:
mono/Makefile.am
mono/dis/ChangeLog
mono/dis/dis-cil.c
mono/dis/dump.c
mono/dis/get.c
mono/dis/get.h
mono/dis/main.c
mono/interpreter/interp.c
mono/metadata/ChangeLog
mono/metadata/cil-coff.h
mono/metadata/metadata.c
mono/metadata/metadata.h

index dd16095408d3eb55d748c3613d06cf3048b9ab33..72ba57a46d84af186b244e28f14da1dfd02f8786 100644 (file)
@@ -1 +1 @@
-SUBDIRS = metadata cil dis interpreter
+SUBDIRS = metadata cil cli dis interpreter 
index 7b4361e6c137097ff800a4f97996bb553b089cac..fea6634bc6c65f2c052f5486d3db85fe1e0ff4aa 100644 (file)
@@ -1,3 +1,11 @@
+2001-07-17  Miguel de Icaza  <miguel@ximian.com>
+
+       * main.c (usage): Print out all the arguments.
+
+       * get.c, main.c, dump.c: Remove `expand', `get_encoded_value',
+       `get_blob_encoded_size' and replaced with the proper functions
+       from metadata.c
+
 2001-07-15  Miguel de Icaza  <miguel@ximian.com>
 
        * main.c (dis_code): Only display .entrypoint when we are dealing
index 8f57ceb067c001147b75fb20d37e8cf09e16417c..433f4b6c425dfab41066fddc38ca62a4f83570d0 100644 (file)
@@ -63,7 +63,7 @@ get_encoded_user_string (const char *ptr)
        char *res;
        int len, i, j;
 
-       ptr = get_blob_encoded_size (ptr, &len);
+       ptr = mono_metadata_decode_blob_size (ptr, &len);
        res = g_malloc (len + 1);
 
        /*
index bd110dbbc25b460ccdf369ee8293458ba2332073..b80cf901a78fef240d7d8c22e7fda304a7b87e58 100644 (file)
@@ -23,7 +23,7 @@ dump_table_assembly (metadata_t *m)
        const char *ptr;
        int len;
 
-       expand (t, 0, cols, CSIZE (cols));
+       mono_metadata_decode_row (t, 0, cols, CSIZE (cols));
        fprintf (output, "Assembly Table\n");
 
        fprintf (output, "Name:          %s\n", mono_metadata_string_heap (m, cols [7]));
@@ -33,7 +33,7 @@ dump_table_assembly (metadata_t *m)
        fprintf (output, "PublicKey:     BlobPtr (0x%08x)\n", cols [6]);
 
        ptr = mono_metadata_blob_heap (m, cols [6]);
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
        if (len > 0){
                fprintf (output, "\tDump:");
                hex_dump (ptr, 0, len);
@@ -74,7 +74,7 @@ dump_table_typedef (metadata_t *m)
                char *s = get_typedef (m, i);
                guint32 cols [6];
 
-               expand (&m->tables [META_TABLE_TYPEDEF], i - 1, cols, CSIZE (cols));
+               mono_metadata_decode_row (&m->tables [META_TABLE_TYPEDEF], i - 1, cols, CSIZE (cols));
 
                fprintf (output, "%d: %s (flist=%d, mlist=%d)\n", i, s, cols [4], cols [5]);
                g_free (s);
@@ -95,12 +95,12 @@ dump_table_assemblyref (metadata_t *m)
                int len;
                guint32 cols [9];
 
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
                fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i,
                         cols [0], cols [1], cols [2], cols [3],
                         mono_metadata_string_heap (m, cols [6]));
                ptr = mono_metadata_blob_heap (m, cols [6]);
-               ptr = get_encoded_value (ptr, &len);
+               ptr = mono_metadata_decode_value (ptr, &len);
                if (len > 0){
                        fprintf (output, "\tPublic Key:");
                        hex_dump (ptr, 0, len);
@@ -123,7 +123,7 @@ dump_table_param (metadata_t *m)
        for (i = 0; i < t->rows; i++){
                guint32 cols [3];
 
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
                fprintf (output, "%d: 0x%04x %d %s\n",
                         i,
                         cols [0], cols [1], 
@@ -144,7 +144,7 @@ dump_table_field (metadata_t *m)
                guint32 cols [3];
                char *sig, *flags;
 
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
                sig = get_field_signature (m, cols [2]);
                flags = field_flags (cols [0]);
                fprintf (output, "%d: %s %s: %s\n",
@@ -170,7 +170,7 @@ dump_table_memberref (metadata_t *m)
        for (i = 0; i < t->rows; i++){
                guint32 cols [3];
 
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
                
                kind = cols [0] & 7;
                idx = cols [0] >> 3;
@@ -218,7 +218,7 @@ dump_table_class_layout (metadata_t *m)
        for (i = 0; i < t->rows; i++){
                guint32 cols [3];
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                fprintf (output, "%d: PackingSize=%d  ClassSize=%d  Parent=%s\n",
                         i, cols [0], cols [1], get_typedef (m, cols [2]));
@@ -235,7 +235,7 @@ dump_table_constant (metadata_t *m)
        for (i = 0; i < t->rows; i++){
                guint32 cols [4];
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                fprintf (output, "%d: Parent=0x%08x %s\n",
                         i, cols [2], get_constant (m, (ElementTypeEnum) cols [0], cols [3]));
@@ -258,7 +258,7 @@ dump_table_property (metadata_t *m)
                char *type;
                int bsize;
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
                flags [0] = 0;
                if (cols [0] & 0x0200)
                        strcat (flags, "special ");
@@ -268,12 +268,12 @@ dump_table_property (metadata_t *m)
                        strcat (flags, "hasdefault ");
 
                ptr = mono_metadata_blob_heap (m, cols [2]);
-               ptr = get_blob_encoded_size (ptr, &bsize);
+               ptr = mono_metadata_decode_blob_size (ptr, &bsize);
                /* ECMA claims 0x08 ... */
                if (*ptr != 0x28 && *ptr != 0x08)
                                g_warning("incorrect signature in propert blob: 0x%x", *ptr);
                ptr++;
-               ptr = get_encoded_value (ptr, &pcount);
+               ptr = mono_metadata_decode_value (ptr, &pcount);
                ptr = get_type (m, ptr, &type);
                fprintf (output, "%d: %s %s (",
                         i, type, mono_metadata_string_heap (m, cols [1]));
@@ -300,7 +300,7 @@ dump_table_event (metadata_t *m)
                const char *name;
                char *type;
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                name = mono_metadata_string_heap (m, cols [1]);
                type = get_typedef_or_ref (m, cols [2]);
@@ -322,7 +322,7 @@ dump_table_file (metadata_t *m)
                guint32 cols [3];
                const char *name;
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                name = mono_metadata_string_heap (m, cols[1]);
                fprintf (output, "%d: %s %s\n", i, name, cols[2]&0x1?"nometadata":"containsmetadata");
@@ -341,7 +341,7 @@ dump_table_moduleref (metadata_t *m)
                guint32 cols [1];
                const char *name;
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                name = mono_metadata_string_heap (m, cols[0]);
                fprintf (output, "%d: %s\n", i, name);
@@ -360,7 +360,7 @@ dump_table_method (metadata_t *m)
                guint32 cols [6];
                const char *name;
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                name = mono_metadata_string_heap (m, cols[3]);
                fprintf (output, "%d: %s\n", i, name);
index a71aaeabb037c6eb964d71482197ba092c5e8127..489e526eeb4ac76ed549714515a863bed0c272bf 100644 (file)
 #include "util.h"
 #include "get.h"
 
-/**
- * expand:
- * @t: table to extract information from.
- * @idx: index in table.
- * @res: array of @res_size cols to store the results in
- *
- * This decompresses the metadata element @idx in table @t
- * into the guint32 @res array that has res_size elements
- */
-void
-expand (metadata_tableinfo_t *t, int idx, guint32 *res, int res_size)
-
-{
-       guint32 bitfield = t->size_bitfield;
-       int i, count = meta_table_count (bitfield);
-       char *data = t->base + idx * t->row_size;
-       
-       g_assert (res_size == count);
-       
-       for (i = 0; i < count; i++){
-               int n = meta_table_size (bitfield, i);
-
-               switch (n){
-               case 1:
-                       res [i] = *data; break;
-               case 2:
-                       res [i] = read16 (data); break;
-                       
-               case 4:
-                       res [i] = read32 (data); break;
-                       
-               default:
-                       g_assert_not_reached ();
-               }
-               data += n;
-       }
-}
-
-/**
- * get_encoded_value:
- * @ptr: pointer to decode from
- * @len: result value is stored here.
- *
- * This routine decompresses 32-bit values as specified in the "Blob and
- * Signature" section (22.2)
- *
- * Returns: updated pointer location
- */
-const char *
-get_encoded_value (const char *_ptr, guint32 *len)
-{
-       const unsigned char *ptr = (unsigned char *) _ptr;
-       unsigned char b = *ptr;
-       
-       if ((b & 0x80) == 0){
-               *len = b;
-               return ptr+1;
-       } else if ((b & 0x40) == 0){
-               *len = ((b & 0x3f) << 8 | ptr [1]);
-               return ptr + 2;
-       }
-       *len = ((b & 0x1f) << 24) |
-               (ptr [1] << 16) |
-               (ptr [2] << 8) |
-               ptr [3];
-       
-       return ptr + 4;
-}
-
 char *
 get_typedef (metadata_t *m, int idx)
 {
        guint32 cols [6];
 
-       expand (&m->tables [META_TABLE_TYPEDEF], idx - 1, cols, CSIZE (cols));
+       mono_metadata_decode_row (&m->tables [META_TABLE_TYPEDEF], idx - 1, cols, CSIZE (cols));
 
        return g_strdup_printf (
                "%s.%s",
@@ -108,7 +39,7 @@ get_module (metadata_t *m, int idx)
         */
        g_assert (idx == 1);
            
-       expand (&m->tables [META_TABLE_MODULEREF], idx - 1, cols, CSIZE (cols));
+       mono_metadata_decode_row (&m->tables [META_TABLE_MODULEREF], idx - 1, cols, CSIZE (cols));
 
        return g_strdup (mono_metadata_string_heap (m, cols [6]));
 }
@@ -118,7 +49,7 @@ get_assemblyref (metadata_t *m, int idx)
 {
        guint32 cols [9];
        
-       expand (&m->tables [META_TABLE_ASSEMBLYREF], idx - 1, cols, CSIZE (cols));
+       mono_metadata_decode_row (&m->tables [META_TABLE_ASSEMBLYREF], idx - 1, cols, CSIZE (cols));
 
        return g_strdup (mono_metadata_string_heap (m, cols [6]));
 }
@@ -136,21 +67,21 @@ get_array_shape (metadata_t *m, const char *ptr, char **result)
        int i, r;
        char buffer [80];
        
-       ptr = get_encoded_value (ptr, &rank);
-       ptr = get_encoded_value (ptr, &num_sizes);
+       ptr = mono_metadata_decode_value (ptr, &rank);
+       ptr = mono_metadata_decode_value (ptr, &num_sizes);
 
        if (num_sizes > 0)
                sizes = g_new (guint32, num_sizes);
        
        for (i = 0; i < num_sizes; i++)
-               ptr = get_encoded_value (ptr, &(sizes [i]));
+               ptr = mono_metadata_decode_value (ptr, &(sizes [i]));
 
-       ptr = get_encoded_value (ptr, &num_lo_bounds);
+       ptr = mono_metadata_decode_value (ptr, &num_lo_bounds);
        if (num_lo_bounds > 0)
                lo_bounds = g_new (guint32, num_lo_bounds);
        
        for (i = 0; i < num_lo_bounds; i++)
-               ptr = get_encoded_value (ptr, &(lo_bounds [i]));
+               ptr = mono_metadata_decode_value (ptr, &(lo_bounds [i]));
 
        for (r = 0; r < rank; r++){
                if (r < num_sizes){
@@ -196,9 +127,9 @@ get_typespec (metadata_t *m, guint32 idx)
        GString *res = g_string_new ("");
        int len;
 
-       expand (&m->tables [META_TABLE_TYPESPEC], idx-1, cols, CSIZE (cols));
+       mono_metadata_decode_row (&m->tables [META_TABLE_TYPESPEC], idx-1, cols, CSIZE (cols));
        ptr = mono_metadata_blob_heap (m, cols [0]);
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
        
        switch (*ptr++){
        case ELEMENT_TYPE_PTR:
@@ -266,7 +197,7 @@ get_typeref (metadata_t *m, int idx)
        char *x, *ret;
        guint32 rs_idx, table;
        
-       expand (&m->tables [META_TABLE_TYPEREF], idx - 1, cols, CSIZE (cols));
+       mono_metadata_decode_row (&m->tables [META_TABLE_TYPEREF], idx - 1, cols, CSIZE (cols));
 
        t = mono_metadata_string_heap (m, cols [1]);
        s = mono_metadata_string_heap (m, cols [2]);
@@ -373,7 +304,7 @@ get_encoded_typedef_or_ref (metadata_t *m, const char *ptr, char **result)
 {
        guint32 token;
        
-       ptr = get_encoded_value (ptr, &token);
+       ptr = mono_metadata_decode_value (ptr, &token);
 
        *result = get_typedef_or_ref (m, token);
 
@@ -405,26 +336,6 @@ get_custom_mod (metadata_t *m, const char *ptr, char **return_value)
 }
 
 
-/**
- * methoddefref_signature:
- * @m: metadata context 
- * @ptr: location to decode from.
- * @result: pointer to string where resulting decoded string is stored
- *
- * This routine decodes into a string a MethodDef or a MethodRef.
- *
- * result will point to a g_malloc()ed string.
- *
- * Returns: the new ptr to continue decoding
- */
-static const char *
-methoddefref_signature (metadata_t *m, const char *ptr, char **result)
-{
-       *result = g_strdup ("method-def-or-ref");
-       
-       return ptr;
-}
-
 static map_t element_type_map [] = {
        { ELEMENT_TYPE_END        , "end" },
        { ELEMENT_TYPE_VOID       , "void" },
@@ -690,7 +601,7 @@ get_field_signature (metadata_t *m, guint32 blob_signature)
        char *res;
        int len;
        
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
        base = ptr;
        /* FIELD is 0x06 */
        g_assert (*ptr == 0x06);
@@ -720,7 +631,7 @@ get_field_literal_type (metadata_t *m, guint32 blob_signature)
        int len;
        char *allocated_modifier_string;
        
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
 
        /* FIELD is 0x06 */
        g_assert (*ptr == 0x06);
@@ -890,38 +801,6 @@ field_flags (guint32 f)
        return g_strdup (buffer);
 }
 
-/**
- * get_blob_encoded_size:
- * @ptr: pointer to a blob object
- * @size: where we return the size of the object
- *
- * This decodes a compressed size as described by 23.1.4
- *
- * Returns: the position to start decoding a blob or user string object
- * from. 
- */
-const char *
-get_blob_encoded_size (const char *xptr, int *size)
-{
-       const unsigned char *ptr = xptr;
-       
-       if ((*ptr & 0x80) == 0){
-               *size = ptr [0] & 0x7f;
-               ptr++;
-       } else if ((*ptr & 0x40) == 0){
-               *size = ((ptr [0] & 0x3f) << 8) + ptr [1];
-               ptr += 2;
-       } else {
-               *size = ((ptr [0] & 0x1f) << 24) +
-                       (ptr [1] << 16) +
-                       (ptr [2] << 8) +
-                       ptr [3];
-               ptr += 4;
-       }
-
-       return (char *) ptr;
-}
-
 /**
  * Returns a stringifed representation of a MethodRefSig (22.2.2)
  */
@@ -935,7 +814,7 @@ get_methodref_signature (metadata_t *m, guint32 blob_signature, const char *fanc
        int param_count, signature_len;
        int i;
        
-       ptr = get_encoded_value (ptr, &signature_len);
+       ptr = mono_metadata_decode_value (ptr, &signature_len);
 
        if (*ptr & 0x20){
                if (*ptr & 0x40)
@@ -948,7 +827,7 @@ get_methodref_signature (metadata_t *m, guint32 blob_signature, const char *fanc
                seen_vararg = 1;
 
        ptr++;
-       ptr = get_encoded_value (ptr, &param_count);
+       ptr = mono_metadata_decode_value (ptr, &param_count);
        ptr = get_ret_type (m, ptr, &allocated_ret_type);
 
        g_string_append (res, allocated_ret_type);
@@ -1010,7 +889,7 @@ typedef_locator (const void *a, const void *b)
        int typedef_index = (bb - loc->t->base) / loc->t->row_size;
        guint32 cols [6], cols_next [6];
 
-       expand (loc->t, typedef_index, cols, CSIZE (cols));
+       mono_metadata_decode_row (loc->t, typedef_index, cols, CSIZE (cols));
 
        if (loc->idx < cols [4])
                return -1;
@@ -1019,7 +898,7 @@ typedef_locator (const void *a, const void *b)
         * Need to check that the next row is valid.
         */
        if (typedef_index + 1 < loc->t->rows) {
-               expand (loc->t, typedef_index + 1, cols_next, CSIZE (cols_next));
+               mono_metadata_decode_row (loc->t, typedef_index + 1, cols_next, CSIZE (cols_next));
                if (loc->idx >= cols_next [4])
                        return 1;
 
@@ -1059,7 +938,7 @@ get_field (metadata_t *m, guint32 token)
        }
        g_assert (mono_metadata_token_code (token) == TOKEN_TYPE_FIELD_DEF);
 
-       expand (&m->tables [META_TABLE_FIELD], idx - 1, cols, CSIZE (cols));
+       mono_metadata_decode_row (&m->tables [META_TABLE_FIELD], idx - 1, cols, CSIZE (cols));
        sig = get_field_signature (m, cols [2]);
 
        /*
@@ -1136,11 +1015,14 @@ get_method (metadata_t *m, guint32 token)
        case TOKEN_TYPE_MEMBER_REF: {
                char *sig;
                
-               expand (&m->tables [META_TABLE_MEMBERREF], idx - 1, member_cols, CSIZE (member_cols));
+               mono_metadata_decode_row (&m->tables [META_TABLE_MEMBERREF],
+                                         idx - 1, member_cols,
+                                         CSIZE (member_cols));
                class = get_memberref_parent (m, member_cols [0]);
-               fancy_name = g_strconcat (class, "::",
-                                         mono_metadata_string_heap (m, member_cols [1]),
-                                         NULL);
+               fancy_name = g_strconcat (
+                       class, "::",
+                       mono_metadata_string_heap (m, member_cols [1]),
+                       NULL);
                
                sig = get_methodref_signature (
                        m, member_cols [2], fancy_name);
@@ -1171,7 +1053,7 @@ get_constant (metadata_t *m, ElementTypeEnum t, guint32 blob_index)
        const char *ptr = mono_metadata_blob_heap (m, blob_index);
        int len;
        
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
        
        switch (t){
        case ELEMENT_TYPE_BOOLEAN:
index b67b5510720d19f42da0f33d11b2db46645a6104..0295baa2a257fd053a79020f09ed5f8d5afabde6 100644 (file)
@@ -50,7 +50,4 @@ const char *get_param                  (metadata_t *m, const char *ptr,
                                        char **retval);
 const char *get_blob_encoded_size      (const char *ptr, int *size);
 
-void expand (metadata_tableinfo_t *t, int idx, guint32 *res, int res_size);
-
-
 ElementTypeEnum get_field_literal_type (metadata_t *m, guint32 blob_signature);
index 61b34f67bf82d1d54d36f85593368c23946c6927..6004135259451fbdc3aacc87fea959b8b852bcc2 100644 (file)
@@ -49,7 +49,7 @@ dis_directive_assembly (metadata_t *m)
        if (t->base == NULL)
                return;
 
-       expand (t, 0, cols, CSIZE (cols));
+       mono_metadata_decode_row (t, 0, cols, CSIZE (cols));
        
        fprintf (output,
                 ".assembly %s\n"
@@ -80,7 +80,7 @@ dis_directive_assemblyref (metadata_t *m)
                return;
 
        for (i = 0; i < t->rows; i++){
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
 
                fprintf (output,
                         ".assembly extern %s\n"
@@ -172,7 +172,7 @@ dis_field_list (metadata_t *m, guint32 start, guint32 end)
        for (i = start; i < end; i++){
                char *sig, *flags;
                
-               expand (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
                sig = get_field_signature (m, cols [2]);
                flags = field_flags (cols [0]);
                
@@ -294,24 +294,24 @@ dis_locals (metadata_t *m, guint32 token)
        guint32 cols[1];
        int len=0, i, bsize;
 
-       expand (t, (token&0xffffff)-1, cols, CSIZE(cols));
+       mono_metadata_decode_row (t, (token&0xffffff)-1, cols, CSIZE(cols));
        ptr = mono_metadata_blob_heap (m, cols[0]);
-       ptr = get_blob_encoded_size (ptr, &bsize);
+       ptr = mono_metadata_decode_blob_size (ptr, &bsize);
        if (*ptr != 0x07)
                        g_warning("wrong signature for locals blob");
        ptr++;
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
        fprintf(output, "\t.locals ( // %d\n", len);
        for (i=0; i < len; ++i) {
                int val;
                char * desc = NULL;
                const char *p = ptr;
                MonoType *type;
-               ptr = get_encoded_value (ptr, &val);
+               ptr = mono_metadata_decode_value (ptr, &val);
                if (val == ELEMENT_TYPE_PINNED) {
                        fprintf(output, "//pinned\n");
                        p = ptr;
-                       ptr = get_encoded_value (ptr, &val);
+                       ptr = mono_metadata_decode_value (ptr, &val);
                }
                if (val == ELEMENT_TYPE_BYREF) {
                        fprintf(output, "// byref\n");
@@ -383,14 +383,14 @@ parse_method_signature (metadata_t *m, guint32 blob_signature)
        MethodSignature *ms = g_new0 (MethodSignature, 1);
        int i, len;
 
-       ptr = get_encoded_value (ptr, &len);
+       ptr = mono_metadata_decode_value (ptr, &len);
        fprintf (output, "     // SIG: ");
        hex_dump (ptr, 0, -len);
        fprintf (output, "\n");
        
        ms->flags = *ptr++;
 
-       ptr = get_encoded_value (ptr, &ms->param_count);
+       ptr = mono_metadata_decode_value (ptr, &ms->param_count);
        ptr = get_ret_type (m, ptr, &ms->ret_type);
        ms->param = g_new (char *, ms->param_count);
        
@@ -440,8 +440,8 @@ dis_method_list (metadata_t *m, cli_image_info_t *ii, guint32 start, guint32 end
                MethodSignature *ms;
                char *flags, *impl_flags;
                
-               expand (t, i, cols, CSIZE (cols));
-               expand (t, i + 1, cols_next, CSIZE (cols_next));
+               mono_metadata_decode_row (t, i, cols, CSIZE (cols));
+               mono_metadata_decode_row (t, i + 1, cols_next, CSIZE (cols_next));
 
                flags = method_flags (cols [2]);
                impl_flags = method_impl_flags (cols [1]);
@@ -462,7 +462,7 @@ dis_method_list (metadata_t *m, cli_image_info_t *ii, guint32 start, guint32 end
                        for (i = 0; i < ms->param_count; i++){
                                char *pf;
                                
-                               expand (p, i, param_cols, CSIZE (param_cols));
+                               mono_metadata_decode_row (p, i, param_cols, CSIZE (param_cols));
                                pf = param_flags (param_cols [0]);
                                fprintf (
                                        output, "\t\t%s %s %s%s", pf, ms->param [i],
@@ -501,10 +501,10 @@ dis_type (metadata_t *m, cli_image_info_t *ii, int n)
        const char *name;
        gboolean next_is_valid, last;
        
-       expand (t, n, cols, CSIZE (cols));
+       mono_metadata_decode_row (t, n, cols, CSIZE (cols));
 
        if (t->rows > n+1){
-               expand (t, n + 1, cols_next, CSIZE (cols_next));
+               mono_metadata_decode_row (t, n + 1, cols_next, CSIZE (cols_next));
                next_is_valid = 1;
        } else
                next_is_valid = 0;
@@ -632,7 +632,18 @@ disassemble_file (const char *file)
 static void
 usage (void)
 {
-       fprintf (stderr, "Usage is: monodis [--typeref][--typedef][--assemblyref][--param][--fields][--memberref] file ..\n");
+       GString *args = g_string_new ("");
+       int i;
+       
+       for (i = 0; table_list [i].name != NULL; i++){
+               g_string_append (args, "[");
+               g_string_append (args, table_list [i].name);
+               g_string_append (args, "] ");
+               if ((i % 4) == 0)
+                       g_string_append_c (args, '\n');
+       }
+       fprintf (stderr,
+                "Usage is: monodis %s file ..\n", args);
        exit (1);
 }
 
index 194dbeb4530d60146c8c1525528b1c9fe1d04853..4f1b1e6625033e9101414de22ff0f47f7b1d8dc9 100644 (file)
@@ -59,6 +59,7 @@ static int count = 0;
  * Don't look at these macros, it hurts...
  */
 #define GOTO_LABEL
+#undef GOTO_LABEL
 #ifdef GOTO_LABEL
 #define SWITCH(a) goto *goto_map [(a)];
 #define BREAK SWITCH(*ip)
@@ -107,6 +108,14 @@ static int count = 0;
 #define SUB_SWITCH case 0xFE:
 #endif
 
+void
+ves_abort (cli_image_info_t *iinfo, MonoMethod *mh, unsigned char *ip, stackval *stack)
+{
+       printf ("In method: %s\n", 
+       printf ("Aborted execution");
+       abort (1);
+}
+
 /*
  * Need to optimize ALU ops when natural int == int32 
  *
@@ -157,10 +166,10 @@ ves_exec_method (cli_image_info_t *iinfo, MonoMethod *mh, stackval *args)
 #ifdef GOTO_LABEL
                START:
 #endif
-               /*g_print ("0x%04x %02x\n", ip-(unsigned char*)mh->header->code, *ip);
+               g_print ("0x%04x %02x\n", ip-(unsigned char*)mh->header->code, *ip);
                if (sp > stack)
                                printf ("\t[%d] %d 0x%08x %0.5f\n", sp-stack, sp[-1].type, sp[-1].data.i, sp[-1].data.f);
-               */
+               
                SWITCH (*ip) {
                CASE (CEE_NOP) 
                        ++ip;
index 1a9a72a7b20dced233e3e8eeb7944f7d4d767a8b..5933a3b67b9275f81849ff45f3ef5e21e5177c8b 100644 (file)
@@ -1,3 +1,8 @@
+2001-07-17  Miguel de Icaza  <miguel@ximian.com>
+
+       * metadata.h: Fixed Paolo's quick hack.  Put the documnentation
+       from get.c here.
+
 Sun Jul 15 19:39:06 CEST 2001 Paolo Molaro <lupus@ximian.com>
 
        * metadata.c, metadata.h: decode local vars in method header
index 7d14cadc8f19dbacb05532fdf2b370c35c74afa0..79c1d8608288edd11836446eaf75a3fa0cf78cea 100644 (file)
@@ -158,18 +158,7 @@ typedef struct {
        metadata_t        cli_metadata;
 } cli_image_info_t;
 
-typedef struct {
-       MonoMetaMethodHeader *header;
-       MonoMethodSignature  *signature;
-       guint32 name; /* index in string heap */
-       /* add flags, info from param table  ... */
-} MonoMethod;
-
 guint32       cli_rva_image_map (cli_image_info_t *iinfo, guint32 rva);
 char         *cli_rva_map       (cli_image_info_t *iinfo, guint32 rva);
 
-MonoMethod   *mono_get_method   (cli_image_info_t *iinfo, guint32 token);
-void          mono_free_method  (MonoMethod *method);
-
-
 #endif /* __MONO_CIL_COFF_H__ */
index 650ad7ba4464284eb662f4a9958264cdcb9de159..f194d97272b60fb1ac9309650e43631315e6f281 100644 (file)
@@ -784,7 +784,15 @@ parse_exception_handler (const char *ptr, gboolean is_fat)
        return eh;
 }
 
-/* cut and paste from expand: remove that one later */
+/**
+ * mono_metadata_decode_row:
+ * @t: table to extract information from.
+ * @idx: index in table.
+ * @res: array of @res_size cols to store the results in
+ *
+ * This decompresses the metadata element @idx in table @t
+ * into the guint32 @res array that has res_size elements
+ */
 void
 mono_metadata_decode_row (metadata_tableinfo_t *t, int idx, guint32 *res, int res_size)
 {
@@ -813,6 +821,16 @@ mono_metadata_decode_row (metadata_tableinfo_t *t, int idx, guint32 *res, int re
        }
 }
 
+/**
+ * mono_metadata_decode_blob_size:
+ * @ptr: pointer to a blob object
+ * @size: where we return the size of the object
+ *
+ * This decodes a compressed size as described by 23.1.4
+ *
+ * Returns: the position to start decoding a blob or user string object
+ * from. 
+ */
 const char *
 mono_metadata_decode_blob_size (const char *xptr, int *size)
 {
@@ -835,7 +853,17 @@ mono_metadata_decode_blob_size (const char *xptr, int *size)
        return (char *) ptr;
 }
 
-/* cut and paste from get_encode_val */
+
+/**
+ * mono_metadata_decode_value:
+ * @ptr: pointer to decode from
+ * @len: result value is stored here.
+ *
+ * This routine decompresses 32-bit values as specified in the "Blob and
+ * Signature" section (22.2)
+ *
+ * Returns: updated pointer location
+ */
 const char *
 mono_metadata_decode_value (const char *_ptr, guint32 *len)
 {
@@ -1122,54 +1150,6 @@ mono_metadata_free_type (MonoType *type)
        g_free (type);
 }
 
-MonoMethod *
-mono_get_method (cli_image_info_t *iinfo, guint32 token)
-{
-       MonoMethod *result = g_new0 (MonoMethod, 1);
-       int table = mono_metadata_token_table (token);
-       int index = mono_metadata_token_index (token);
-       metadata_tableinfo_t *tables = iinfo->cli_metadata.tables;
-       const char *loc;
-       const char *sig = NULL;
-       int size;
-       guint32 cols[6];
-
-       /*
-        * We need a context with cli_image_info_t for this module and the assemblies
-        * loaded later to support method refs...
-        */
-       if (table != META_TABLE_METHOD) {
-               g_assert (table == META_TABLE_MEMBERREF);
-               mono_metadata_decode_row (&tables [table], index, cols, 3);
-               g_assert ((cols [0] & 0x07) != 3);
-               table = META_TABLE_METHOD;
-               index = cols [0] >> 3;
-               sig = mono_metadata_blob_heap (&iinfo->cli_metadata, cols [2]);
-               result->name = cols [1];
-       }
-       
-       mono_metadata_decode_row (&tables [table], index - 1, cols, 6);
-       result->name = cols [3];
-       /* if this is a methodref from another module/assembly, this fails */
-       loc = cli_rva_map (iinfo, cols [0]);
-       g_assert (loc);
-       result->header = mono_metadata_parse_mh (&iinfo->cli_metadata, loc);
-       if (!sig) /* already taken from the methodref */
-               sig = mono_metadata_blob_heap (&iinfo->cli_metadata, cols [4]);
-       sig = mono_metadata_decode_blob_size (sig, &size);
-       result->signature = mono_metadata_parse_method_signature (&iinfo->cli_metadata, 0, sig, NULL);
-
-       return result;
-}
-
-void
-mono_free_method  (MonoMethod *method)
-{
-       mono_metadata_free_method_signature (method->signature);
-       mono_metadata_free_mh (method->header);
-       g_free (method);
-}
-
 /** 
  * @mh: The Method header
  * @ptr: Points to the beginning of the Section Data (25.3)
index e42fcc517d08080981f24a892a643df48a7921f9..eaf80870a59a06e96491868179d0afaaa4883772 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <glib.h>
 
-#include "eltype.h"
+#include <mono/metadata/eltype.h>
 
 typedef struct {
        guint32  sh_offset;
@@ -75,6 +75,11 @@ typedef struct {
        guint32   size_bitfield;
 } metadata_tableinfo_t;
 
+void         mono_metadata_decode_row (metadata_tableinfo_t  *t,
+                                      int                    idx,
+                                      guint32               *res,
+                                      int                    res_size);
+
 /*
  * This macro is used to extract the size of the table encoded in
  * the size_bitfield of metadata_tableinfo_t.
@@ -174,21 +179,20 @@ MonoMetaTable *mono_metadata_get_table    (MetaTableEnum table);
 /*
  *
  */
-char          *mono_metadata_locate       (metadata_t *meta, int table, int idx);
-char          *mono_metadata_locate_token (metadata_t *meta, guint32 token);
-
-const char    *mono_metadata_string_heap  (metadata_t *meta, guint32 index);
-const char    *mono_metadata_blob_heap    (metadata_t *meta, guint32 index);
-const char    *mono_metadata_user_string  (metadata_t *meta, guint32 index);
+char          *mono_metadata_locate        (metadata_t *meta, int table, int idx);
+char          *mono_metadata_locate_token  (metadata_t *meta, guint32 token);
+                                          
+const char    *mono_metadata_string_heap   (metadata_t *meta, guint32 index);
+const char    *mono_metadata_blob_heap     (metadata_t *meta, guint32 index);
+const char    *mono_metadata_user_string   (metadata_t *meta, guint32 index);
 
+/*
+ * Functions to extract information from the Blobs
+ */
 const char  *mono_metadata_decode_value     (const char            *ptr,
                                              guint32               *len);
 const char  *mono_metadata_decode_blob_size (const char            *xptr,
                                              int                   *size);
-void         mono_metadata_decode_row       (metadata_tableinfo_t  *t,
-                                             int                    idx,
-                                             guint32               *res,
-                                             int                    res_size);
 
 typedef enum {
        MONO_META_EXCEPTION_CLAUSE_NONE,