xref: /reactos/sdk/lib/rossym/dwarfpubnames.c (revision e1d33479)
1*e1d33479SHermès Bélusca-Maïto 
2c2c66affSColin Finck #include <ntddk.h>
3c2c66affSColin Finck #include <reactos/rossym.h>
4c2c66affSColin Finck #include <ntimage.h>
5c2c66affSColin Finck 
6c2c66affSColin Finck #define NDEBUG
7c2c66affSColin Finck #include <debug.h>
8c2c66affSColin Finck 
9c2c66affSColin Finck #include "dwarf.h"
10c2c66affSColin Finck 
11c2c66affSColin Finck static int
_dwarfnametounit(Dwarf * d,char * name,DwarfBlock * bl,DwarfSym * s)12c2c66affSColin Finck _dwarfnametounit(Dwarf *d, char *name, DwarfBlock *bl, DwarfSym *s)
13c2c66affSColin Finck {
14c2c66affSColin Finck 	int vers;
15c2c66affSColin Finck 	ulong len, unit, off;
16c2c66affSColin Finck 	uchar *next;
17c2c66affSColin Finck 	char *str;
18c2c66affSColin Finck 	DwarfBuf b;
19c2c66affSColin Finck 
20c2c66affSColin Finck 	b.d = d;
21c2c66affSColin Finck 	b.p = bl->data;
22c2c66affSColin Finck 	b.ep = b.p + bl->len;
23c2c66affSColin Finck 
24c2c66affSColin Finck 	while(b.p < b.ep){
25c2c66affSColin Finck 		len = dwarfget4(&b);
26c2c66affSColin Finck 		if(len > b.ep-b.p){
27c2c66affSColin Finck 			werrstr("bad length in dwarf name header");
28c2c66affSColin Finck 			return -1;
29c2c66affSColin Finck 		}
30c2c66affSColin Finck 		next = b.p + len;
31c2c66affSColin Finck 		vers = dwarfget2(&b);
32c2c66affSColin Finck 		if(vers != 1 && vers != 2){
33c2c66affSColin Finck 			werrstr("bad version %d in dwarf name header", vers);
34c2c66affSColin Finck 			return -1;
35c2c66affSColin Finck 		}
36c2c66affSColin Finck 		unit = dwarfget4(&b);
37c2c66affSColin Finck 		dwarfget4(&b);	/* unit length */
38c2c66affSColin Finck 		while(b.p < next){
39c2c66affSColin Finck 			off = dwarfget4(&b);
40c2c66affSColin Finck 			if(off == 0)
41c2c66affSColin Finck 				break;
42c2c66affSColin Finck 			str = dwarfgetstring(&b);
43c2c66affSColin Finck 			if(strcmp(str, name) == 0){
44c2c66affSColin Finck 				if(dwarfenumunit(d, unit, s) < 0)
45c2c66affSColin Finck 					return -1;
46c2c66affSColin Finck 				if(unit + off >= s->b.ep - d->info.data){
47c2c66affSColin Finck 					werrstr("bad offset in name entry");
48c2c66affSColin Finck 					return -1;
49c2c66affSColin Finck 				}
50c2c66affSColin Finck 				s->b.p = d->info.data + unit + off;
51c2c66affSColin Finck 				if(dwarfnextsym(d, s) < 0)
52c2c66affSColin Finck 					return -1;
53c2c66affSColin Finck 				if(s->attrs.name==nil || strcmp(s->attrs.name, name)!=0){
54c2c66affSColin Finck 					werrstr("unexpected name %#q in lookup for %#q", s->attrs.name, name);
55c2c66affSColin Finck 					return -1;
56c2c66affSColin Finck 				}
57c2c66affSColin Finck 				return 0;
58c2c66affSColin Finck 			}
59c2c66affSColin Finck 		}
60c2c66affSColin Finck 		b.p = next;
61c2c66affSColin Finck 	}
62c2c66affSColin Finck 	werrstr("unknown name '%s'", name);
63c2c66affSColin Finck 	return -1;
64c2c66affSColin Finck }
65c2c66affSColin Finck 
66c2c66affSColin Finck int
dwarflookupname(Dwarf * d,char * name,DwarfSym * sym)67c2c66affSColin Finck dwarflookupname(Dwarf *d, char *name, DwarfSym *sym)
68c2c66affSColin Finck {
69c2c66affSColin Finck 	return _dwarfnametounit(d, name, &d->pubnames, sym);
70c2c66affSColin Finck }
71c2c66affSColin Finck 
72c2c66affSColin Finck /*
73c2c66affSColin Finck 
74c2c66affSColin Finck int
75c2c66affSColin Finck dwarflookuptype(Dwarf *d, char *name, DwarfSym *sym)
76c2c66affSColin Finck {
77c2c66affSColin Finck 	return _dwarfnametounit(d, name, &d->pubtypes, sym);
78c2c66affSColin Finck }
79c2c66affSColin Finck 
80c2c66affSColin Finck  */
81c2c66affSColin Finck 
82