msc.c 55.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/*
 *	MS debug info dumping utility
 *
 * 	Copyright 2006 Eric Pouech
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "config.h"
#include "wine/port.h"

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <time.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include <fcntl.h>

#include "windef.h"
#include "winbase.h"
#include "winedump.h"
#include "wine/mscvpdb.h"

#define PSTRING(adr, ofs) \
    ((const struct p_string*)((const char*)(adr) + (ofs)))

static const char* p_string(const struct p_string* s)
{
    static char tmp[256 + 1];
    memcpy(tmp, s->name, s->namelen);
    tmp[s->namelen] = '\0';
    return tmp;
}

58
struct full_value
59
{
60 61 62 63 64 65
    enum {fv_integer, fv_longlong} type;
    union
    {
        int                 i;
        long long unsigned  llu;
    } v;
66 67
};

68
static int full_numeric_leaf(struct full_value* fv, const unsigned short int* leaf)
69 70 71 72
{
    unsigned short int type = *leaf++;
    int length = 2;

73
    fv->type = fv_integer;
74 75
    if (type < LF_NUMERIC)
    {
76
        fv->v.i = type;
77 78 79 80 81 82 83
    }
    else
    {
        switch (type)
        {
        case LF_CHAR:
            length += 1;
84
            fv->v.i = *(const char*)leaf;
85 86 87 88
            break;

        case LF_SHORT:
            length += 2;
89
            fv->v.i = *(const short*)leaf;
90 91 92 93
            break;

        case LF_USHORT:
            length += 2;
94
            fv->v.i = *(const unsigned short*)leaf;
95 96 97 98
            break;

        case LF_LONG:
            length += 4;
99
            fv->v.i = *(const int*)leaf;
100 101 102 103
            break;

        case LF_ULONG:
            length += 4;
104
            fv->v.i = *(const unsigned int*)leaf;
105 106 107
            break;

        case LF_QUADWORD:
108
            length += 8;
109 110
            fv->type = fv_longlong;
            fv->v.llu = *(const long long int*)leaf;
111 112
            break;

113 114
        case LF_UQUADWORD:
            length += 8;
115 116
            fv->type = fv_longlong;
            fv->v.llu = *(const long long unsigned int*)leaf;
117 118 119 120
            break;

        case LF_REAL32:
            length += 4;
121
            printf(">>> unsupported leaf value %04x\n", type);
122
            fv->v.i = 0;    /* FIXME */
123 124 125 126
            break;

        case LF_REAL48:
            length += 6;
127
            fv->v.i = 0;    /* FIXME */
128
            printf(">>> unsupported leaf value %04x\n", type);
129 130 131 132
            break;

        case LF_REAL64:
            length += 8;
133
            fv->v.i = 0;    /* FIXME */
134
            printf(">>> unsupported leaf value %04x\n", type);
135 136 137 138
            break;

        case LF_REAL80:
            length += 10;
139
            fv->v.i = 0;    /* FIXME */
140
            printf(">>> unsupported leaf value %04x\n", type);
141 142 143 144
            break;

        case LF_REAL128:
            length += 16;
145
            fv->v.i = 0;    /* FIXME */
146
            printf(">>> unsupported leaf value %04x\n", type);
147 148 149 150
            break;

        case LF_COMPLEX32:
            length += 4;
151
            fv->v.i = 0;    /* FIXME */
152
            printf(">>> unsupported leaf value %04x\n", type);
153 154 155 156
            break;

        case LF_COMPLEX64:
            length += 8;
157
            fv->v.i = 0;    /* FIXME */
158
            printf(">>> unsupported leaf value %04x\n", type);
159 160 161 162
            break;

        case LF_COMPLEX80:
            length += 10;
163
            fv->v.i = 0;    /* FIXME */
164
            printf(">>> unsupported leaf value %04x\n", type);
165 166 167 168
            break;

        case LF_COMPLEX128:
            length += 16;
169
            fv->v.i = 0;    /* FIXME */
170
            printf(">>> unsupported leaf value %04x\n", type);
171 172 173 174
            break;

        case LF_VARSTRING:
            length += 2 + *leaf;
175
            fv->v.i = 0;    /* FIXME */
176
            printf(">>> unsupported leaf value %04x\n", type);
177 178 179 180
            break;

        default:
	    printf(">>> Unsupported numeric leaf-id %04x\n", type);
181
            fv->v.i = 0;
182 183 184 185 186 187
            break;
        }
    }
    return length;
}

188 189 190 191 192 193 194 195 196 197 198 199
static const char* full_value_string(const struct full_value* fv)
{
    static      char    tmp[128];

    switch (fv->type)
    {
    case fv_integer: sprintf(tmp, "0x%x", fv->v.i); break;
    case fv_longlong: sprintf(tmp, "0x%x%08x", (unsigned)(fv->v.llu >> 32), (unsigned)fv->v.llu); break;
    }
    return tmp;
}

