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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
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
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
573
574
575
576
577
578
579
580
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
/*
* File types.c - datatype handling stuff for internal debugger.
*
* Copyright (C) 1997, Eric Youngdale.
*
* 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
*
* Note: This really doesn't do much at the moment, but it forms the framework
* upon which full support for datatype handling will eventually be built.
*/
#include "config.h"
#include <stdlib.h>
#include "debugger.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
/******************************************************************
* types_get_real_type
*
* Get rid of any potential typedef in the lvalue's type to get
* to the 'real' type (the one we can work upon).
*/
BOOL types_get_real_type(struct dbg_type* type, DWORD* tag)
{
if (type->id == dbg_itype_none) return FALSE;
do
{
if (!types_get_info(type, TI_GET_SYMTAG, tag))
return FALSE;
if (*tag != SymTagTypedef) return TRUE;
} while (types_get_info(type, TI_GET_TYPE, &type->id));
return FALSE;
}
/******************************************************************
* types_extract_as_longlong
*
* Given a lvalue, try to get an integral (or pointer/address) value
* out of it
*/
LONGLONG types_extract_as_longlong(const struct dbg_lvalue* lvalue,
unsigned* psize, BOOL *issigned)
{
LONGLONG rtn = 0;
DWORD tag, bt;
DWORD64 size;
struct dbg_type type = lvalue->type;
BOOL s = FALSE;
if (!types_get_real_type(&type, &tag))
RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
if (type.id == dbg_itype_segptr)
{
return (LONG_PTR)memory_to_linear_addr(&lvalue->addr);
}
if (psize) *psize = 0;
if (issigned) *issigned = FALSE;
switch (tag)
{
case SymTagBaseType:
if (!types_get_info(&type, TI_GET_LENGTH, &size) ||
!types_get_info(&type, TI_GET_BASETYPE, &bt))
{
WINE_ERR("Couldn't get information\n");
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
}
if (size > sizeof(rtn))
{
WINE_ERR("Size too large (%s)\n", wine_dbgstr_longlong(size));
RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
}
switch (bt)
{
case btChar:
case btInt:
if (!be_cpu->fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn))
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
break;
case btUInt:
if (!be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
break;
case btFloat:
RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
}
if (psize) *psize = (unsigned)size;
if (issigned) *issigned = s;
break;
case SymTagPointerType:
if (!be_cpu->fetch_integer(lvalue, sizeof(void*), s = FALSE, &rtn))
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
break;
case SymTagArrayType:
case SymTagUDT:
if (!be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
break;
case SymTagEnum:
/* FIXME: we don't handle enum size */
if (!be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
break;
case SymTagFunctionType:
rtn = (ULONG_PTR)memory_to_linear_addr(&lvalue->addr);
break;
default:
WINE_FIXME("Unsupported tag %u\n", tag);
RaiseException(DEBUG_STATUS_NOT_AN_INTEGER, 0, 0, NULL);
}
return rtn;
}
/******************************************************************
* types_extract_as_integer
*
* Given a lvalue, try to get an integral (or pointer/address) value
* out of it
*/
long int types_extract_as_integer(const struct dbg_lvalue* lvalue)
{
return types_extract_as_longlong(lvalue, NULL, NULL);
}
/******************************************************************
* types_extract_as_address
*
*
*/
void types_extract_as_address(const struct dbg_lvalue* lvalue, ADDRESS64* addr)
{
if (lvalue->type.id == dbg_itype_segptr && lvalue->type.module == 0)
{
*addr = lvalue->addr;
}
else
{
addr->Mode = AddrModeFlat;
addr->Offset = types_extract_as_longlong(lvalue, NULL, NULL);
}
}
BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lvalue_from)
{
LONGLONG val;
DWORD64 size;
BOOL is_signed;
if (!types_get_info(&lvalue_to->type, TI_GET_LENGTH, &size)) return FALSE;
if (sizeof(val) < size)
{
dbg_printf("Unsufficient size\n");
return FALSE;
}
/* FIXME: should support floats as well */
val = types_extract_as_longlong(lvalue_from, NULL, &is_signed);
return be_cpu->store_integer(lvalue_to, size, is_signed, val);
}
/******************************************************************
* types_get_udt_element_lvalue
*
* Implement a structure derefencement
*/
static BOOL types_get_udt_element_lvalue(struct dbg_lvalue* lvalue,
const struct dbg_type* type, long int* tmpbuf)
{
DWORD offset, bitoffset;
DWORD bt;
DWORD64 length;
unsigned mask;
types_get_info(type, TI_GET_TYPE, &lvalue->type.id);
lvalue->type.module = type->module;
if (!types_get_info(type, TI_GET_OFFSET, &offset)) return FALSE;
lvalue->addr.Offset += offset;
if (types_get_info(type, TI_GET_BITPOSITION, &bitoffset))
{
types_get_info(type, TI_GET_LENGTH, &length);
/* FIXME: this test isn't sufficient, depending on start of bitfield
* (ie a 32 bit field can spread across 5 bytes)
*/
if (length > 8 * sizeof(*tmpbuf)) return FALSE;
lvalue->addr.Offset += bitoffset >> 3;
/*
* Bitfield operation. We have to extract the field and store
* it in a temporary buffer so that we get it all right.
*/
if (!memory_read_value(lvalue, sizeof(*tmpbuf), tmpbuf)) return FALSE;
mask = 0xffffffff << (DWORD)length;
*tmpbuf >>= bitoffset & 7;
*tmpbuf &= ~mask;
lvalue->cookie = DLV_HOST;
lvalue->addr.Offset = (ULONG_PTR)tmpbuf;
/*
* OK, now we have the correct part of the number.
* Check to see whether the basic type is signed or not, and if so,
* we need to sign extend the number.
*/
if (types_get_info(&lvalue->type, TI_GET_BASETYPE, &bt) &&
bt == btInt && (*tmpbuf & (1 << ((DWORD)length - 1))))
{
*tmpbuf |= mask;
}
}
else
{
if (!memory_read_value(lvalue, sizeof(*tmpbuf), tmpbuf)) return FALSE;
}
return TRUE;
}
/******************************************************************
* types_udt_find_element
*
*/
BOOL types_udt_find_element(struct dbg_lvalue* lvalue, const char* name, long int* tmpbuf)
{
DWORD tag, count;
char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
WCHAR* ptr;
char tmp[256];
struct dbg_type type;
if (!types_get_real_type(&lvalue->type, &tag) || tag != SymTagUDT)
return FALSE;
if (types_get_info(&lvalue->type, TI_GET_CHILDRENCOUNT, &count))
{
fcp->Start = 0;
while (count)
{
fcp->Count = min(count, 256);
if (types_get_info(&lvalue->type, TI_FINDCHILDREN, fcp))
{
unsigned i;
type.module = lvalue->type.module;
for (i = 0; i < min(fcp->Count, count); i++)
{
ptr = NULL;
type.id = fcp->ChildId[i];
types_get_info(&type, TI_GET_SYMNAME, &ptr);
if (!ptr) continue;
WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
HeapFree(GetProcessHeap(), 0, ptr);
if (strcmp(tmp, name)) continue;
return types_get_udt_element_lvalue(lvalue, &type, tmpbuf);
}
}
count -= min(count, 256);
fcp->Start += 256;
}
}
return FALSE;
}
/******************************************************************
* types_array_index
*
* Grab an element from an array
*/
BOOL types_array_index(const struct dbg_lvalue* lvalue, int index, struct dbg_lvalue* result)
{
struct dbg_type type = lvalue->type;
DWORD tag, count;
memset(result, 0, sizeof(*result));
result->type.id = dbg_itype_none;
result->type.module = 0;
if (!types_get_real_type(&type, &tag)) return FALSE;
switch (tag)
{
case SymTagArrayType:
if (!types_get_info(&type, TI_GET_COUNT, &count)) return FALSE;
if (index < 0 || index >= count) return FALSE;
result->addr = lvalue->addr;
break;
case SymTagPointerType:
if (!memory_read_value(lvalue, be_cpu->pointer_size, &result->addr.Offset)) return FALSE;
result->addr.Mode = AddrModeFlat;
switch (be_cpu->pointer_size)
{
case 4: result->addr.Offset = (DWORD)result->addr.Offset; break;
case 8: break;
default: assert(0);
}
break;
default:
assert(FALSE);
}
/*
* Get the base type, so we know how much to index by.
*/
if (!types_get_info(&type, TI_GET_TYPE, &result->type.id)) return FALSE;
result->type.module = type.module;
if (index)
{
DWORD64 length;
if (!types_get_info(&result->type, TI_GET_LENGTH, &length)) return FALSE;
result->addr.Offset += index * (DWORD)length;
}
/* FIXME: the following statement is not always true (and can lead to buggy behavior).
* There is no way to tell where the deref:ed value is...
* For example:
* x is a pointer to struct s, x being on the stack
* => lvalue is in debuggee, result is in debugger
* x is a pointer to struct s, x being optimized into a reg
* => lvalue is debugger, result is debuggee
* x is a pointer to internal variable x
* => lvalue is debugger, result is debuggee
* So we always force debuggee address space, because dereferencing pointers to
* internal variables is very unlikely. A correct fix would be
* rather large.
*/
result->cookie = DLV_TARGET;
return TRUE;
}
struct type_find_t
{
unsigned long result; /* out: the found type */
enum SymTagEnum tag; /* in: the tag to look for */
union
{
unsigned long typeid; /* when tag is SymTagUDT */
const char* name; /* when tag is SymTagPointerType */
} u;
};
static BOOL CALLBACK types_cb(PSYMBOL_INFO sym, ULONG size, void* _user)
{
struct type_find_t* user = _user;
BOOL ret = TRUE;
struct dbg_type type;
DWORD type_id;
if (sym->Tag == user->tag)
{
switch (user->tag)
{
case SymTagUDT:
if (!strcmp(user->u.name, sym->Name))
{
user->result = sym->TypeIndex;
ret = FALSE;
}
break;
case SymTagPointerType:
type.module = sym->ModBase;
type.id = sym->TypeIndex;
if (types_get_info(&type, TI_GET_TYPE, &type_id) && type_id == user->u.typeid)
{
user->result = sym->TypeIndex;
ret = FALSE;
}
break;
default: break;
}
}
return ret;
}
/******************************************************************
* types_find_pointer
*
* Should look up in module based at linear whether (typeid*) exists
* Otherwise, we could create it locally
*/
struct dbg_type types_find_pointer(const struct dbg_type* type)
{
struct type_find_t f;
struct dbg_type ret;
f.result = dbg_itype_none;
f.tag = SymTagPointerType;
f.u.typeid = type->id;
SymEnumTypes(dbg_curr_process->handle, type->module, types_cb, &f);
ret.module = type->module;
ret.id = f.result;
return ret;
}
/******************************************************************
* types_find_type
*
* Should look up in the module based at linear address whether a type
* named 'name' and with the correct tag exists
*/
struct dbg_type types_find_type(unsigned long linear, const char* name, enum SymTagEnum tag)
{
struct type_find_t f;
struct dbg_type ret;
f.result = dbg_itype_none;
f.tag = tag;
f.u.name = name;
SymEnumTypes(dbg_curr_process->handle, linear, types_cb, &f);
ret.module = linear;
ret.id = f.result;
return ret;
}
/***********************************************************************
* print_value
*
* Implementation of the 'print' command.
*/
void print_value(const struct dbg_lvalue* lvalue, char format, int level)
{
struct dbg_type type = lvalue->type;
struct dbg_lvalue lvalue_field;
int i;
DWORD tag;
DWORD count;
DWORD64 size;
if (!types_get_real_type(&type, &tag))
{
WINE_FIXME("---error\n");
return;
}
if (type.id == dbg_itype_none)
{
/* No type, just print the addr value */
print_bare_address(&lvalue->addr);
goto leave;
}
if (format == 'i' || format == 's' || format == 'w' || format == 'b' || format == 'g')
{
dbg_printf("Format specifier '%c' is meaningless in 'print' command\n", format);
format = '\0';
}
switch (tag)
{
case SymTagBaseType:
case SymTagEnum:
case SymTagPointerType:
/* FIXME: this in not 100% optimal (as we're going through the typedef handling
* stuff again
*/
print_basic(lvalue, format);
break;
case SymTagUDT:
if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count))
{
char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
WCHAR* ptr;
char tmp[256];
long int tmpbuf;
struct dbg_type sub_type;
dbg_printf("{");
fcp->Start = 0;
while (count)
{
fcp->Count = min(count, 256);
if (types_get_info(&type, TI_FINDCHILDREN, fcp))
{
for (i = 0; i < min(fcp->Count, count); i++)
{
ptr = NULL;
sub_type.module = type.module;
sub_type.id = fcp->ChildId[i];
types_get_info(&sub_type, TI_GET_SYMNAME, &ptr);
if (!ptr) continue;
WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
dbg_printf("%s=", tmp);
HeapFree(GetProcessHeap(), 0, ptr);
lvalue_field = *lvalue;
if (types_get_udt_element_lvalue(&lvalue_field, &sub_type, &tmpbuf))
{
print_value(&lvalue_field, format, level + 1);
}
if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
}
}
count -= min(count, 256);
fcp->Start += 256;
}
dbg_printf("}");
}
break;
case SymTagArrayType:
/*
* Loop over all of the entries, printing stuff as we go.
*/
count = 1; size = 1;
types_get_info(&type, TI_GET_COUNT, &count);
types_get_info(&type, TI_GET_LENGTH, &size);
if (size == count)
{
unsigned len;
char buffer[256];
/*
* Special handling for character arrays.
*/
/* FIXME should check basic type here (should be a char!!!!)... */
len = min(count, sizeof(buffer));
memory_get_string(dbg_curr_process,
memory_to_linear_addr(&lvalue->addr),
lvalue->cookie == DLV_TARGET, TRUE, buffer, len);
dbg_printf("\"%s%s\"", buffer, (len < count) ? "..." : "");
break;
}
lvalue_field = *lvalue;
types_get_info(&type, TI_GET_TYPE, &lvalue_field.type.id);
dbg_printf("{");
for (i = 0; i < count; i++)
{
print_value(&lvalue_field, format, level + 1);
lvalue_field.addr.Offset += size / count;
dbg_printf((i == count - 1) ? "}" : ", ");
}
break;
case SymTagFunctionType:
dbg_printf("Function ");
print_bare_address(&lvalue->addr);
dbg_printf(": ");
types_print_type(&type, FALSE);
break;
case SymTagTypedef:
lvalue_field = *lvalue;
types_get_info(&lvalue->type, TI_GET_TYPE, &lvalue_field.type.id);
print_value(&lvalue_field, format, level);
break;
default:
WINE_FIXME("Unknown tag (%u)\n", tag);
RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
break;
}
leave:
if (level == 0) dbg_printf("\n");
}
static BOOL CALLBACK print_types_cb(PSYMBOL_INFO sym, ULONG size, void* ctx)
{
struct dbg_type type;
type.module = sym->ModBase;
type.id = sym->TypeIndex;
dbg_printf("Mod: %08lx ID: %08lx\n", type.module, type.id);
types_print_type(&type, TRUE);
dbg_printf("\n");
return TRUE;
}
static BOOL CALLBACK print_types_mod_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
{
return SymEnumTypes(dbg_curr_process->handle, base, print_types_cb, ctx);
}
BOOL print_types(void)
{
if (!dbg_curr_process)
{
dbg_printf("No known process, cannot print types\n");
return FALSE;
}
SymEnumerateModules64(dbg_curr_process->handle, print_types_mod_cb, NULL);
return FALSE;
}
BOOL types_print_type(const struct dbg_type* type, BOOL details)
{
WCHAR* ptr;
char tmp[256];
const char* name;
DWORD tag, udt, count;
struct dbg_type subtype;
if (type->id == dbg_itype_none || !types_get_info(type, TI_GET_SYMTAG, &tag))
{
dbg_printf("--invalid--<%lxh>--", type->id);
return FALSE;
}
if (types_get_info(type, TI_GET_SYMNAME, &ptr) && ptr)
{
WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
name = tmp;
HeapFree(GetProcessHeap(), 0, ptr);
}
else name = "--none--";
switch (tag)
{
case SymTagBaseType:
if (details) dbg_printf("Basic<%s>", name); else dbg_printf("%s", name);
break;
case SymTagPointerType:
types_get_info(type, TI_GET_TYPE, &subtype.id);
subtype.module = type->module;
types_print_type(&subtype, FALSE);
dbg_printf("*");
break;
case SymTagUDT:
types_get_info(type, TI_GET_UDTKIND, &udt);
switch (udt)
{
case UdtStruct: dbg_printf("struct %s", name); break;
case UdtUnion: dbg_printf("union %s", name); break;
case UdtClass: dbg_printf("class %s", name); break;
default: WINE_ERR("Unsupported UDT type (%d) for %s\n", udt, name); break;
}
if (details &&
types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
{
char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
WCHAR* ptr;
char tmp[256];
int i;
struct dbg_type type_elt;
dbg_printf(" {");
fcp->Start = 0;
while (count)
{
fcp->Count = min(count, 256);
if (types_get_info(type, TI_FINDCHILDREN, fcp))
{
for (i = 0; i < min(fcp->Count, count); i++)
{
ptr = NULL;
type_elt.module = type->module;
type_elt.id = fcp->ChildId[i];
types_get_info(&type_elt, TI_GET_SYMNAME, &ptr);
if (!ptr) continue;
WideCharToMultiByte(CP_ACP, 0, ptr, -1, tmp, sizeof(tmp), NULL, NULL);
HeapFree(GetProcessHeap(), 0, ptr);
dbg_printf("%s", tmp);
if (types_get_info(&type_elt, TI_GET_TYPE, &type_elt.id))
{
dbg_printf(":");
types_print_type(&type_elt, details);
}
if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
}
}
count -= min(count, 256);
fcp->Start += 256;
}
dbg_printf("}");
}
break;
case SymTagArrayType:
types_get_info(type, TI_GET_TYPE, &subtype.id);
subtype.module = type->module;
types_print_type(&subtype, details);
if (types_get_info(type, TI_GET_COUNT, &count))
dbg_printf(" %s[%d]", name, count);
else
dbg_printf(" %s[]", name);
break;
case SymTagEnum:
dbg_printf("enum %s", name);
break;
case SymTagFunctionType:
types_get_info(type, TI_GET_TYPE, &subtype.id);
/* is the returned type the same object as function sig itself ? */
if (subtype.id != type->id)
{
subtype.module = type->module;
types_print_type(&subtype, FALSE);
}
else
{
subtype.module = 0;
dbg_printf("<ret_type=self>");
}
dbg_printf(" (*%s)(", name);
if (types_get_info(type, TI_GET_CHILDRENCOUNT, &count))
{
char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
int i;
fcp->Start = 0;
if (!count) dbg_printf("void");
else while (count)
{
fcp->Count = min(count, 256);
if (types_get_info(type, TI_FINDCHILDREN, fcp))
{
for (i = 0; i < min(fcp->Count, count); i++)
{
subtype.id = fcp->ChildId[i];
types_get_info(&subtype, TI_GET_TYPE, &subtype.id);
types_print_type(&subtype, FALSE);
if (i < min(fcp->Count, count) - 1 || count > 256) dbg_printf(", ");
}
}
count -= min(count, 256);
fcp->Start += 256;
}
}
dbg_printf(")");
break;
case SymTagTypedef:
dbg_printf("%s", name);
break;
default:
WINE_ERR("Unknown type %u for %s\n", tag, name);
break;
}
return TRUE;
}
/* helper to typecast pInfo to its expected type (_t) */
#define X(_t) (*((_t*)pInfo))
BOOL types_get_info(const struct dbg_type* type, IMAGEHLP_SYMBOL_TYPE_INFO ti, void* pInfo)
{
if (type->id == dbg_itype_none) return FALSE;
if (type->module != 0)
{
DWORD ret, tag, bt;
ret = SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, ti, pInfo);
if (!ret &&
SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_SYMTAG, &tag) &&
tag == SymTagBaseType &&
SymGetTypeInfo(dbg_curr_process->handle, type->module, type->id, TI_GET_BASETYPE, &bt))
{
static const WCHAR voidW[] = {'v','o','i','d','\0'};
static const WCHAR charW[] = {'c','h','a','r','\0'};
static const WCHAR wcharW[] = {'W','C','H','A','R','\0'};
static const WCHAR intW[] = {'i','n','t','\0'};
static const WCHAR uintW[] = {'u','n','s','i','g','n','e','d',' ','i','n','t','\0'};
static const WCHAR floatW[] = {'f','l','o','a','t','\0'};
static const WCHAR boolW[] = {'b','o','o','l','\0'};
static const WCHAR longW[] = {'l','o','n','g',' ','i','n','t','\0'};
static const WCHAR ulongW[] = {'u','n','s','i','g','n','e','d',' ','l','o','n','g',' ','i','n','t','\0'};
static const WCHAR complexW[] = {'c','o','m','p','l','e','x','\0'};
const WCHAR* name = NULL;
switch (bt)
{
case btVoid: name = voidW; break;
case btChar: name = charW; break;
case btWChar: name = wcharW; break;
case btInt: name = intW; break;
case btUInt: name = uintW; break;
case btFloat: name = floatW; break;
case btBool: name = boolW; break;
case btLong: name = longW; break;
case btULong: name = ulongW; break;
case btComplex: name = complexW; break;
default: WINE_FIXME("Unsupported basic type %u\n", bt); return FALSE;
}
X(WCHAR*) = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(WCHAR));
if (X(WCHAR*))
{
lstrcpyW(X(WCHAR*), name);
ret = TRUE;
}
}
return ret;
}
assert(type->id >= dbg_itype_first);
switch (type->id)
{
case dbg_itype_unsigned_long_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
default: WINE_FIXME("unsupported %u for u-long int\n", ti); return FALSE;
}
break;
case dbg_itype_signed_long_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
case TI_GET_BASETYPE: X(DWORD) = btInt; break;
default: WINE_FIXME("unsupported %u for s-long int\n", ti); return FALSE;
}
break;
case dbg_itype_unsigned_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 4; break;
case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
default: WINE_FIXME("unsupported %u for u-int\n", ti); return FALSE;
}
break;
case dbg_itype_signed_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 4; break;
case TI_GET_BASETYPE: X(DWORD) = btInt; break;
default: WINE_FIXME("unsupported %u for s-int\n", ti); return FALSE;
}
break;
case dbg_itype_unsigned_short_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 2; break;
case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
default: WINE_FIXME("unsupported %u for u-short int\n", ti); return FALSE;
}
break;
case dbg_itype_signed_short_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 2; break;
case TI_GET_BASETYPE: X(DWORD) = btInt; break;
default: WINE_FIXME("unsupported %u for s-short int\n", ti); return FALSE;
}
break;
case dbg_itype_unsigned_char_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 1; break;
case TI_GET_BASETYPE: X(DWORD) = btUInt; break;
default: WINE_FIXME("unsupported %u for u-char int\n", ti); return FALSE;
}
break;
case dbg_itype_signed_char_int:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 1; break;
case TI_GET_BASETYPE: X(DWORD) = btInt; break;
default: WINE_FIXME("unsupported %u for s-char int\n", ti); return FALSE;
}
break;
case dbg_itype_char:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 1; break;
case TI_GET_BASETYPE: X(DWORD) = btChar; break;
default: WINE_FIXME("unsupported %u for char int\n", ti); return FALSE;
}
break;
case dbg_itype_astring:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagPointerType; break;
case TI_GET_LENGTH: X(DWORD64) = ADDRSIZE; break;
case TI_GET_TYPE: X(DWORD) = dbg_itype_char; break;
default: WINE_FIXME("unsupported %u for a string\n", ti); return FALSE;
}
break;
case dbg_itype_segptr:
switch (ti)
{
case TI_GET_SYMTAG: X(DWORD) = SymTagBaseType; break;
case TI_GET_LENGTH: X(DWORD64) = 4; break;
case TI_GET_BASETYPE: X(DWORD) = btInt; break;
default: WINE_FIXME("unsupported %u for seg-ptr\n", ti); return FALSE;
}
break;
default: WINE_FIXME("unsupported type id 0x%lx\n", type->id);
}
#undef X
return TRUE;
}