[DBGHELP] set correct values in symt_fill_sym_info (SYMBOL_INFO).
[reactos.git] / dll / win32 / dbghelp / msc.c
index 73df739..07f3e3a 100644 (file)
  *     Add symbol size to internal symbol table.
  */
 
-#include "dbghelp_private.h"
+#define NONAMELESSUNION
 
-#include <wine/exception.h>
+#include "config.h"
+#include "wine/port.h"
 
-WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc);
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
 
-#define MAX_PATHNAME_LEN 1024
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <stdarg.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winternl.h"
+
+#include "wine/exception.h"
+#include "wine/debug.h"
+#include "dbghelp_private.h"
+#include "wine/mscvpdb.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc);
 
 struct pdb_stream_name
 {
@@ -151,6 +169,8 @@ static void codeview_init_basic_types(struct module* module)
     cv_basic_types[T_REAL80] = &symt_new_basic(module, btFloat, "long double", 10)->symt;
     cv_basic_types[T_RCHAR]  = &symt_new_basic(module, btInt,   "signed char", 1)->symt;
     cv_basic_types[T_WCHAR]  = &symt_new_basic(module, btWChar, "wchar_t", 2)->symt;
+    cv_basic_types[T_CHAR16] = &symt_new_basic(module, btChar16,"char16_t", 2)->symt;
+    cv_basic_types[T_CHAR32] = &symt_new_basic(module, btChar32,"char32_t", 4)->symt;
     cv_basic_types[T_INT2]   = &symt_new_basic(module, btInt,   "INT2", 2)->symt;
     cv_basic_types[T_UINT2]  = &symt_new_basic(module, btUInt,  "UINT2", 2)->symt;
     cv_basic_types[T_INT4]   = &symt_new_basic(module, btInt,   "INT4", 4)->symt;
@@ -177,6 +197,8 @@ static void codeview_init_basic_types(struct module* module)
     cv_basic_types[T_32PREAL80] = &symt_new_pointer(module, cv_basic_types[T_REAL80], 4)->symt;
     cv_basic_types[T_32PRCHAR]  = &symt_new_pointer(module, cv_basic_types[T_RCHAR], 4)->symt;
     cv_basic_types[T_32PWCHAR]  = &symt_new_pointer(module, cv_basic_types[T_WCHAR], 4)->symt;
+    cv_basic_types[T_32PCHAR16] = &symt_new_pointer(module, cv_basic_types[T_CHAR16], 4)->symt;
+    cv_basic_types[T_32PCHAR32] = &symt_new_pointer(module, cv_basic_types[T_CHAR32], 4)->symt;
     cv_basic_types[T_32PINT2]   = &symt_new_pointer(module, cv_basic_types[T_INT2], 4)->symt;
     cv_basic_types[T_32PUINT2]  = &symt_new_pointer(module, cv_basic_types[T_UINT2], 4)->symt;
     cv_basic_types[T_32PINT4]   = &symt_new_pointer(module, cv_basic_types[T_INT4], 4)->symt;
@@ -203,6 +225,8 @@ static void codeview_init_basic_types(struct module* module)
     cv_basic_types[T_64PREAL80] = &symt_new_pointer(module, cv_basic_types[T_REAL80], 8)->symt;
     cv_basic_types[T_64PRCHAR]  = &symt_new_pointer(module, cv_basic_types[T_RCHAR], 8)->symt;
     cv_basic_types[T_64PWCHAR]  = &symt_new_pointer(module, cv_basic_types[T_WCHAR], 8)->symt;
+    cv_basic_types[T_64PCHAR16] = &symt_new_pointer(module, cv_basic_types[T_CHAR16], 8)->symt;
+    cv_basic_types[T_64PCHAR32] = &symt_new_pointer(module, cv_basic_types[T_CHAR32], 8)->symt;
     cv_basic_types[T_64PINT2]   = &symt_new_pointer(module, cv_basic_types[T_INT2], 8)->symt;
     cv_basic_types[T_64PUINT2]  = &symt_new_pointer(module, cv_basic_types[T_UINT2], 8)->symt;
     cv_basic_types[T_64PINT4]   = &symt_new_pointer(module, cv_basic_types[T_INT4], 8)->symt;
@@ -210,6 +234,33 @@ static void codeview_init_basic_types(struct module* module)
     cv_basic_types[T_64PINT8]   = &symt_new_pointer(module, cv_basic_types[T_INT8], 8)->symt;
     cv_basic_types[T_64PUINT8]  = &symt_new_pointer(module, cv_basic_types[T_UINT8], 8)->symt;
     cv_basic_types[T_64PHRESULT]= &symt_new_pointer(module, cv_basic_types[T_HRESULT], 8)->symt;
+
+    cv_basic_types[T_PVOID]   = &symt_new_pointer(module, cv_basic_types[T_VOID],   sizeof(void*))->symt;
+    cv_basic_types[T_PCHAR]   = &symt_new_pointer(module, cv_basic_types[T_CHAR],   sizeof(void*))->symt;
+    cv_basic_types[T_PSHORT]  = &symt_new_pointer(module, cv_basic_types[T_SHORT],  sizeof(void*))->symt;
+    cv_basic_types[T_PLONG]   = &symt_new_pointer(module, cv_basic_types[T_LONG],   sizeof(void*))->symt;
+    cv_basic_types[T_PQUAD]   = &symt_new_pointer(module, cv_basic_types[T_QUAD],   sizeof(void*))->symt;
+    cv_basic_types[T_PUCHAR]  = &symt_new_pointer(module, cv_basic_types[T_UCHAR],  sizeof(void*))->symt;
+    cv_basic_types[T_PUSHORT] = &symt_new_pointer(module, cv_basic_types[T_USHORT], sizeof(void*))->symt;
+    cv_basic_types[T_PULONG]  = &symt_new_pointer(module, cv_basic_types[T_ULONG],  sizeof(void*))->symt;
+    cv_basic_types[T_PUQUAD]  = &symt_new_pointer(module, cv_basic_types[T_UQUAD],  sizeof(void*))->symt;
+    cv_basic_types[T_PBOOL08] = &symt_new_pointer(module, cv_basic_types[T_BOOL08], sizeof(void*))->symt;
+    cv_basic_types[T_PBOOL16] = &symt_new_pointer(module, cv_basic_types[T_BOOL16], sizeof(void*))->symt;
+    cv_basic_types[T_PBOOL32] = &symt_new_pointer(module, cv_basic_types[T_BOOL32], sizeof(void*))->symt;
+    cv_basic_types[T_PBOOL64] = &symt_new_pointer(module, cv_basic_types[T_BOOL64], sizeof(void*))->symt;
+    cv_basic_types[T_PREAL32] = &symt_new_pointer(module, cv_basic_types[T_REAL32], sizeof(void*))->symt;
+    cv_basic_types[T_PREAL64] = &symt_new_pointer(module, cv_basic_types[T_REAL64], sizeof(void*))->symt;
+    cv_basic_types[T_PREAL80] = &symt_new_pointer(module, cv_basic_types[T_REAL80], sizeof(void*))->symt;
+    cv_basic_types[T_PRCHAR]  = &symt_new_pointer(module, cv_basic_types[T_RCHAR],  sizeof(void*))->symt;
+    cv_basic_types[T_PWCHAR]  = &symt_new_pointer(module, cv_basic_types[T_WCHAR],  sizeof(void*))->symt;
+    cv_basic_types[T_PCHAR16] = &symt_new_pointer(module, cv_basic_types[T_CHAR16], sizeof(void*))->symt;
+    cv_basic_types[T_PCHAR32] = &symt_new_pointer(module, cv_basic_types[T_CHAR32], sizeof(void*))->symt;
+    cv_basic_types[T_PINT2]   = &symt_new_pointer(module, cv_basic_types[T_INT2],   sizeof(void*))->symt;
+    cv_basic_types[T_PUINT2]  = &symt_new_pointer(module, cv_basic_types[T_UINT2],  sizeof(void*))->symt;
+    cv_basic_types[T_PINT4]   = &symt_new_pointer(module, cv_basic_types[T_INT4],   sizeof(void*))->symt;
+    cv_basic_types[T_PUINT4]  = &symt_new_pointer(module, cv_basic_types[T_UINT4],  sizeof(void*))->symt;
+    cv_basic_types[T_PINT8]   = &symt_new_pointer(module, cv_basic_types[T_INT8],   sizeof(void*))->symt;
+    cv_basic_types[T_PUINT8]  = &symt_new_pointer(module, cv_basic_types[T_UINT8],  sizeof(void*))->symt;
 }
 
 static int leaf_as_variant(VARIANT* v, const unsigned short int* leaf)