200 201
static int numeric_leaf(int* value, const unsigned short int* leaf)
{
202
    struct full_value fv;
203
    int len = full_numeric_leaf(&fv, leaf);
204

205 206 207 208 209
    switch (fv.type)
    {
    case fv_integer: *value = fv.v.i; break;
    case fv_longlong: *value = (unsigned)fv.v.llu; printf("bad conversion\n"); break;
    }
210 211 212
    return len;
}

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
static const char* get_attr(unsigned attr)
{
    static char tmp[256];

    switch (attr & 3)
    {
    case 0: strcpy(tmp, ""); break;
    case 1: strcpy(tmp, "private "); break;
    case 2: strcpy(tmp, "protected "); break;
    case 3: strcpy(tmp, "public "); break;
    }
    switch ((attr >> 2) & 7)
    {
    case 0: strcat(tmp, ""); break;
    case 1: strcat(tmp, "virtual "); break;
    case 2: strcat(tmp, "static "); break;
    case 3: strcat(tmp, "friend "); break;
    case 4: strcat(tmp, "introducing virtual "); break;
    case 5: strcat(tmp, "pure virtual "); break;
    case 6: strcat(tmp, "pure introducing virtual "); break;
    case 7: strcat(tmp, "reserved "); break;
    }
    if ((attr >> 5) & 1) strcat(tmp, "pseudo ");
    if ((attr >> 6) & 1) strcat(tmp, "no-inherit ");
    if ((attr >> 7) & 1) strcat(tmp, "no-construct ");
    return tmp;
}

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
static const char* get_property(unsigned prop)
{
    static char tmp[1024];
    unsigned    pos = 0;

    if (!prop) return "none";
#define X(s) {if (pos) tmp[pos++] = ';'; strcpy(tmp + pos, s); pos += strlen(s);}
    if (prop & 0x0001) X("packed");
    if (prop & 0x0002) X("w/{cd}tor");
    if (prop & 0x0004) X("w/overloaded-ops");
    if (prop & 0x0008) X("nested-class");
    if (prop & 0x0010) X("has-nested-classes");
    if (prop & 0x0020) X("w/overloaded-assign");
    if (prop & 0x0040) X("w/casting-methods");
    if (prop & 0x0080) X("forward");
    if (prop & 0x0100) X("scoped");
#undef X

    if (prop & ~0x01FF) pos += sprintf(tmp, "unk%x", prop & ~0x01FF);
    else tmp[pos] = '\0';
    assert(pos < sizeof(tmp));

    return tmp;
}

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
static void do_field(const unsigned char* start, const unsigned char* end)
{
    /*
     * A 'field list' is a CodeView-specific data type which doesn't
     * directly correspond to any high-level data type.  It is used
     * to hold the collection of members of a struct, class, union
     * or enum type.  The actual definition of that type will follow
     * later, and refer to the field list definition record.
     *
     * As we don't have a field list type ourselves, we look ahead
     * in the field list to try to find out whether this field list
     * will be used for an enum or struct type, and create a dummy
     * type of the corresponding sort.  Later on, the definition of
     * the 'real' type will copy the member / enumeration data.
     */
    const unsigned char*        ptr = start;
    const char*                 cstr;
    const struct p_string*      pstr;
    int leaf_len, value;

    while (ptr < end)
    {
        const union codeview_fieldtype* fieldtype = (const union codeview_fieldtype*)ptr;

        if (*ptr >= 0xf0)       /* LF_PAD... */
        {
            ptr +=* ptr & 0x0f;
            continue;
        }

        switch (fieldtype->generic.id)
        {
        case LF_ENUMERATE_V1:
            leaf_len = numeric_leaf(&value, &fieldtype->enumerate_v1.value);
            pstr = PSTRING(&fieldtype->enumerate_v1.value, leaf_len);
            printf("\t\tEnumerate V1: '%s' value:%d\n",
                   p_string(pstr), value);
            ptr += 2 + 2 + leaf_len + 1 + pstr->namelen;
            break;

        case LF_ENUMERATE_V3:
            leaf_len = numeric_leaf(&value, &fieldtype->enumerate_v3.value);
            cstr = (const char*)&fieldtype->enumerate_v3.value + leaf_len;
            printf("\t\tEnumerate V3: '%s' value:%d\n",
                   cstr, value);
            ptr += 2 + 2 + leaf_len + strlen(cstr) + 1;
            break;

        case LF_MEMBER_V1:
            leaf_len = numeric_leaf(&value, &fieldtype->member_v1.offset);
            pstr = PSTRING(&fieldtype->member_v1.offset, leaf_len);
            printf("\t\tMember V1: '%s' type:%x attr:%s @%d\n",
                   p_string(pstr), fieldtype->member_v1.type,
                   get_attr(fieldtype->member_v1.attribute), value);
            ptr += 2 + 2 + 2 + leaf_len + 1 + pstr->namelen;
            break;

        case LF_MEMBER_V2:
            leaf_len = numeric_leaf(&value, &fieldtype->member_v2.offset);
            pstr = PSTRING(&fieldtype->member_v2.offset, leaf_len);
            printf("\t\tMember V2: '%s' type:%x attr:%s @%d\n",
                   p_string(pstr), fieldtype->member_v2.type,
                   get_attr(fieldtype->member_v2.attribute), value);
            ptr += 2 + 2 + 4 + leaf_len + 1 + pstr->namelen;
            break;

        case LF_MEMBER_V3:
            leaf_len = numeric_leaf(&value, &fieldtype->member_v3.offset);
            cstr = (const char*)&fieldtype->member_v3.offset + leaf_len;
            printf("\t\tMember V3: '%s' type:%x attr:%s @%d\n",
                   cstr, fieldtype->member_v3.type, 
                   get_attr(fieldtype->member_v3.attribute), value);
            ptr += 2 + 2 + 4 + leaf_len + strlen(cstr) + 1;
            break;

        case LF_ONEMETHOD_V1:
            switch ((fieldtype->onemethod_v1.attribute >> 2) & 7)
            {
            case 4: case 6:
                printf("\t\tVirtual-method V1: '%s' attr:%s type:%x vtable_offset:%u\n",
                       p_string(&fieldtype->onemethod_virt_v1.p_name),
                       get_attr(fieldtype->onemethod_virt_v1.attribute),
                       fieldtype->onemethod_virt_v1.type,
                       fieldtype->onemethod_virt_v1.vtab_offset);
                ptr += 2 + 2 + 2 + 4 + (1 + fieldtype->onemethod_virt_v1.p_name.namelen);
                break;

            default:
                printf("\t\tMethod V1: '%s' attr:%s type:%x\n",
                       p_string(&fieldtype->onemethod_v1.p_name),
                       get_attr(fieldtype->onemethod_v1.attribute),
                       fieldtype->onemethod_v1.type);
                ptr += 2 + 2 + 2 + (1 + fieldtype->onemethod_v1.p_name.namelen);
                break;
            }
            break;

        case LF_ONEMETHOD_V2:
            switch ((fieldtype->onemethod_v2.attribute >> 2) & 7)
            {
            case 4: case 6:
                printf("\t\tVirtual-method V2: '%s' attr:%s type:%x vtable_offset:%u\n",
                       p_string(&fieldtype->onemethod_virt_v2.p_name),
                       get_attr(fieldtype->onemethod_virt_v2.attribute),
                       fieldtype->onemethod_virt_v2.type,
                       fieldtype->onemethod_virt_v2.vtab_offset);
                ptr += 2 + 2 + 4 + 4 + (1 + fieldtype->onemethod_virt_v2.p_name.namelen);
                break;

            default:
                printf("\t\tMethod V2: '%s' attr:%s type:%x\n",
                       p_string(&fieldtype->onemethod_v2.p_name),
                       get_attr(fieldtype->onemethod_v2.attribute),
                       fieldtype->onemethod_v2.type);
                ptr += 2 + 2 + 4 + (1 + fieldtype->onemethod_v2.p_name.namelen);
                break;
            }
            break;

        case LF_ONEMETHOD_V3:
            switch ((fieldtype->onemethod_v3.attribute >> 2) & 7)
            {
            case 4: case 6:
                printf("\t\tVirtual-method V3: '%s' attr:%s type:%x vtable_offset:%u\n",
                       fieldtype->onemethod_virt_v3.name,
                       get_attr(fieldtype->onemethod_virt_v3.attribute),
                       fieldtype->onemethod_virt_v3.type,
                       fieldtype->onemethod_virt_v3.vtab_offset);
                ptr += 2 + 2 + 4 + 4 + (strlen(fieldtype->onemethod_virt_v3.name) + 1);
                break;

            default:
                printf("\t\tMethod V3: '%s' attr:%s type:%x\n",
                       fieldtype->onemethod_v3.name,
                       get_attr(fieldtype->onemethod_v3.attribute),
                       fieldtype->onemethod_v3.type);
                ptr += 2 + 2 + 4 + (strlen(fieldtype->onemethod_v3.name) + 1);
                break;
            }
            break;

        case LF_METHOD_V1:
            printf("\t\tMethod V1: '%s' overloaded=#%d method-list=%x\n",
                   p_string(&fieldtype->method_v1.p_name),
                   fieldtype->method_v1.count, fieldtype->method_v1.mlist);
            ptr += 2 + 2 + 2 + (1 + fieldtype->method_v1.p_name.namelen);
            break;

        case LF_METHOD_V2:
            printf("\t\tMethod V2: '%s' overloaded=#%d method-list=%x\n",
                   p_string(&fieldtype->method_v2.p_name),
                   fieldtype->method_v2.count, fieldtype->method_v2.mlist);
            ptr += 2 + 2 + 4 + (1 + fieldtype->method_v2.p_name.namelen);
            break;

        case LF_METHOD_V3:
            printf("\t\tMethod V3: '%s' overloaded=#%d method-list=%x\n",
                   fieldtype->method_v3.name,
                   fieldtype->method_v3.count, fieldtype->method_v3.mlist);
            ptr += 2 + 2 + 4 + (strlen(fieldtype->method_v3.name) + 1);
            break;

        case LF_STMEMBER_V1:
            printf("\t\tStatic member V1: '%s' attr:%s type:%x\n",
                   p_string(&fieldtype->stmember_v1.p_name),
                   get_attr(fieldtype->stmember_v1.attribute),
                   fieldtype->stmember_v1.type);
            ptr += 2 + 2 + 2 + (1 + fieldtype->stmember_v1.p_name.namelen);
            break;

        case LF_STMEMBER_V2:
            printf("\t\tStatic member V2: '%s' attr:%s type:%x\n",
                   p_string(&fieldtype->stmember_v2.p_name),
                   get_attr(fieldtype->stmember_v2.attribute),
                   fieldtype->stmember_v2.type);
            ptr += 2 + 2 + 4 + (1 + fieldtype->stmember_v2.p_name.namelen);
            break;

        case LF_STMEMBER_V3:
            printf("\t\tStatic member V3: '%s' attr:%s type:%x\n",
                   fieldtype->stmember_v3.name,
                   get_attr(fieldtype->stmember_v3.attribute),
                   fieldtype->stmember_v3.type);
            ptr += 2 + 2 + 4 + (strlen(fieldtype->stmember_v3.name) + 1);
            break;

        case LF_FRIENDFCN_V1:
            printf("\t\tFriend function V1: '%s' type:%x\n",
                   p_string(&fieldtype->friendfcn_v1.p_name),
                   fieldtype->friendfcn_v1.type);
            break;

        case LF_FRIENDFCN_V2:
            printf("\t\tFriend function V2: '%s' type:%x\n",
                   p_string(&fieldtype->friendfcn_v2.p_name),
                   fieldtype->friendfcn_v2.type);
            break;

#if 0
        case LF_FRIENDFCN_V3:
            printf("\t\tFriend function V3: '%s' type:%x\n",
                   fieldtype->friendfcn_v3.name,
                   fieldtype->friendfcn_v3.type);
            break;
#endif

        case LF_BCLASS_V1:
            leaf_len = numeric_leaf(&value, &fieldtype->bclass_v1.offset);
            printf("\t\tBase class V1: type:%x attr:%s @%d\n",
                   fieldtype->bclass_v1.type, 
                   get_attr(fieldtype->bclass_v1.attribute), value);
            ptr += 2 + 2 + 2 + leaf_len;
            break;

        case LF_BCLASS_V2:
            leaf_len = numeric_leaf(&value, &fieldtype->bclass_v2.offset);
            printf("\t\tBase class V2: type:%x attr:%s @%d\n",
                   fieldtype->bclass_v2.type, 
                   get_attr(fieldtype->bclass_v2.attribute), value);
            ptr += 2 + 2 + 4 + leaf_len;
            break;

        case LF_VBCLASS_V1:
        case LF_IVBCLASS_V1:
            leaf_len = numeric_leaf(&value, &fieldtype->vbclass_v1.vbpoff);
            printf("\t\t%sirtual base class V1: type:%x (ptr:%x) attr:%s vbpoff:%d ",
                   (fieldtype->generic.id == LF_VBCLASS_V2) ? "V" : "Indirect v",
                   fieldtype->vbclass_v1.btype, fieldtype->vbclass_v1.vbtype,
                   get_attr(fieldtype->vbclass_v1.attribute), value);
            ptr += 2 + 2 + 2 + 2 + leaf_len;
            leaf_len = numeric_leaf(&value, (const unsigned short*)ptr);
            printf("vboff:%d\n", value);
            ptr += leaf_len;
            break;

        case LF_VBCLASS_V2:
        case LF_IVBCLASS_V2:
            leaf_len = numeric_leaf(&value, &fieldtype->vbclass_v1.vbpoff);
            printf("\t\t%sirtual base class V2: type:%x (ptr:%x) attr:%s vbpoff:%d ",
                   (fieldtype->generic.id == LF_VBCLASS_V2) ? "V" : "Indirect v",
                   fieldtype->vbclass_v2.btype, fieldtype->vbclass_v2.vbtype,
                   get_attr(fieldtype->vbclass_v2.attribute), value);
            ptr += 2 + 2 + 4 + 4 + leaf_len;
            leaf_len = numeric_leaf(&value, (const unsigned short*)ptr);
            printf("vboff:%d\n", value);
            ptr += leaf_len;
            break;

        case LF_FRIENDCLS_V1:
            printf("\t\tFriend class V1: type:%x\n", fieldtype->friendcls_v1.type);
            break;

        case LF_FRIENDCLS_V2:
            printf("\t\tFriend class V2: type:%x\n", fieldtype->friendcls_v2.type);
            break;

        case LF_NESTTYPE_V1:
            printf("\t\tNested type V1: '%s' type:%x\n",
                   p_string(&fieldtype->nesttype_v1.p_name),
                   fieldtype->nesttype_v1.type);
            ptr += 2 + 2 + (1 + fieldtype->nesttype_v1.p_name.namelen);
            break;

        case LF_NESTTYPE_V2:
            printf("\t\tNested type V2: '%s' pad0:%u type:%x\n",
                   p_string(&fieldtype->nesttype_v2.p_name),
                   fieldtype->nesttype_v2._pad0, fieldtype->nesttype_v2.type);
            ptr += 2 + 2 + 4 + (1 + fieldtype->nesttype_v2.p_name.namelen);
            break;

        case LF_NESTTYPE_V3:
            printf("\t\tNested type V3: '%s' pad0:%u type:%x\n",
                   fieldtype->nesttype_v3.name,
                   fieldtype->nesttype_v3._pad0, fieldtype->nesttype_v3.type);
            ptr += 2 + 2 + 4 + (strlen(fieldtype->nesttype_v3.name) + 1);
            break;

        case LF_VFUNCTAB_V1:
            printf("\t\tVirtual function table V1: type:%x\n",
                   fieldtype->vfunctab_v1.type);
            ptr += 2 + 2;
            break;

        case LF_VFUNCTAB_V2:
            printf("\t\tVirtual function table V2: type:%x\n",
                   fieldtype->vfunctab_v2.type);
            ptr += 2 + 2 + 4;
            break;

        case LF_VFUNCOFF_V1:
            printf("\t\tVirtual function table offset V1: type:%x offset:%x\n",
                   fieldtype->vfuncoff_v1.type, fieldtype->vfuncoff_v1.offset);
            break;

        case LF_VFUNCOFF_V2:
            printf("\t\tVirtual function table offset V2: type:%x offset:%x\n",
                   fieldtype->vfuncoff_v2.type, fieldtype->vfuncoff_v2.offset);
            break;

        default:
            printf(">>> Unsupported field-id %x\n", fieldtype->generic.id);
            dump_data((const void*)fieldtype, 0x30, "\t");
            break;
        }
    }
}

