ReactOS 0.4.15-dev-7681-g776c3a3
dwarfabbrev.c
Go to the documentation of this file.
1/*
2 * Dwarf abbreviation parsing code.
3 *
4 * The convention here is that calling dwarfgetabbrevs relinquishes
5 * access to any abbrevs returned previously. Will have to add
6 * explicit reference counting if this turns out not to be acceptable.
7 */
8
9#define NTOSAPI
10#include <ntddk.h>
11#include <reactos/rossym.h>
12#include "rossympriv.h"
13#include <ntimage.h>
14
15#define NDEBUG
16#include <debug.h>
17
18#include "rossym.h"
19#include "rossympriv.h"
20#include "dwarf.h"
21
22static int parseabbrevs(Dwarf*, ulong, DwarfAbbrev*, DwarfAttr*, int*, int*);
24
25static int
27{
28 int nattr, nabbrev;
29 DwarfAbbrev *abbrev;
31
32 if(d->acache.off == off && d->acache.na){
33 *aa = d->acache.a;
34 return d->acache.na;
35 }
36
37 /* two passes - once to count, then allocate, then a second to copy */
38 if(parseabbrevs(d, off, nil, nil, &nabbrev, &nattr) < 0) {
39 return -1;
40 }
41
42 abbrev = malloc(nabbrev*sizeof(DwarfAbbrev) + nattr*sizeof(DwarfAttr));
43 attr = (DwarfAttr*)(abbrev+nabbrev);
44
45 if(parseabbrevs(d, off, abbrev, attr, nil, nil) < 0){
46 free(abbrev);
47 return -1;
48 }
49
50 free(d->acache.a);
51 d->acache.a = abbrev;
52 d->acache.na = nabbrev;
53 d->acache.off = off;
54
55 *aa = abbrev;
56 return nabbrev;
57}
58
59static int
60parseabbrevs(Dwarf *d, ulong off, DwarfAbbrev *abbrev, DwarfAttr *attr, int *pnabbrev, int *pnattr)
61{
62 int i, nabbrev, nattr, haskids;
64 DwarfBuf b;
65
66 if(off >= d->abbrev.len){
67 werrstr("bad abbrev section offset 0x%lux >= 0x%lux\n", off, d->abbrev.len);
68 return -1;
69 }
70
71 memset(&b, 0, sizeof b);
72 b.p = d->abbrev.data + off;
73 b.ep = d->abbrev.data + d->abbrev.len;
74
75 nabbrev = 0;
76 nattr = 0;
77 for(;;){
78 if(b.p == nil){
79 werrstr("malformed abbrev data");
80 return -1;
81 }
82 num = dwarfget128(&b);
83 if(num == 0)
84 break;
85 tag = dwarfget128(&b);
86 haskids = dwarfget1(&b);
87 for(i=0;; i++){
88 name = dwarfget128(&b);
89 form = dwarfget128(&b);
90 if(name == 0 && form == 0)
91 break;
92 if(attr){
93 attr[i].name = name;
94 attr[i].form = form;
95 }
96 }
97 if(abbrev){
98 abbrev->num = num;
99 abbrev->tag = tag;
100 abbrev->haskids = haskids;
101 abbrev->attr = attr;
102 abbrev->nattr = i;
103 abbrev++;
104 attr += i;
105 }
106 nabbrev++;
107 nattr += i;
108 }
109 if(pnabbrev)
110 *pnabbrev = nabbrev;
111 if(pnattr)
112 *pnattr = nattr;
113 return 0;
114}
115
116static DwarfAbbrev*
118{
119 int i;
120
121 for(i=0; i<na; i++)
122 if(a[i].num == num)
123 return &a[i];
124 werrstr("abbrev not found");
125 return nil;
126}
127
130{
131 DwarfAbbrev *a;
132 int na;
133
134 if((na = loadabbrevs(d, off, &a)) < 0){
135 werrstr("loadabbrevs: %r");
136 return nil;
137 }
138 return findabbrev(a, na, num);
139}
140
141
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
unsigned long ulong
Definition: linux.h:275
int form
Definition: main.c:89
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint GLuint num
Definition: glext.h:9618
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define d
Definition: ke_i.h:81
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
static int parseabbrevs(Dwarf *, ulong, DwarfAbbrev *, DwarfAttr *, int *, int *)
Definition: dwarfabbrev.c:60
static DwarfAbbrev * findabbrev(DwarfAbbrev *a, int na, ulong num)
Definition: dwarfabbrev.c:117
static int loadabbrevs(Dwarf *d, ulong off, DwarfAbbrev **aa)
Definition: dwarfabbrev.c:26
DwarfAbbrev * dwarfgetabbrev(Dwarf *, ulong, ulong)
Definition: dwarfabbrev.c:129
#define werrstr(str,...)
Definition: compat.h:34
#define nil
Definition: compat.h:23
#define memset(x, y, z)
Definition: compat.h:39
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
int nattr
Definition: dwarf.h:431
ulong num
Definition: dwarf.h:427
ulong tag
Definition: dwarf.h:428
uchar haskids
Definition: dwarf.h:429
DwarfAttr * attr
Definition: dwarf.h:430
Definition: dwarf.h:437
Definition: cookie.c:202
WCHAR * name
Definition: cookie.c:203
Definition: name.c:39
Definition: ecma_167.h:138