@@ -631,9 +682,9 @@ static struct symt* codeview_add_type_array(struct codeview_type_parse* ctp,
     return &symt_new_array(ctp->module, 0, -arr_len, elem, index)->symt;
 }
 
-static int codeview_add_type_enum_field_list(struct module* module,
-                                             struct symt_enum* symt,
-                                             const union codeview_reftype* ref_type)
+static BOOL codeview_add_type_enum_field_list(struct module* module,
+                                              struct symt_enum* symt,
+                                              const union codeview_reftype* ref_type)
 {
     const unsigned char*                ptr = ref_type->fieldlist.list;
     const unsigned char*                last = (const BYTE*)ref_type + ref_type->generic.len + 2;
@@ -982,7 +1033,7 @@ static struct symt* codeview_add_type_struct(struct codeview_type_parse* ctp,
         hash_table_iter_init(&ctp->module->ht_types, &hti, name);
         while ((ptr = hash_table_iter_up(&hti)))
         {
-            type = GET_ENTRY(ptr, struct symt_ht, hash_elt);
+            type = CONTAINING_RECORD(ptr, struct symt_ht, hash_elt);
 
             if (type->symt.tag == SymTagUDT &&
                 type->hash_elt.name && !strcmp(type->hash_elt.name, name))
@@ -1307,12 +1358,12 @@ static struct symt* codeview_parse_one_type(struct codeview_type_parse* ctp,
     default:
         FIXME("Unsupported type-id leaf %x\n", type->generic.id);
         dump(type, 2 + type->generic.len);
-        return FALSE;
+        return NULL;
     }
     return codeview_add_type(curr_type, symt) ? symt : NULL;
 }
 
-static int codeview_parse_type_table(struct codeview_type_parse* ctp)
+static BOOL codeview_parse_type_table(struct codeview_type_parse* ctp)
 {
     unsigned int                curr_type = FIRST_DEFINABLE_TYPE;
     const union codeview_type*  type;
@@ -1537,8 +1588,8 @@ static inline void codeview_add_variable(const struct msc_debug_info* msc_dbg,
     }
 }
 
-static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root, 
-                          int offset, int size, BOOL do_globals)
+static BOOL codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root,
+                           int offset, int size, BOOL do_globals)
 {
     struct symt_function*               curr_func = NULL;
     int                                 i, length;
@@ -1962,13 +2013,24 @@ static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root
             break;
 
         /* the symbols we can safely ignore for now */
-        case 0x112c:
+        case S_TRAMPOLINE:
         case S_FRAMEINFO_V2:
         case S_SECUCOOKIE_V3:
         case S_SECTINFO_V3:
         case S_SUBSECTINFO_V3:
         case S_ENTRYPOINT_V3:
-        case 0x1139:
+        case S_LOCAL_VS2013:
+        case S_CALLSITEINFO:
+        case S_DEFRANGE_REGISTER:
+        case S_DEFRANGE_FRAMEPOINTER_REL:
+        case S_DEFRANGE_SUBFIELD_REGISTER:
+        case S_FPOFF_VS2013:
+        case S_DEFRANGE_REGISTER_REL:
+        case S_BUILDINFO:
+        case S_INLINESITE:
+        case S_INLINESITE_END:
+        case S_FILESTATIC:
+        case S_CALLEES:
             TRACE("Unsupported symbol id %x\n", sym->generic.id);
             break;
 
@@ -1984,8 +2046,8 @@ static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root
     return TRUE;
 }
 