573
static void codeview_dump_one_type(unsigned curr_type, const union codeview_type* type)
574
{
575
    const union codeview_reftype* reftype = (const union codeview_reftype*)type;
576
    int                 i, leaf_len, value;
577
    unsigned int        j;
578 579
    const char*         str;

580
    switch (type->generic.id)
581
    {
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
    case LF_POINTER_V1:
        printf("\t%x => Pointer V1 to type:%x\n",
               curr_type, type->pointer_v1.datatype);
        break;
    case LF_POINTER_V2:
        printf("\t%x => Pointer V2 to type:%x\n",
               curr_type, type->pointer_v2.datatype);
        break;
    case LF_ARRAY_V1:
        leaf_len = numeric_leaf(&value, &type->array_v1.arrlen);
        printf("\t%x => Array V1-'%s'[%u type:%x] type:%x\n",
               curr_type, p_string(PSTRING(&type->array_v1.arrlen, leaf_len)),
               value, type->array_v1.idxtype, type->array_v1.elemtype);
        break;
    case LF_ARRAY_V2:
        leaf_len = numeric_leaf(&value, &type->array_v2.arrlen);
        printf("\t%x => Array V2-'%s'[%u type:%x] type:%x\n",
               curr_type, p_string(PSTRING(&type->array_v2.arrlen, leaf_len)),
               value, type->array_v2.idxtype, type->array_v2.elemtype);
        break;
    case LF_ARRAY_V3:
        leaf_len = numeric_leaf(&value, &type->array_v3.arrlen);
        str = (const char*)&type->array_v3.arrlen + leaf_len;
        printf("\t%x => Array V3-'%s'[%u type:%x] type:%x\n",
               curr_type, str, value,
               type->array_v3.idxtype, type->array_v3.elemtype);
        break;

    /* a bitfields is a CodeView specific data type which represent a bitfield
     * in a structure or a class. For now, we store it in a SymTag-like type
     * (so that the rest of the process is seamless), but check at udt inclusion
     * type for its presence
     */
    case LF_BITFIELD_V1:
        printf("\t%x => Bitfield V1:%x offset:%u #bits:%u\n",
               curr_type, reftype->bitfield_v1.type, reftype->bitfield_v1.bitoff,
               reftype->bitfield_v1.nbits);
        break;

    case LF_BITFIELD_V2:
        printf("\t%x => Bitfield V2:%x offset:%u #bits:%u\n",
               curr_type, reftype->bitfield_v2.type, reftype->bitfield_v2.bitoff,
               reftype->bitfield_v2.nbits);
        break;

    case LF_FIELDLIST_V1:
    case LF_FIELDLIST_V2:
        printf("\t%x => Fieldlist\n", curr_type);
        do_field(reftype->fieldlist.list, (const BYTE*)type + reftype->generic.len + 2);
        break;

    case LF_STRUCTURE_V1:
    case LF_CLASS_V1:
        leaf_len = numeric_leaf(&value, &type->struct_v1.structlen);
636
        printf("\t%x => %s V1 '%s' elts:%u property:%s fieldlist-type:%x derived-type:%x vshape:%x size:%u\n",
637 638
               curr_type, type->generic.id == LF_CLASS_V1 ? "Class" : "Struct",
               p_string(PSTRING(&type->struct_v1.structlen, leaf_len)),
639
               type->struct_v1.n_element, get_property(type->struct_v1.property),
640 641 642 643 644 645 646
               type->struct_v1.fieldlist, type->struct_v1.derived,
               type->struct_v1.vshape, value);
        break;

    case LF_STRUCTURE_V2:
    case LF_CLASS_V2:
        leaf_len = numeric_leaf(&value, &type->struct_v2.structlen);
647
        printf("\t%x => %s V2 '%s' elts:%u property:%s\n"
648 649 650
               "                fieldlist-type:%x derived-type:%x vshape:%x size:%u\n",
               curr_type, type->generic.id == LF_CLASS_V2 ? "Class" : "Struct",
               p_string(PSTRING(&type->struct_v2.structlen, leaf_len)),
651
               type->struct_v2.n_element, get_property(type->struct_v2.property),
652 653 654 655 656 657 658 659
               type->struct_v2.fieldlist, type->struct_v2.derived,
               type->struct_v2.vshape, value);
        break;

    case LF_STRUCTURE_V3:
    case LF_CLASS_V3:
        leaf_len = numeric_leaf(&value, &type->struct_v3.structlen);
        str = (const char*)&type->struct_v3.structlen + leaf_len;
660
        printf("\t%x => %s V3 '%s' elts:%u property:%s\n"
661 662
               "                fieldlist-type:%x derived-type:%x vshape:%x size:%u\n",
               curr_type, type->generic.id == LF_CLASS_V3 ? "Class" : "Struct",
663
               str, type->struct_v3.n_element, get_property(type->struct_v3.property),
664 665 666 667 668 669
               type->struct_v3.fieldlist, type->struct_v3.derived,
               type->struct_v3.vshape, value);
        break;

    case LF_UNION_V1:
        leaf_len = numeric_leaf(&value, &type->union_v1.un_len);
670
        printf("\t%x => Union V1 '%s' count:%u property:%s fieldlist-type:%x size:%u\n",
671
               curr_type, p_string(PSTRING(&type->union_v1.un_len, leaf_len)),
672
               type->union_v1.count, get_property(type->union_v1.property),
673 674 675 676 677
               type->union_v1.fieldlist, value);
        break;

    case LF_UNION_V2:
        leaf_len = numeric_leaf(&value, &type->union_v2.un_len);
678
        printf("\t%x => Union V2 '%s' count:%u property:%s fieldlist-type:%x size:%u\n",
679
               curr_type, p_string(PSTRING(&type->union_v2.un_len, leaf_len)),
680
               type->union_v2.count, get_property(type->union_v2.property),
681 682 683 684 685 686
               type->union_v2.fieldlist, value);
        break;

    case LF_UNION_V3:
        leaf_len = numeric_leaf(&value, &type->union_v3.un_len);
        str = (const char*)&type->union_v3.un_len + leaf_len;
687
        printf("\t%x => Union V3 '%s' count:%u property:%s fieldlist-type:%x size:%u\n",
688
               curr_type, str, type->union_v3.count,
689 690
               get_property(type->union_v3.property),
               type->union_v3.fieldlist, value);
691 692 693
        break;

    case LF_ENUM_V1:
694
        printf("\t%x => Enum V1 '%s' type:%x field-type:%x count:%u property:%s\n",
695 696 697 698
               curr_type, p_string(&type->enumeration_v1.p_name),
               type->enumeration_v1.type,
               type->enumeration_v1.fieldlist,
               type->enumeration_v1.count,
699
               get_property(type->enumeration_v1.property));
700 701 702
        break;

    case LF_ENUM_V2:
703
        printf("\t%x => Enum V2 '%s' type:%x field-type:%x count:%u property:%s\n",
704 705 706 707
               curr_type, p_string(&type->enumeration_v2.p_name),
               type->enumeration_v2.type,
               type->enumeration_v2.fieldlist,
               type->enumeration_v2.count,
708
               get_property(type->enumeration_v2.property));
709 710 711
        break;

    case LF_ENUM_V3:
712
        printf("\t%x => Enum V3 '%s' type:%x field-type:%x count:%u property:%s\n",
713 714 715 716
               curr_type, type->enumeration_v3.name,
               type->enumeration_v3.type,
               type->enumeration_v3.fieldlist,
               type->enumeration_v3.count,
717
               get_property(type->enumeration_v3.property));
718 719 720 721 722
        break;

    case LF_ARGLIST_V1:
        printf("\t%x => Arglist V1(#%u):", curr_type, reftype->arglist_v1.num);
        for (i = 0; i < reftype->arglist_v1.num; i++)
723
        {
724 725 726 727
            printf(" %x", reftype->arglist_v1.args[i]);
        }
        printf("\n");
        break;
728

729 730
    case LF_ARGLIST_V2:
        printf("\t%x => Arglist V2(#%u):", curr_type, reftype->arglist_v2.num);
731
        for (j = 0; j < reftype->arglist_v2.num; j++)
732
        {
733
            printf("\t %x", reftype->arglist_v2.args[j]);
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
        }
        printf("\t\n");
        break;

    case LF_PROCEDURE_V1:
        /* FIXME: unknown could be the calling convention for the proc */
        printf("\t%x => Procedure V1 ret_type:%x call:%x (#%u args_type:%x)\n",
               curr_type, type->procedure_v1.rvtype,
               type->procedure_v1.call, type->procedure_v1.params,
               type->procedure_v1.arglist);
        break;

    case LF_PROCEDURE_V2:
        printf("\t%x => Procedure V2 ret_type:%x unk:%x (#%u args_type:%x)\n",
               curr_type, type->procedure_v2.rvtype,
               type->procedure_v2.call, type->procedure_v2.params,
               type->procedure_v2.arglist);
        break;

    case LF_MFUNCTION_V2:
        printf("\t%x => MFunction V2 ret-type:%x call:%x class-type:%x this-type:%x\n"
               "\t\t#args:%x args-type:%x this_adjust:%x\n",
               curr_type,
               type->mfunction_v2.rvtype,
               type->mfunction_v2.call,
               type->mfunction_v2.class_type,
               type->mfunction_v2.this_type,
               type->mfunction_v2.params,
               type->mfunction_v2.arglist,
               type->mfunction_v2.this_adjust);
        break;

    case LF_MODIFIER_V1:
        printf("\t%x => Modifier V1 type:%x modif:%x\n",
               curr_type, type->modifier_v1.type, type->modifier_v1.attribute);
        break;

    case LF_MODIFIER_V2:
        printf("\t%x => Modifier V2 type:%x modif:%x\n",
               curr_type, type->modifier_v2.type, type->modifier_v2.attribute);
        break;

    case LF_METHODLIST_V1:
        {
            const unsigned short* pattr = (const unsigned short*)((const char*)type + 4);
779

780 781
            printf("\t%x => Method list\n", curr_type);
            while ((const char*)pattr < (const char*)type + type->generic.len + 2)
782
            {
783
                switch ((*pattr >> 2) & 7)
784
                {
785 786 787 788 789 790 791 792 793 794
                case 4: case 6:
                    printf("\t\t\tattr:%s type:%x vtab-offset:%x\n",
                           get_attr(pattr[0]), pattr[1],
                           *(const unsigned*)(&pattr[2]));
                    pattr += 3;
                    break;
                default:
                    printf("\t\t\tattr:%s type:%x\n",
                           get_attr(pattr[0]), pattr[1]);
                    pattr += 2;
795 796
                }
            }
797 798
        }
        break;
799

800 801 802
    case LF_METHODLIST_V2:
        {
            const unsigned* pattr = (const unsigned*)((const char*)type + 4);
803

804 805 806 807
            printf("\t%x => Method list\n", curr_type);
            while ((const char*)pattr < (const char*)type + type->generic.len + 2)
            {
                switch ((*pattr >> 2) & 7)
808
                {
809 810 811 812 813 814 815 816 817
                case 4: case 6:
                    printf("\t\t\tattr:%s type:%x vtab-offset:%x\n",
                           get_attr(pattr[0]), pattr[1], pattr[2]);
                    pattr += 3;
                    break;
                default:
                    printf("\t\t\tattr:%s type:%x\n",
                           get_attr(pattr[0]), pattr[1]);
                    pattr += 2;
818 819
                }
            }
820 821
        }
        break;
822

823 824 825 826 827 828 829 830 831
    case LF_VTSHAPE_V1:
        {
            int count = *(const unsigned short*)((const char*)type + 4);
            int shift = 0;
            const char* ptr = (const char*)type + 6;
            const char* desc[] = {"Near", "Far", "Thin", "Disp to outtermost",
                                  "Pointer to metaclass", "Near32", "Far32"};
            printf("\t%x => VT Shape #%d: ", curr_type, count);
            while (count--)
832
            {
833 834 835 836 837
                if (((*ptr << shift) & 0xF) <= 6)
                    printf("%s ", desc[(*ptr << shift) & 0xF]);
                else
                    printf("%x ", (*ptr << shift) & 0xF);
                if (shift == 0) shift = 4; else {shift = 0; ptr++;}
838
            }
839
            printf("\n");
840
        }
841
        break;
842

843 844 845 846 847 848 849 850 851 852 853
    case LF_DERIVED_V1:
        printf("\t%x => Derived V1(#%u):", curr_type, reftype->derived_v1.num);
        for (i = 0; i < reftype->derived_v1.num; i++)
        {
            printf(" %x", reftype->derived_v1.drvdcls[i]);
        }
        printf("\n");
        break;

    case LF_DERIVED_V2:
        printf("\t%x => Derived V2(#%u):", curr_type, reftype->derived_v2.num);
854
        for (j = 0; j < reftype->derived_v2.num; j++)
855
        {
856
            printf(" %x", reftype->derived_v2.drvdcls[j]);
857 858 859 860
        }
        printf("\n");
        break;

861 862 863 864 865 866 867
    default:
        printf(">>> Unsupported type-id %x for %x\n", type->generic.id, curr_type);
        dump_data((const void*)type, type->generic.len + 2, "");
        break;
    }
}

