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
|
/* Copyright (C) 2021 Free Software Foundation, Inc.
Contributed by Oracle.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#include "config.h"
#include <ctype.h>
#include "util.h"
#include "DbeSession.h"
#include "Application.h"
#include "Experiment.h"
#include "Exp_Layout.h"
#include "MetricList.h"
#include "MemObject.h"
#include "PathTree.h"
#include "DbeView.h"
#include "Metric.h"
#include "MemorySpace.h"
#include "Table.h"
#include "IndexObject.h"
MemObjType_t::MemObjType_t ()
{
type = -1;
name = NULL;
index_expr = NULL;
machmodel = NULL;
mnemonic = 0;
short_description = NULL;
long_description = NULL;
}
MemObjType_t::~MemObjType_t ()
{
free (name);
free (index_expr);
free (machmodel);
free (short_description);
free (long_description);
}
MemorySpace::MemorySpace (DbeView *_dbev, int _mstype)
{
char *mname;
dbev = _dbev;
phaseIdx = -1;
// set up the MemoryObject information
objs = new HashMap<uint64_t, MemObj*>;
mstype = _mstype;
msindex_exp = NULL;
msname = NULL;
msindex_exp_str = NULL;
// find the memory space in the table
MemObjType_t *mot = findMemSpaceByIndex (mstype);
if (mot)
{
msname = dbe_strdup (mot->name);
if (mot->index_expr != NULL)
{
msindex_exp_str = dbe_strdup (mot->index_expr);
msindex_exp = dbeSession->ql_parse (msindex_exp_str);
if (msindex_exp == NULL)
// this was checked when the definition was created
abort ();
}
}
// create the Total and Unknown objects
mname = dbe_strdup (NTXT ("<Total>"));
total_memobj = createMemObject ((uint64_t) - 2, mname);
mname = dbe_strdup (GTXT ("<Unknown>"));
unk_memobj = createMemObject ((uint64_t) - 1, mname);
hist_data_all = NULL;
selected_mo_index = (uint64_t) - 3;
sel_ind = -1;
}
MemorySpace::~MemorySpace ()
{
reset ();
delete objs;
free (msname);
free (msindex_exp);
free (msindex_exp_str);
}
void
MemorySpace::reset ()
{
if (hist_data_all != NULL)
{
delete hist_data_all;
hist_data_all = NULL;
}
// do not clear the selected object's index
// selected_mo_index = (uint64_t)-3;
// destroy any existing objects, but keep the vector
// Now that we have a hashmap, which has its own vector,
// safe to delete and reallocate
delete objs;
objs = new HashMap<uint64_t, MemObj*>;
}
// find a memory object by its memory-object index
int
MemorySpace::findMemObject (uint64_t indx)
{
int index;
Hist_data::HistItem *hi;
if (indx == (uint64_t) - 3)
return -1;
Vec_loop (Hist_data::HistItem *, hist_data_all->hist_items, index, hi)
{
if (((uint64_t) ((MemObj *) hi->obj)->id) == indx)
return index;
}
// object does not exist; filter change eliminated it, for example
return -1;
}
// find the object referenced in the packet
MemObj *
MemorySpace::lookupMemObject (Experiment *exp, DataView *packets, long i)
{
uint64_t idx;
uint64_t va = (uint64_t) packets->getLongValue (PROP_VADDR, i);
if (va == ABS_UNSUPPORTED)
// return NULL, to ignore the record
return NULL;
if (va < ABS_CODE_RANGE)
// The va is not valid, rather, it's an error code
// return the <Unknown> object
return unk_memobj;
Expression::Context ctx (dbev, exp, packets, i);
idx = msindex_exp->eval (&ctx);
if (idx == (uint64_t) - 1)
return unk_memobj;
// do a binary search for the memory object
MemObj *res = objs->get (idx);
if (res == NULL)
{
res = createMemObject (idx, NULL);
objs->put (idx, res);
}
else
return res;
// recompute range
if (idx < idx_min)
idx_min = idx;
if (idx > idx_max)
idx_max = idx;
return res;
}
MemObj *
MemorySpace::createMemObject (uint64_t index, char *moname)
{
MemObj *res;
char *name;
if (moname != NULL)
{
res = new MemObj (index, moname);
return res;
}
// Custom memory objects
// The memory_page_size is defined in the machine model file such
// as ./machinemodels/t4.ermm.
// Most users prefer to look at the hexadecimal version of virtual
// addresses. Display only the hexadecimal version of virtual addresses
// for all machine model views with an exception of virtual page size.
if (dbe_strcmp (msname, NTXT ("Memory_page_size")) == 0)
name = dbe_sprintf (NTXT ("%s 0x%16.16llx (%llu)"), msname,
(long long) index, (unsigned long long) index);
else if (dbe_strcmp (msname, NTXT ("Memory_in_home_lgrp")) == 0)
name = dbe_sprintf (NTXT ("%s: %s"), msname,
index == 1 ? GTXT ("True") : index == 0 ? GTXT ("False")
: GTXT ("<Unknown>"));
else if (dbe_strcmp (msname, NTXT ("Memory_lgrp")) == 0)
name = dbe_sprintf (NTXT ("%s %llu"), msname, (unsigned long long) index);
else
name = dbe_sprintf (NTXT ("%s 0x%16.16llx"), msname, (long long) index);
res = new MemObj (index, name);
return res;
}
static Vector<MemObjType_t*> dyn_memobj_vec;
static Vector<MemObjType_t*> *dyn_memobj = &dyn_memobj_vec;
static Vector<int> *ordlist;
// Static function to get a vector of custom memory object definitions
Vector<void*> *
MemorySpace::getMemObjects ()
{
MemObjType_t *mot;
int ii;
int size = dyn_memobj->size ();
Vector<int> *indx = new Vector<int>(size);
Vector<char*> *name = new Vector<char*>(size);
Vector<char> *mnemonic = new Vector<char>(size);
Vector<char*> *formula = new Vector<char*>(size);
Vector<char*> *machmodel = new Vector<char*>(size);
Vector<int> *order = new Vector<int>(size);
Vector<char*> *sdesc = new Vector<char*>(size);
Vector<char*> *ldesc = new Vector<char*>(size);
if (size > 0)
{
Vec_loop (MemObjType_t *, dyn_memobj, ii, mot)
{
indx->store (ii, mot->type);
order->store (ii, ii);
name->store (ii, dbe_strdup (mot->name));
formula->store (ii, dbe_strdup (mot->index_expr));
mnemonic->store (ii, mot->mnemonic);
sdesc->store (ii, mot->short_description == NULL ? NULL
: dbe_strdup (mot->short_description));
ldesc->store (ii, mot->long_description == NULL ? NULL
: dbe_strdup (mot->long_description));
if (mot->machmodel == NULL)
machmodel->store (ii, NULL);
else
machmodel->store (ii, dbe_strdup (mot->machmodel));
}
}
Vector<void*> *res = new Vector<void*>(8);
res->store (0, indx);
res->store (1, name);
res->store (2, mnemonic);
res->store (3, formula);
res->store (4, machmodel);
res->store (5, order);
res->store (6, sdesc);
res->store (7, ldesc);
return (res);
}
// Static function to set order of memory object tabs
void
MemorySpace::set_MemTabOrder (Vector<int> *orders)
{
int size = orders->size ();
ordlist = new Vector<int>(size);
for (int i = 0; i < size; i++)
ordlist->store (i, orders->fetch (i));
}
// Static function to define a new memory object type
char *
MemorySpace::mobj_define (char *mname, char *mindex_exp, char *_machmodel,
char *short_description, char *long_description)
{
MemObjType_t *mot;
if (mname == NULL)
return dbe_strdup (GTXT ("No memory object name has been specified."));
if (isalpha ((int) (mname[0])) == 0)
return dbe_sprintf (GTXT ("Memory Object type name %s does not begin with an alphabetic character"),
mname);
char *p = mname;
while (*p != 0)
{
if (isalnum ((int) (*p)) == 0 && *p != '_')
return dbe_sprintf (GTXT ("Memory Object type name %s contains a non-alphanumeric character"),
mname);
p++;
}
mot = findMemSpaceByName (mname);
if (mot != NULL)
{
if (strcmp (mot->index_expr, mindex_exp) == 0)
// It's a redefinition, but the new definition is the same
return NULL;
return dbe_sprintf (GTXT ("Memory/Index Object type name %s is already defined"),
mname);
}
// make sure the name is not in use
if (dbeSession->findIndexSpaceByName (mname) >= 0)
return dbe_sprintf (GTXT ("Memory/Index Object type name %s is already defined"),
mname);
if (mindex_exp == NULL || *mindex_exp == 0)
return dbe_strdup (GTXT ("No index-expr has been specified."));
// verify that the index expression parses correctly
Expression *e = dbeSession->ql_parse (mindex_exp);
if (e == NULL)
return dbe_sprintf (GTXT ("Memory Object index expression is invalid: %s"),
mindex_exp);
delete e;
// It's OK, create the new table entry
char *s = dbeSession->indxobj_define (mname, NULL, mindex_exp,
short_description, long_description);
if (s)
return s;
IndexObjType_t *indObj = dbeSession->findIndexSpace (mname);
mot = new MemObjType_t;
mot->type = indObj->type;
indObj->memObj = mot;
mot->name = dbe_strdup (mname);
mot->index_expr = dbe_strdup (mindex_exp);
mot->mnemonic = MemorySpace::pickMnemonic (mname);
mot->machmodel = dbe_strdup (_machmodel);
mot->short_description = dbe_strdup (short_description);
mot->long_description = dbe_strdup (long_description);
// add it to the list
dyn_memobj->append (mot);
// tell the session
if (dbeSession != NULL)
dbeSession->mobj_define (mot);
return NULL;
}
// Static function to delete a new memory object type
char *
MemorySpace::mobj_delete (char *mname)
{
if (mname == NULL)
return dbe_strdup (GTXT ("No memory object name has been specified.\n"));
// search the dynamic types
for (long idx = 0, sz = VecSize (dyn_memobj); idx < sz; idx++)
{
MemObjType_t *mt = dyn_memobj->get (idx);
if (strcasecmp (mt->name, mname) == 0)
{
// delete it from the vector
mt = dyn_memobj->remove (idx);
delete mt;
dbeSession->removeIndexSpaceByName (mname);
return NULL;
}
}
return dbe_sprintf (GTXT ("Memory object `%s' is not defined.\n"), mname);
}
// Static function to get a list of memory object names from a machine model
Vector <char*> *
MemorySpace::getMachineModelMemObjs (char *mname)
{
Vector <char *> *ret = new Vector <char *> ();
if (mname == NULL)
return ret;
// search the memory objects
int idx;
MemObjType_t *mt;
Vec_loop (MemObjType_t*, dyn_memobj, idx, mt)
{
if (mt->machmodel != NULL && strcmp (mt->machmodel, mname) == 0)
{
char *n = dbe_strdup (mt->name);
ret->append (n);
}
}
return ret;
}
char
MemorySpace::pickMnemonic (char *name)
{
return name[0];
}
void
MemorySpace::get_filter_keywords (Vector <void*> *res)
{
Vector <char*> *kwCategory = (Vector<char*>*) res->fetch (0);
Vector <char*> *kwCategoryI18N = (Vector<char*>*) res->fetch (1);
Vector <char*> *kwDataType = (Vector<char*>*) res->fetch (2);
Vector <char*> *kwKeyword = (Vector<char*>*) res->fetch (3);
Vector <char*> *kwFormula = (Vector<char*>*) res->fetch (4);
Vector <char*> *kwDescription = (Vector<char*>*) res->fetch (5);
Vector <void*> *kwEnumDescs = (Vector<void*>*) res->fetch (6);
char *vtypeNames[] = VTYPE_TYPE_NAMES;
for (int i = 0, sz = dyn_memobj ? dyn_memobj->size () : 0; i < sz; i++)
{
MemObjType_t *obj = dyn_memobj->fetch (i);
kwCategory->append (dbe_strdup (NTXT ("FK_MEMOBJ")));
kwCategoryI18N->append (dbe_strdup (GTXT ("Memory Object Definitions")));
kwDataType->append (dbe_strdup (vtypeNames[TYPE_INT64]));
kwKeyword->append (dbe_strdup (obj->name));
kwFormula->append (dbe_strdup (obj->index_expr));
kwDescription->append (NULL);
kwEnumDescs->append (NULL);
}
}
MemObjType_t *
MemorySpace::findMemSpaceByName (const char *mname)
{
int idx;
MemObjType_t *mt;
// search the dynamic types
Vec_loop (MemObjType_t*, dyn_memobj, idx, mt)
{
if (strcasecmp (mt->name, mname) == 0)
return mt;
}
return NULL;
}
MemObjType_t *
MemorySpace::findMemSpaceByIndex (int index)
{
int idx;
MemObjType_t *mt;
// search the dynamic types
Vec_loop (MemObjType_t*, dyn_memobj, idx, mt)
{
if (mt->type == index)
return mt;
}
return NULL;
}
|