-static int codeview_snarf_public(const struct msc_debug_info* msc_dbg, const BYTE* root,
-                                 int offset, int size)
+static BOOL codeview_snarf_public(const struct msc_debug_info* msc_dbg, const BYTE* root,
+                                  int offset, int size)
 
 {
     int                                 i, length;
@@ -2005,20 +2067,22 @@ static int codeview_snarf_public(const struct msc_debug_info* msc_dbg, const BYT
 
         switch (sym->generic.id)
         {
-       case S_PUB_V1: /* FIXME is this really a 'data_v1' structure ?? */
+       case S_PUB_V1:
             if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
             {
                 symt_new_public(msc_dbg->module, compiland,
-                                terminate_string(&sym->data_v1.p_name),
-                                codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset), 1);
+                                terminate_string(&sym->public_v1.p_name),
+                                sym->public_v1.symtype == SYMTYPE_FUNCTION,
+                                codeview_get_address(msc_dbg, sym->public_v1.segment, sym->public_v1.offset), 1);
             }
             break;
-       case S_PUB_V2: /* FIXME is this really a 'data_v2' structure ?? */
+       case S_PUB_V2:
             if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
             {
                 symt_new_public(msc_dbg->module, compiland,
-                                terminate_string(&sym->data_v2.p_name),
-                                codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset), 1);
+                                terminate_string(&sym->public_v2.p_name),
+                                sym->public_v3.symtype == SYMTYPE_FUNCTION,
+                                codeview_get_address(msc_dbg, sym->public_v2.segment, sym->public_v2.offset), 1);
             }
            break;
 