868
BOOL codeview_dump_types_from_offsets(const void* table, const DWORD* offsets, unsigned num_types)
869 870 871 872 873 874 875 876 877 878 879 880
{
    unsigned long i;

    for (i = 0; i < num_types; i++)
    {
        codeview_dump_one_type(0x1000 + i,
                               (const union codeview_type*)((const char*)table + offsets[i]));
    }

    return TRUE;
}

881
BOOL codeview_dump_types_from_block(const void* table, unsigned long len)
882 883 884 885 886 887 888
{
    unsigned int        curr_type = 0x1000;
    const unsigned char*ptr = table;

    while (ptr - (const unsigned char*)table < len)
    {
        const union codeview_type* type = (const union codeview_type*)ptr;
889

890
        codeview_dump_one_type(curr_type, type);
891
        curr_type++;
892
        ptr += (type->generic.len + 2 + 3) & ~3;
893 894 895 896 897
    }

    return TRUE;
}

898
BOOL codeview_dump_symbols(const void* root, unsigned long size)
899
{
900 901 902 903
    unsigned int i;
    int          length;
    char*        curr_func = NULL;
    int          nest_block = 0;
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
    /*
     * Loop over the different types of records and whenever we
     * find something we are interested in, record it and move on.
     */
    for (i = 0; i < size; i += length)
    {
        const union codeview_symbol* sym = (const union codeview_symbol*)((const char*)root + i);
        length = sym->generic.len + 2;
        if (!sym->generic.id || length < 4) break;
        switch (sym->generic.id)
        {
        /*
         * Global and local data symbols.  We don't associate these
         * with any given source file.
         */
	case S_GDATA_V2:
	case S_LDATA_V2:
921
            printf("\tS-%s-Data V2 '%s' %04x:%08x type:%08x\n",
922
                   sym->generic.id == S_GDATA_V2 ? "Global" : "Local",
923
                   get_symbol_str(p_string(&sym->data_v2.p_name)),
924 925 926 927 928 929 930 931
                   sym->data_v2.segment, sym->data_v2.offset, sym->data_v2.symtype);
	    break;

        case S_LDATA_V3:
        case S_GDATA_V3:
/* EPP         case S_DATA_V3: */
            printf("\tS-%s-Data V3 '%s' (%04x:%08x) type:%08x\n",
                   sym->generic.id == S_GDATA_V3 ? "Global" : "Local",
932 933
                   get_symbol_str(sym->data_v3.name),
                   sym->data_v3.segment, sym->data_v3.offset,
934 935 936 937 938
                   sym->data_v3.symtype);
            break;

	case S_PUB_V2:
            printf("\tS-Public V2 '%s' %04x:%08x type:%08x\n",
939
                   get_symbol_str(p_string(&sym->public_v2.p_name)),
940 941 942 943 944
                   sym->public_v2.segment, sym->public_v2.offset,
                   sym->public_v2.symtype);
	    break;

	case S_PUB_V3:
945
        /* not completely sure of those two anyway */
946 947 948 949 950
	case S_PUB_FUNC1_V3:
	case S_PUB_FUNC2_V3:
            printf("\tS-Public%s V3 '%s' %04x:%08x type:%08x\n",
                   sym->generic.id == S_PUB_V3 ? "" :
                                      (sym->generic.id == S_PUB_FUNC1_V3 ? "<subkind1" : "<subkind2"),
951
                   get_symbol_str(sym->public_v3.name),
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
                   sym->public_v3.segment,
                   sym->public_v3.offset, sym->public_v3.symtype);
	    break;

        /*
         * Sort of like a global function, but it just points
         * to a thunk, which is a stupid name for what amounts to
         * a PLT slot in the normal jargon that everyone else uses.
         */
	case S_THUNK_V1:
            printf("\tS-Thunk V1 '%s' (%04x:%08x#%x) type:%x\n", 
                   p_string(&sym->thunk_v1.p_name),
                   sym->thunk_v1.segment, sym->thunk_v1.offset,
                   sym->thunk_v1.thunk_len, sym->thunk_v1.thtype);
            curr_func = strdup(p_string(&sym->thunk_v1.p_name));
	    break;

	case S_THUNK_V3:
            printf("\tS-Thunk V3 '%s' (%04x:%08x#%x) type:%x\n", 
                   sym->thunk_v3.name,
                   sym->thunk_v3.segment, sym->thunk_v3.offset,
                   sym->thunk_v3.thunk_len, sym->thunk_v3.thtype);
            curr_func = strdup(sym->thunk_v3.name);
	    break;

        /* Global and static functions */
	case S_GPROC_V1:
	case S_LPROC_V1:
980
            printf("\tS-%s-Proc V1: '%s' (%04x:%08x#%x) type:%x attr:%x\n",
981 982 983
                   sym->generic.id == S_GPROC_V1 ? "Global" : "-Local",
                   p_string(&sym->proc_v1.p_name),
                   sym->proc_v1.segment, sym->proc_v1.offset,
984 985 986 987
                   sym->proc_v1.proc_len, sym->proc_v1.proctype,
                   sym->proc_v1.flags);
            printf("\t  Debug: start=%08x end=%08x\n",
                   sym->proc_v1.debug_start, sym->proc_v1.debug_end);
988 989 990 991 992 993 994 995 996 997 998 999 1000
            if (nest_block)
            {
                printf(">>> prev func '%s' still has nest_block %u count\n", curr_func, nest_block);
                nest_block = 0;
            }
            curr_func = strdup(p_string(&sym->proc_v1.p_name));
/* EPP 	unsigned int	pparent; */
/* EPP 	unsigned int	pend; */
/* EPP 	unsigned int	next; */
	    break;

	case S_GPROC_V2:
	case S_LPROC_V2:
1001
            printf("\tS-%s-Proc V2: '%s' (%04x:%08x#%x) type:%x attr:%x\n",
1002 1003 1004
                   sym->generic.id == S_GPROC_V2 ? "Global" : "-Local",
                   p_string(&sym->proc_v2.p_name),
                   sym->proc_v2.segment, sym->proc_v2.offset,
1005 1006 1007 1008
                   sym->proc_v2.proc_len, sym->proc_v2.proctype,
                   sym->proc_v2.flags);
            printf("\t  Debug: start=%08x end=%08x\n",
                   sym->proc_v2.debug_start, sym->proc_v2.debug_end);
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
            if (nest_block)
            {
                printf(">>> prev func '%s' still has nest_block %u count\n", curr_func, nest_block);
                nest_block = 0;
            }
            curr_func = strdup(p_string(&sym->proc_v2.p_name));
/* EPP 	unsigned int	pparent; */
/* EPP 	unsigned int	pend; */
/* EPP 	unsigned int	next; */
	    break;

        case S_LPROC_V3:
        case S_GPROC_V3:
1022
            printf("\tS-%s-Procedure V3 '%s' (%04x:%08x#%x) type:%x attr:%x\n",
1023 1024 1025
                   sym->generic.id == S_GPROC_V3 ? "Global" : "Local",
                   sym->proc_v3.name,
                   sym->proc_v3.segment, sym->proc_v3.offset,
1026 1027 1028 1029
                   sym->proc_v3.proc_len, sym->proc_v3.proctype,
                   sym->proc_v3.flags);
            printf("\t  Debug: start=%08x end=%08x\n",
                   sym->proc_v3.debug_start, sym->proc_v3.debug_end);
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
            if (nest_block)
            {
                printf(">>> prev func '%s' still has nest_block %u count\n", curr_func, nest_block);
                nest_block = 0;
            }
            curr_func = strdup(sym->proc_v3.name);
/* EPP 	unsigned int	pparent; */
/* EPP 	unsigned int	pend; */
/* EPP 	unsigned int	next; */
            break;

        /* Function parameters and stack variables */
	case S_BPREL_V1:
            printf("\tS-BP-relative V1: '%s' @%d type:%x (%s)\n", 
                   p_string(&sym->stack_v1.p_name),
                   sym->stack_v1.offset, sym->stack_v1.symtype, curr_func);
            break;

	case S_BPREL_V2:
            printf("\tS-BP-relative V2: '%s' @%d type:%x (%s)\n", 
                   p_string(&sym->stack_v2.p_name),
                   sym->stack_v2.offset, sym->stack_v2.symtype, curr_func);
            break;

        case S_BPREL_V3:
            printf("\tS-BP-relative V3: '%s' @%d type:%x (in %s)\n", 
                   sym->stack_v3.name, sym->stack_v3.offset,
                   sym->stack_v3.symtype, curr_func);
            break;
1059

1060 1061 1062 1063
        case S_REGREL_V3:
            printf("\tS-Reg-relative V3: '%s' @%d type:%x reg:%x (in %s)\n",
                   sym->regrel_v3.name, sym->regrel_v3.offset,
                   sym->regrel_v3.symtype, sym->regrel_v3.reg, curr_func);
1064
            break;
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100

        case S_REGISTER_V1:
            printf("\tS-Register V1 '%s' in %s type:%x register:%x\n",
                   p_string(&sym->register_v1.p_name),
                   curr_func, sym->register_v1.reg, sym->register_v1.type);
            break;

        case S_REGISTER_V2:
            printf("\tS-Register V2 '%s' in %s type:%x register:%x\n",
                   p_string(&sym->register_v2.p_name),
                   curr_func, sym->register_v2.reg, sym->register_v2.type);
            break;

        case S_REGISTER_V3:
            printf("\tS-Register V3 '%s' in %s type:%x register:%x\n",
                   sym->register_v3.name,
                   curr_func, sym->register_v3.reg, sym->register_v3.type);
            break;

        case S_BLOCK_V1:
            printf("\tS-Block V1 '%s' in '%s' (%04x:%08x#%08x)\n",
                   p_string(&sym->block_v1.p_name),
                   curr_func, 
                   sym->block_v1.segment, sym->block_v1.offset,
                   sym->block_v1.length);
            nest_block++;
            break;

        case S_BLOCK_V3:
            printf("\tS-Block V3 '%s' in '%s' (%04x:%08x#%08x) parent:%u end:%x\n",
                   sym->block_v3.name, curr_func, 
                   sym->block_v3.segment, sym->block_v3.offset, sym->block_v3.length,
                   sym->block_v3.parent, sym->block_v3.end);
            nest_block++;
            break;

1101
        /* Additional function information */
1102 1103 1104 1105 1106 1107 1108 1109 1110
        case S_FRAMEINFO_V2:
            printf("\tS-Frame-Info V2: frame-size:%x unk2:%x unk3:%x saved-regs-sz:%x eh(%04x:%08x) flags:%08x\n",
                   sym->frame_info_v2.sz_frame,
                   sym->frame_info_v2.unknown2,
                   sym->frame_info_v2.unknown3,
                   sym->frame_info_v2.sz_saved_regs,
                   sym->frame_info_v2.eh_sect,
                   sym->frame_info_v2.eh_offset,
                   sym->frame_info_v2.flags);
1111 1112
            break;

1113 1114 1115 1116 1117
        case S_SECUCOOKIE_V3:
            printf("\tSecurity Cookie V3 @%d unk:%x\n",
                   sym->security_cookie_v3.offset, sym->security_cookie_v3.unknown);
            break;

1118 1119 1120 1121 1122 1123 1124 1125 1126
        case S_END_V1:
            if (nest_block)
            {
                nest_block--;
                printf("\tS-End-Of block (%u)\n", nest_block);
            }
            else
            {
                printf("\tS-End-Of %s\n", curr_func);
1127
                free(curr_func);
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
                curr_func = NULL;
            }
            break;

        case S_COMPILAND_V1:
            {
                const char*     machine;
                const char*     lang;

                switch (sym->compiland_v1.unknown & 0xFF)
                {
                case 0x00:      machine = "Intel 8080"; break;
                case 0x01:      machine = "Intel 8086"; break;
                case 0x02:      machine = "Intel 80286"; break;
                case 0x03:      machine = "Intel 80386"; break;
                case 0x04:      machine = "Intel 80486"; break;
                case 0x05:      machine = "Intel Pentium"; break;
                case 0x10:      machine = "MIPS R4000"; break;
                default:
                    {
                        static char tmp[16];
                        sprintf(tmp, "machine=%x", sym->compiland_v1.unknown & 0xFF);
                        machine = tmp;
                    }
                    break;
                }
                switch ((sym->compiland_v1.unknown >> 8) & 0xFF)
                {
                case 0x00:      lang = "C"; break;
                case 0x01:      lang = "C++"; break;
                case 0x02:      lang = "Fortran"; break;
                case 0x03:      lang = "Masm"; break;
                case 0x04:      lang = "Pascal"; break;
                case 0x05:      lang = "Basic"; break;
                case 0x06:      lang = "Cobol"; break;
                default:
                    {
                        static char tmp[16];
                        sprintf(tmp, "language=%x", (sym->compiland_v1.unknown >> 8) & 0xFF);
                        lang = tmp;
                    }
                    break;
                }

                printf("\tS-Compiland V1 '%s' %s %s unk:%x\n",
                       p_string(&sym->compiland_v1.p_name), machine, lang,
                       sym->compiland_v1.unknown >> 16);
            }
            break;

        case S_COMPILAND_V2:
            printf("\tS-Compiland V2 '%s'\n",
                   p_string(&sym->compiland_v2.p_name));
            dump_data((const void*)sym, sym->generic.len + 2, "  ");
            {
                const char* ptr = sym->compiland_v2.p_name.name + sym->compiland_v2.p_name.namelen;
                while (*ptr)
                {
                    printf("\t\t%s => ", ptr); ptr += strlen(ptr) + 1;
                    printf("%s\n", ptr); ptr += strlen(ptr) + 1;
                }
            }
            break;

        case S_COMPILAND_V3:
            printf("\tS-Compiland V3 '%s' unknown:%x\n",
                   sym->compiland_v3.name, sym->compiland_v3.unknown);
            break;

        case S_OBJNAME_V1:
            printf("\tS-ObjName V1 sig:%.4s '%s'\n",
                   sym->objname_v1.signature, p_string(&sym->objname_v1.p_name));
            break;

        case S_LABEL_V1:
            printf("\tS-Label V1 '%s' in '%s' (%04x:%08x)\n", 
                   p_string(&sym->label_v1.p_name),     
                   curr_func, sym->label_v1.segment, sym->label_v1.offset);
            break;

        case S_LABEL_V3:
            printf("\tS-Label V3 '%s' in '%s' (%04x:%08x) flag:%x\n", 
                   sym->label_v3.name, curr_func, sym->label_v3.segment,
                   sym->label_v3.offset, sym->label_v3.flags);
            break;

        case S_CONSTANT_V2:
            {
1216
                int             vlen;
1217
                struct full_value fv;
1218

1219
                vlen = full_numeric_leaf(&fv, &sym->constant_v2.cvalue);
1220
                printf("\tS-Constant V2 '%s' = %s type:%x\n",
1221
                       p_string(PSTRING(&sym->constant_v2.cvalue, vlen)),
1222
                       full_value_string(&fv), sym->constant_v2.type);
1223 1224 1225 1226 1227
            }
            break;

        case S_CONSTANT_V3:
            {
1228
                int             vlen;
1229
                struct full_value fv;
1230

1231
                vlen = full_numeric_leaf(&fv, &sym->constant_v3.cvalue);
1232
                printf("\tS-Constant V3 '%s' =  %s type:%x\n",
1233
                       (const char*)&sym->constant_v3.cvalue + vlen,
1234
                       full_value_string(&fv), sym->constant_v3.type);
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
            }
            break;

        case S_UDT_V1:
            printf("\tS-Udt V1 '%s': type:0x%x\n", 
                   p_string(&sym->udt_v1.p_name), sym->udt_v1.type);
            break;

        case S_UDT_V2:
            printf("\tS-Udt V2 '%s': type:0x%x\n", 
                   p_string(&sym->udt_v2.p_name), sym->udt_v2.type);
            break;

        case S_UDT_V3:
            printf("\tS-Udt V3 '%s': type:0x%x\n",
                   sym->udt_v3.name, sym->udt_v3.type);
            break;
        /*
         * These are special, in that they are always followed by an
         * additional length-prefixed string which is *not* included
         * into the symbol length count.  We need to skip it.
         */
	case S_PROCREF_V1:
            printf("\tS-Procref V1 "); goto doaref;
	case S_DATAREF_V1:
            printf("\tS-Dataref V1 "); goto doaref;
	case S_LPROCREF_V1:
            printf("\tS-L-Procref V1 "); goto doaref;
        doaref:
            {
                const struct p_string* pname;

                pname = PSTRING(sym, length);
                length += (pname->namelen + 1 + 3) & ~3;
1269 1270
                printf("\t%08x %08x %08x '%s'\n",
                       *(((const DWORD*)sym) + 1), *(((const DWORD*)sym) + 2), *(((const DWORD*)sym) + 3),
1271 1272 1273 1274 1275
                       p_string(pname));
            }
            break;
        case S_MSTOOL_V3:    /* info about tool used to create CU */
            {
1276 1277 1278
                const unsigned short*   ptr = ((const unsigned short*)sym) + 2;
                const char*             x1;
                const char*             x2 = (const char*)&ptr[9];
1279
                /* FIXME: what are all those values for ? */
1280
                printf("\tTool V3 unk=%04x%04x%04x front=%d.%d.%d.0 back=%d.%d.%d.0 %s\n",
1281
                       ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7],
1282 1283 1284 1285 1286 1287 1288
                       ptr[8], x2);
                while (*(x1 = x2 + strlen(x2) + 1))
                {
                    x2 = x1 + strlen(x1) + 1;
                    if (!*x2) break;
                    printf("\t\t%s: %s\n", x1, x2);
                }
1289 1290 1291
            }
            break;

1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
        case S_MSTOOLINFO_V3:
            {
                const unsigned short*   ptr = ((const unsigned short*)sym) + 2;

                printf("\tTool info V3: unk=%04x%04x%04x front=%d.%d.%d.%d back=%d.%d.%d.%d %s\n",
                       ptr[0], ptr[1], ptr[2],
                       ptr[3], ptr[4], ptr[5], ptr[6],
                       ptr[7], ptr[8], ptr[9], ptr[10],
                       (const char*)(ptr + 11));
            }
            break;

1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
        case S_MSTOOLENV_V3:
            {
                const char*             x1 = (const char*)sym + 4 + 1;
                const char*             x2;

                printf("\tTool conf V3\n");
                while (*x1)
                {
                    x2 = x1 + strlen(x1) + 1;
                    if (!*x2) break;
                    printf("\t\t%s: %s\n", x1, x2);
                    x1 = x2 + strlen(x2) + 1;
                }
            }
            break;

1320 1321 1322 1323
        case S_ALIGN_V1:
            /* simply skip it */
            break;

1324 1325 1326 1327 1328
        case S_SSEARCH_V1:
            printf("\tSSearch V1: (%04x:%08x)\n",
                   sym->ssearch_v1.segment, sym->ssearch_v1.offset);
            break;

1329 1330
        case S_SECTINFO_V3:
            printf("\tSSection Info: seg=%04x ?=%04x rva=%08x size=%08x attr=%08x %s\n",
1331 1332 1333 1334 1335
                   *(const unsigned short*)((const char*)sym + 4),
                   *(const unsigned short*)((const char*)sym + 6),
                   *(const unsigned*)((const char*)sym + 8),
                   *(const unsigned*)((const char*)sym + 12),
                   *(const unsigned*)((const char*)sym + 16),
1336 1337 1338 1339 1340
                   (const char*)sym + 20);
            break;

        case S_SUBSECTINFO_V3:
            printf("\tSSubSection Info: addr=%04x:%08x size=%08x attr=%08x %s\n",
1341 1342 1343 1344
                   *(const unsigned short*)((const char*)sym + 16),
                   *(const unsigned*)((const char*)sym + 12),
                   *(const unsigned*)((const char*)sym + 4),
                   *(const unsigned*)((const char*)sym + 8),
1345 1346 1347
                   (const char*)sym + 18);
            break;

1348 1349
        case S_ENTRYPOINT_V3:
            printf("\tSEntryPoint: id=%x '%s'\n",
1350
                   *(const unsigned*)((const char*)sym + 4), (const char*)sym + 8);
1351 1352
            break;

1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
        case S_LTHREAD_V1:
        case S_GTHREAD_V1:
            printf("\tS-Thread %s Var V1 '%s' seg=%04x offset=%08x type=%x\n",
                   sym->generic.id == S_LTHREAD_V1 ? "global" : "local",
                   p_string(&sym->thread_v1.p_name),
                   sym->thread_v1.segment, sym->thread_v1.offset, sym->thread_v1.symtype);
            break;

        case S_LTHREAD_V2:
        case S_GTHREAD_V2:
            printf("\tS-Thread %s Var V2 '%s' seg=%04x offset=%08x type=%x\n",
                   sym->generic.id == S_LTHREAD_V2 ? "global" : "local",
                   p_string(&sym->thread_v2.p_name),
                   sym->thread_v2.segment, sym->thread_v2.offset, sym->thread_v2.symtype);
            break;

        case S_LTHREAD_V3:
        case S_GTHREAD_V3:
            printf("\tS-Thread %s Var V3 '%s' seg=%04x offset=%08x type=%x\n",
                   sym->generic.id == S_LTHREAD_V3 ? "global" : "local", sym->thread_v3.name,
                   sym->thread_v3.segment, sym->thread_v3.offset, sym->thread_v3.symtype);
            break;

1376 1377 1378 1379 1380
        default:
            printf(">>> Unsupported symbol-id %x sz=%d\n", sym->generic.id, sym->generic.len + 2);
            dump_data((const void*)sym, sym->generic.len + 2, "  ");
        }
    }