@@ -2026,8 +2090,9 @@ static int codeview_snarf_public(const struct msc_debug_info* msc_dbg, const BYT
             if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
             {
                 symt_new_public(msc_dbg->module, compiland,
-                                sym->data_v3.name,
-                                codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset), 1);
+                                sym->public_v3.name,
+                                sym->public_v3.symtype == SYMTYPE_FUNCTION,
+                                codeview_get_address(msc_dbg, sym->public_v3.segment, sym->public_v3.offset), 1);
             }
             break;
         case S_PUB_FUNC1_V3:
@@ -2219,7 +2284,7 @@ static void pdb_free_file(struct pdb_file_info* pdb_file)
     HeapFree(GetProcessHeap(), 0, pdb_file->stream_dict);
 }
 
-static BOOL pdb_load_stream_name_table(struct pdb_file_info* pdb_file, const char* str, unsigned cb)
+static void pdb_load_stream_name_table(struct pdb_file_info* pdb_file, const char* str, unsigned cb)
 {
     DWORD*      pdw;
     DWORD*      ok_bits;
@@ -2232,7 +2297,7 @@ static BOOL pdb_load_stream_name_table(struct pdb_file_info* pdb_file, const cha
     count = *pdw++;
 
     pdb_file->stream_dict = HeapAlloc(GetProcessHeap(), 0, (numok + 1) * sizeof(struct pdb_stream_name) + cb);
-    if (!pdb_file->stream_dict) return FALSE;
+    if (!pdb_file->stream_dict) return;
     cpstr = (char*)(pdb_file->stream_dict + numok + 1);
     memcpy(cpstr, str, cb);
 
@@ -2242,7 +2307,7 @@ static BOOL pdb_load_stream_name_table(struct pdb_file_info* pdb_file, const cha
     if (*pdw++ != 0)
     {
         FIXME("unexpected value\n");
-        return -1;
+        return;
     }
 
     for (i = j = 0; i < count; i++)
@@ -2258,7 +2323,6 @@ static BOOL pdb_load_stream_name_table(struct pdb_file_info* pdb_file, const cha
     /* add sentinel */
     pdb_file->stream_dict[numok].name = NULL;
     pdb_file->fpoext_stream = -1;
-    return j == numok && i == count;
 }
 
 static unsigned pdb_get_stream_by_name(const struct pdb_file_info* pdb_file, const char* name)
@@ -2389,11 +2453,11 @@ static HANDLE map_pdb_file(const struct process* pcs,
     switch (lookup->kind)
     {
     case PDB_JG:
-        ret = path_find_symbol_file(pcs, lookup->filename, NULL, lookup->timestamp,
+        ret = path_find_symbol_file(pcs, module, lookup->filename, NULL, lookup->timestamp,
                                     lookup->age, dbg_file_path, &module->module.PdbUnmatched);
         break;
     case PDB_DS:
-        ret = path_find_symbol_file(pcs, lookup->filename, &lookup->guid, 0,
+        ret = path_find_symbol_file(pcs, module, lookup->filename, &lookup->guid, 0,
                                     lookup->age, dbg_file_path, &module->module.PdbUnmatched);
         break;
     }
@@ -2619,7 +2683,7 @@ static void pdb_process_symbol_imports(const struct process* pcs,
         while (imp < (const PDB_SYMBOL_IMPORT*)last)
         {
             ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
-            if (i >= CV_MAX_MODULES) FIXME("Out of bounds !!!\n");
+            if (i >= CV_MAX_MODULES) FIXME("Out of bounds!!!\n");
             if (!strcasecmp(pdb_lookup->filename, imp->filename))
             {
                 if (module_index != -1) FIXME("Twice the entry\n");
@@ -2652,7 +2716,7 @@ static void pdb_process_symbol_imports(const struct process* pcs,
         pdb_module_info->used_subfiles = 1;
     }
     cv_current_module = &cv_zmodules[module_index];
-    if (cv_current_module->allowed) FIXME("Already allowed ??\n");
+    if (cv_current_module->allowed) FIXME("Already allowed??\n");
     cv_current_module->allowed = TRUE;
 }
 
@@ -2824,7 +2888,7 @@ static BOOL pdb_process_file(const struct process* pcs,
     if (ret)
     {
         struct pdb_module_info*     pdb_info = msc_dbg->module->format_info[DFI_PDB]->u.pdb_info;
-        msc_dbg->module->module.SymType = SymCv;
+        msc_dbg->module->module.SymType = SymPdb;
         if (pdb_info->pdb_files[0].kind == PDB_JG)
             msc_dbg->module->module.PdbSig = pdb_info->pdb_files[0].u.jg.timestamp;
         else
@@ -2900,8 +2964,8 @@ struct zvalue
     struct hash_table_elt       elt;
 };
 
-#define PEV_ERROR(pev, msg)       snprintf((pev)->error, sizeof((pev)->error), "%s", (msg)),FALSE
-#define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt)),FALSE
+#define PEV_ERROR(pev, msg)       snprintf((pev)->error, sizeof((pev)->error), "%s", (msg))
+#define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt))
 
 #if 0
 static void pev_dump_stack(struct pevaluator* pev)
@@ -2929,9 +2993,9 @@ static BOOL  pev_get_val(struct pevaluator* pev, const char* str, DWORD_PTR* val
         hash_table_iter_init(&pev->values, &hti, str);
         while ((ptr = hash_table_iter_up(&hti)))
         {
-            if (!strcmp(GET_ENTRY(ptr, struct zvalue, elt)->elt.name, str))
+            if (!strcmp(CONTAINING_RECORD(ptr, struct zvalue, elt)->elt.name, str))
             {
-                *val = GET_ENTRY(ptr, struct zvalue, elt)->value;
+                *val = CONTAINING_RECORD(ptr, struct zvalue, elt)->value;
                 return TRUE;
             }
         }
@@ -2984,9 +3048,9 @@ static BOOL  pev_set_value(struct pevaluator* pev, const char* name, DWORD_PTR v
     hash_table_iter_init(&pev->values, &hti, name);
     while ((ptr = hash_table_iter_up(&hti)))
     {
-        if (!strcmp(GET_ENTRY(ptr, struct zvalue, elt)->elt.name, name))
+        if (!strcmp(CONTAINING_RECORD(ptr, struct zvalue, elt)->elt.name, name))
         {
-            GET_ENTRY(ptr, struct zvalue, elt)->value = val;
+            CONTAINING_RECORD(ptr, struct zvalue, elt)->value = val;
             break;
         }
     }
@@ -3235,7 +3299,7 @@ static BOOL codeview_process_info(const struct process* pcs,
                 ctp.table  = (const BYTE*)(ctp.offset + types->cTypes);
 
                 cv_current_module = &cv_zmodules[0];
-                if (cv_current_module->allowed) FIXME("Already allowed ??\n");
+                if (cv_current_module->allowed) FIXME("Already allowed??\n");
                 cv_current_module->allowed = TRUE;
 
                 codeview_parse_type_table(&ctp);