1381
    return TRUE;
1382
}
1383

1384
void codeview_dump_linetab(const char* linetab, BOOL pascal_str, const char* pfx)
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
{
    const char*                 ptr = linetab;
    int				nfile, nseg, nline;
    int				i, j, k;
    const unsigned int*         filetab;
    const unsigned int*         lt_ptr;
    const struct startend*      start;

    nfile = *(const short*)linetab;
    filetab = (const unsigned int*)(linetab + 2 * sizeof(short));
    printf("%s%d files with %d ???\n", pfx, nfile, *(const short*)(linetab + sizeof(short)));

    for (i = 0; i < nfile; i++)
    {
        ptr = linetab + filetab[i];
        nseg = *(const short*)ptr;
        ptr += 2 * sizeof(short);
        lt_ptr = (const unsigned int*)ptr;
        start = (const struct startend*)(lt_ptr + nseg);

        /*
         * Now snarf the filename for all of the segments for this file.
         */
        if (pascal_str)
        {
            char			filename[MAX_PATH];
            const struct p_string*      p_fn;

            p_fn = (const struct p_string*)(start + nseg);
            memset(filename, 0, sizeof(filename));
            memcpy(filename, p_fn->name, p_fn->namelen);
            printf("%slines for file #%d/%d %s %d\n", pfx, i, nfile, filename, nseg);
        }
        else
            printf("%slines for file #%d/%d %s %d\n", pfx, i, nfile, (const char*)(start + nseg), nseg);

        for (j = 0; j < nseg; j++)
	{
            ptr = linetab + *lt_ptr++;
            nline = *(const short*)(ptr + 2);
            printf("%s  %04x:%08x-%08x #%d\n",
                   pfx, *(const short*)(ptr + 0), start[j].start, start[j].end, nline);
            ptr += 4;
            for (k = 0; k < nline; k++)
            {
                printf("%s    %x %d\n",
                       pfx, ((const unsigned int*)ptr)[k],
                       ((const unsigned short*)((const unsigned int*)ptr + nline))[k]);
            }
	}
    }
}
1437 1438 1439 1440

void codeview_dump_linetab2(const char* linetab, DWORD size, const char* strimage, DWORD strsize, const char* pfx)
{
    unsigned    i;
1441 1442 1443 1444 1445 1446 1447 1448
    const struct codeview_linetab2*     lt2;
    const struct codeview_linetab2*     lt2_files = NULL;
    const struct codeview_lt2blk_lines* lines_blk;
    const struct codeview_linetab2_file*fd;

    /* locate LT2_FILES_BLOCK (if any) */
    lt2 = (const struct codeview_linetab2*)linetab;
    while ((const char*)(lt2 + 1) < linetab + size)
1449
    {
1450
        if (lt2->header == LT2_FILES_BLOCK)
1451
        {
1452
            lt2_files = lt2;
1453 1454
            break;
        }
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
        lt2 = codeview_linetab2_next_block(lt2);
    }
    if (!lt2_files)
    {
        printf("%sNo LT2_FILES_BLOCK found\n", pfx);
        return;
    }

    lt2 = (const struct codeview_linetab2*)linetab;
    while ((const char*)(lt2 + 1) < linetab + size)
    {
        /* FIXME: should also check that whole lbh fits in linetab + size */
        switch (lt2->header)
1468
        {
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
        case LT2_LINES_BLOCK:
            lines_blk = (const struct codeview_lt2blk_lines*)lt2;
            printf("%sblock from %04x:%08x #%x (%x lines) fo=%x\n",
                   pfx, lines_blk->seg, lines_blk->start, lines_blk->size,
                   lines_blk->nlines, lines_blk->file_offset);
            /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
            fd = (const struct codeview_linetab2_file*)((const char*)lt2_files + 8 + lines_blk->file_offset);
            printf("%s  md5=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
                   pfx, fd->md5[ 0], fd->md5[ 1], fd->md5[ 2], fd->md5[ 3],
                   fd->md5[ 4], fd->md5[ 5], fd->md5[ 6], fd->md5[ 7],
                   fd->md5[ 8], fd->md5[ 9], fd->md5[10], fd->md5[11],
                   fd->md5[12], fd->md5[13], fd->md5[14], fd->md5[15]);
            /* FIXME: should check that string is within strimage + strsize */
            printf("%s  file=%s\n", pfx, strimage ? strimage + fd->offset : "--none--");
            for (i = 0; i < lines_blk->nlines; i++)
            {
                printf("%s  offset=%08x line=%d\n",
                       pfx, lines_blk->l[i].offset, lines_blk->l[i].lineno ^ 0x80000000);
            }
            break;
        case LT2_FILES_BLOCK: /* skip */
            break;
        default:
            printf("%sblock end %x\n", pfx, lt2->header);
            lt2 = (const struct codeview_linetab2*)((const char*)linetab + size);
            continue;
1495
        }
1496
        lt2 = codeview_linetab2_next_block(lt2);
1497 1498
    }
}