1*f22f0ef4Schristos /* Copyright (C) 2021 Free Software Foundation, Inc.
2*f22f0ef4Schristos    Contributed by Oracle.
3*f22f0ef4Schristos 
4*f22f0ef4Schristos    This file is part of GNU Binutils.
5*f22f0ef4Schristos 
6*f22f0ef4Schristos    This program is free software; you can redistribute it and/or modify
7*f22f0ef4Schristos    it under the terms of the GNU General Public License as published by
8*f22f0ef4Schristos    the Free Software Foundation; either version 3, or (at your option)
9*f22f0ef4Schristos    any later version.
10*f22f0ef4Schristos 
11*f22f0ef4Schristos    This program is distributed in the hope that it will be useful,
12*f22f0ef4Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*f22f0ef4Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*f22f0ef4Schristos    GNU General Public License for more details.
15*f22f0ef4Schristos 
16*f22f0ef4Schristos    You should have received a copy of the GNU General Public License
17*f22f0ef4Schristos    along with this program; if not, write to the Free Software
18*f22f0ef4Schristos    Foundation, 51 Franklin Street - Fifth Floor, Boston,
19*f22f0ef4Schristos    MA 02110-1301, USA.  */
20*f22f0ef4Schristos 
21*f22f0ef4Schristos #include "config.h"
22*f22f0ef4Schristos #include <ctype.h>
23*f22f0ef4Schristos 
24*f22f0ef4Schristos #include "util.h"
25*f22f0ef4Schristos #include "DbeSession.h"
26*f22f0ef4Schristos #include "Application.h"
27*f22f0ef4Schristos #include "Experiment.h"
28*f22f0ef4Schristos #include "Exp_Layout.h"
29*f22f0ef4Schristos #include "MetricList.h"
30*f22f0ef4Schristos #include "MemObject.h"
31*f22f0ef4Schristos #include "PathTree.h"
32*f22f0ef4Schristos #include "DbeView.h"
33*f22f0ef4Schristos #include "Metric.h"
34*f22f0ef4Schristos #include "MemorySpace.h"
35*f22f0ef4Schristos #include "Table.h"
36*f22f0ef4Schristos #include "IndexObject.h"
37*f22f0ef4Schristos 
MemObjType_t()38*f22f0ef4Schristos MemObjType_t::MemObjType_t ()
39*f22f0ef4Schristos {
40*f22f0ef4Schristos   type = -1;
41*f22f0ef4Schristos   name = NULL;
42*f22f0ef4Schristos   index_expr = NULL;
43*f22f0ef4Schristos   machmodel = NULL;
44*f22f0ef4Schristos   mnemonic = 0;
45*f22f0ef4Schristos   short_description = NULL;
46*f22f0ef4Schristos   long_description = NULL;
47*f22f0ef4Schristos }
48*f22f0ef4Schristos 
~MemObjType_t()49*f22f0ef4Schristos MemObjType_t::~MemObjType_t ()
50*f22f0ef4Schristos {
51*f22f0ef4Schristos   free (name);
52*f22f0ef4Schristos   free (index_expr);
53*f22f0ef4Schristos   free (machmodel);
54*f22f0ef4Schristos   free (short_description);
55*f22f0ef4Schristos   free (long_description);
56*f22f0ef4Schristos }
57*f22f0ef4Schristos 
MemorySpace(DbeView * _dbev,int _mstype)58*f22f0ef4Schristos MemorySpace::MemorySpace (DbeView *_dbev, int _mstype)
59*f22f0ef4Schristos {
60*f22f0ef4Schristos   char *mname;
61*f22f0ef4Schristos   dbev = _dbev;
62*f22f0ef4Schristos   phaseIdx = -1;
63*f22f0ef4Schristos 
64*f22f0ef4Schristos   // set up the MemoryObject information
65*f22f0ef4Schristos   objs = new HashMap<uint64_t, MemObj*>;
66*f22f0ef4Schristos   mstype = _mstype;
67*f22f0ef4Schristos   msindex_exp = NULL;
68*f22f0ef4Schristos   msname = NULL;
69*f22f0ef4Schristos   msindex_exp_str = NULL;
70*f22f0ef4Schristos 
71*f22f0ef4Schristos   // find the memory space in the table
72*f22f0ef4Schristos   MemObjType_t *mot = findMemSpaceByIndex (mstype);
73*f22f0ef4Schristos   if (mot)
74*f22f0ef4Schristos     {
75*f22f0ef4Schristos       msname = dbe_strdup (mot->name);
76*f22f0ef4Schristos       if (mot->index_expr != NULL)
77*f22f0ef4Schristos 	{
78*f22f0ef4Schristos 	  msindex_exp_str = dbe_strdup (mot->index_expr);
79*f22f0ef4Schristos 	  msindex_exp = dbeSession->ql_parse (msindex_exp_str);
80*f22f0ef4Schristos 	  if (msindex_exp == NULL)
81*f22f0ef4Schristos 	    // this was checked when the definition was created
82*f22f0ef4Schristos 	    abort ();
83*f22f0ef4Schristos 	}
84*f22f0ef4Schristos     }
85*f22f0ef4Schristos 
86*f22f0ef4Schristos   // create the Total and Unknown objects
87*f22f0ef4Schristos   mname = dbe_strdup (NTXT ("<Total>"));
88*f22f0ef4Schristos   total_memobj = createMemObject ((uint64_t) - 2, mname);
89*f22f0ef4Schristos   mname = dbe_strdup (GTXT ("<Unknown>"));
90*f22f0ef4Schristos   unk_memobj = createMemObject ((uint64_t) - 1, mname);
91*f22f0ef4Schristos   hist_data_all = NULL;
92*f22f0ef4Schristos   selected_mo_index = (uint64_t) - 3;
93*f22f0ef4Schristos   sel_ind = -1;
94*f22f0ef4Schristos }
95*f22f0ef4Schristos 
~MemorySpace()96*f22f0ef4Schristos MemorySpace::~MemorySpace ()
97*f22f0ef4Schristos {
98*f22f0ef4Schristos   reset ();
99*f22f0ef4Schristos   delete objs;
100*f22f0ef4Schristos   free (msname);
101*f22f0ef4Schristos   free (msindex_exp);
102*f22f0ef4Schristos   free (msindex_exp_str);
103*f22f0ef4Schristos }
104*f22f0ef4Schristos 
105*f22f0ef4Schristos void
reset()106*f22f0ef4Schristos MemorySpace::reset ()
107*f22f0ef4Schristos {
108*f22f0ef4Schristos   if (hist_data_all != NULL)
109*f22f0ef4Schristos     {
110*f22f0ef4Schristos       delete hist_data_all;
111*f22f0ef4Schristos       hist_data_all = NULL;
112*f22f0ef4Schristos     }
113*f22f0ef4Schristos   // do not clear the selected object's index
114*f22f0ef4Schristos   // selected_mo_index = (uint64_t)-3;
115*f22f0ef4Schristos 
116*f22f0ef4Schristos   // destroy any existing objects, but keep the vector
117*f22f0ef4Schristos   // Now that we have a hashmap, which has its own vector,
118*f22f0ef4Schristos   //     safe to delete and reallocate
119*f22f0ef4Schristos   delete objs;
120*f22f0ef4Schristos   objs = new HashMap<uint64_t, MemObj*>;
121*f22f0ef4Schristos }
122*f22f0ef4Schristos 
123*f22f0ef4Schristos // find a memory object by its memory-object index
124*f22f0ef4Schristos int
findMemObject(uint64_t indx)125*f22f0ef4Schristos MemorySpace::findMemObject (uint64_t indx)
126*f22f0ef4Schristos {
127*f22f0ef4Schristos   int index;
128*f22f0ef4Schristos   Hist_data::HistItem *hi;
129*f22f0ef4Schristos   if (indx == (uint64_t) - 3)
130*f22f0ef4Schristos     return -1;
131*f22f0ef4Schristos 
132*f22f0ef4Schristos   Vec_loop (Hist_data::HistItem *, hist_data_all->hist_items, index, hi)
133*f22f0ef4Schristos   {
134*f22f0ef4Schristos     if (((uint64_t) ((MemObj *) hi->obj)->id) == indx)
135*f22f0ef4Schristos       return index;
136*f22f0ef4Schristos   }
137*f22f0ef4Schristos   // object does not exist; filter change eliminated it, for example
138*f22f0ef4Schristos   return -1;
139*f22f0ef4Schristos }
140*f22f0ef4Schristos 
141*f22f0ef4Schristos // find the object referenced in the packet
142*f22f0ef4Schristos MemObj *
lookupMemObject(Experiment * exp,DataView * packets,long i)143*f22f0ef4Schristos MemorySpace::lookupMemObject (Experiment *exp, DataView *packets, long i)
144*f22f0ef4Schristos {
145*f22f0ef4Schristos   uint64_t idx;
146*f22f0ef4Schristos   uint64_t va = (uint64_t) packets->getLongValue (PROP_VADDR, i);
147*f22f0ef4Schristos   if (va == ABS_UNSUPPORTED)
148*f22f0ef4Schristos     // return NULL, to ignore the record
149*f22f0ef4Schristos     return NULL;
150*f22f0ef4Schristos   if (va < ABS_CODE_RANGE)
151*f22f0ef4Schristos     // The va is not valid, rather, it's an error code
152*f22f0ef4Schristos     // return the <Unknown> object
153*f22f0ef4Schristos     return unk_memobj;
154*f22f0ef4Schristos 
155*f22f0ef4Schristos   Expression::Context ctx (dbev, exp, packets, i);
156*f22f0ef4Schristos   idx = msindex_exp->eval (&ctx);
157*f22f0ef4Schristos   if (idx == (uint64_t) - 1)
158*f22f0ef4Schristos     return unk_memobj;
159*f22f0ef4Schristos 
160*f22f0ef4Schristos   // do a binary search for the memory object
161*f22f0ef4Schristos   MemObj *res = objs->get (idx);
162*f22f0ef4Schristos   if (res == NULL)
163*f22f0ef4Schristos     {
164*f22f0ef4Schristos       res = createMemObject (idx, NULL);
165*f22f0ef4Schristos       objs->put (idx, res);
166*f22f0ef4Schristos     }
167*f22f0ef4Schristos   else
168*f22f0ef4Schristos     return res;
169*f22f0ef4Schristos 
170*f22f0ef4Schristos   // recompute range
171*f22f0ef4Schristos   if (idx < idx_min)
172*f22f0ef4Schristos     idx_min = idx;
173*f22f0ef4Schristos   if (idx > idx_max)
174*f22f0ef4Schristos     idx_max = idx;
175*f22f0ef4Schristos   return res;
176*f22f0ef4Schristos }
177*f22f0ef4Schristos 
178*f22f0ef4Schristos MemObj *
createMemObject(uint64_t index,char * moname)179*f22f0ef4Schristos MemorySpace::createMemObject (uint64_t index, char *moname)
180*f22f0ef4Schristos {
181*f22f0ef4Schristos   MemObj *res;
182*f22f0ef4Schristos   char *name;
183*f22f0ef4Schristos   if (moname != NULL)
184*f22f0ef4Schristos     {
185*f22f0ef4Schristos       res = new MemObj (index, moname);
186*f22f0ef4Schristos       return res;
187*f22f0ef4Schristos     }
188*f22f0ef4Schristos 
189*f22f0ef4Schristos   // Custom memory objects
190*f22f0ef4Schristos   // The memory_page_size is defined in the machine model file such
191*f22f0ef4Schristos   // as ./machinemodels/t4.ermm.
192*f22f0ef4Schristos   // Most users prefer to look at the hexadecimal version of virtual
193*f22f0ef4Schristos   // addresses. Display only the hexadecimal version of virtual addresses
194*f22f0ef4Schristos   // for all machine model views with an exception of virtual page size.
195*f22f0ef4Schristos   if (dbe_strcmp (msname, NTXT ("Memory_page_size")) == 0)
196*f22f0ef4Schristos     name = dbe_sprintf (NTXT ("%s 0x%16.16llx (%llu)"), msname,
197*f22f0ef4Schristos 			(long long) index, (unsigned long long) index);
198*f22f0ef4Schristos   else if (dbe_strcmp (msname, NTXT ("Memory_in_home_lgrp")) == 0)
199*f22f0ef4Schristos     name = dbe_sprintf (NTXT ("%s: %s"), msname,
200*f22f0ef4Schristos 			index == 1 ? GTXT ("True") : index == 0 ? GTXT ("False")
201*f22f0ef4Schristos 			: GTXT ("<Unknown>"));
202*f22f0ef4Schristos   else if (dbe_strcmp (msname, NTXT ("Memory_lgrp")) == 0)
203*f22f0ef4Schristos     name = dbe_sprintf (NTXT ("%s %llu"), msname, (unsigned long long) index);
204*f22f0ef4Schristos   else
205*f22f0ef4Schristos     name = dbe_sprintf (NTXT ("%s 0x%16.16llx"), msname, (long long) index);
206*f22f0ef4Schristos 
207*f22f0ef4Schristos   res = new MemObj (index, name);
208*f22f0ef4Schristos   return res;
209*f22f0ef4Schristos }
210*f22f0ef4Schristos 
211*f22f0ef4Schristos 
212*f22f0ef4Schristos static Vector<MemObjType_t*> dyn_memobj_vec;
213*f22f0ef4Schristos static Vector<MemObjType_t*> *dyn_memobj = &dyn_memobj_vec;
214*f22f0ef4Schristos static Vector<int> *ordlist;
215*f22f0ef4Schristos 
216*f22f0ef4Schristos // Static function to get a vector of custom memory object definitions
217*f22f0ef4Schristos 
218*f22f0ef4Schristos Vector<void*> *
getMemObjects()219*f22f0ef4Schristos MemorySpace::getMemObjects ()
220*f22f0ef4Schristos {
221*f22f0ef4Schristos   MemObjType_t *mot;
222*f22f0ef4Schristos   int ii;
223*f22f0ef4Schristos   int size = dyn_memobj->size ();
224*f22f0ef4Schristos   Vector<int> *indx = new Vector<int>(size);
225*f22f0ef4Schristos   Vector<char*> *name = new Vector<char*>(size);
226*f22f0ef4Schristos   Vector<char> *mnemonic = new Vector<char>(size);
227*f22f0ef4Schristos   Vector<char*> *formula = new Vector<char*>(size);
228*f22f0ef4Schristos   Vector<char*> *machmodel = new Vector<char*>(size);
229*f22f0ef4Schristos   Vector<int> *order = new Vector<int>(size);
230*f22f0ef4Schristos   Vector<char*> *sdesc = new Vector<char*>(size);
231*f22f0ef4Schristos   Vector<char*> *ldesc = new Vector<char*>(size);
232*f22f0ef4Schristos 
233*f22f0ef4Schristos   if (size > 0)
234*f22f0ef4Schristos     {
235*f22f0ef4Schristos       Vec_loop (MemObjType_t *, dyn_memobj, ii, mot)
236*f22f0ef4Schristos       {
237*f22f0ef4Schristos 	indx->store (ii, mot->type);
238*f22f0ef4Schristos 	order->store (ii, ii);
239*f22f0ef4Schristos 	name->store (ii, dbe_strdup (mot->name));
240*f22f0ef4Schristos 	formula->store (ii, dbe_strdup (mot->index_expr));
241*f22f0ef4Schristos 	mnemonic->store (ii, mot->mnemonic);
242*f22f0ef4Schristos 	sdesc->store (ii, mot->short_description == NULL ? NULL
243*f22f0ef4Schristos 		      : dbe_strdup (mot->short_description));
244*f22f0ef4Schristos 	ldesc->store (ii, mot->long_description == NULL ? NULL
245*f22f0ef4Schristos 		      : dbe_strdup (mot->long_description));
246*f22f0ef4Schristos 	if (mot->machmodel == NULL)
247*f22f0ef4Schristos 	  machmodel->store (ii, NULL);
248*f22f0ef4Schristos 	else
249*f22f0ef4Schristos 	  machmodel->store (ii, dbe_strdup (mot->machmodel));
250*f22f0ef4Schristos       }
251*f22f0ef4Schristos     }
252*f22f0ef4Schristos   Vector<void*> *res = new Vector<void*>(8);
253*f22f0ef4Schristos   res->store (0, indx);
254*f22f0ef4Schristos   res->store (1, name);
255*f22f0ef4Schristos   res->store (2, mnemonic);
256*f22f0ef4Schristos   res->store (3, formula);
257*f22f0ef4Schristos   res->store (4, machmodel);
258*f22f0ef4Schristos   res->store (5, order);
259*f22f0ef4Schristos   res->store (6, sdesc);
260*f22f0ef4Schristos   res->store (7, ldesc);
261*f22f0ef4Schristos   return (res);
262*f22f0ef4Schristos }
263*f22f0ef4Schristos 
264*f22f0ef4Schristos // Static function to set order of memory object tabs
265*f22f0ef4Schristos void
set_MemTabOrder(Vector<int> * orders)266*f22f0ef4Schristos MemorySpace::set_MemTabOrder (Vector<int> *orders)
267*f22f0ef4Schristos {
268*f22f0ef4Schristos   int size = orders->size ();
269*f22f0ef4Schristos   ordlist = new Vector<int>(size);
270*f22f0ef4Schristos   for (int i = 0; i < size; i++)
271*f22f0ef4Schristos     ordlist->store (i, orders->fetch (i));
272*f22f0ef4Schristos }
273*f22f0ef4Schristos 
274*f22f0ef4Schristos // Static function to define a new memory object type
275*f22f0ef4Schristos char *
mobj_define(char * mname,char * mindex_exp,char * _machmodel,char * short_description,char * long_description)276*f22f0ef4Schristos MemorySpace::mobj_define (char *mname, char *mindex_exp, char *_machmodel,
277*f22f0ef4Schristos 			  char *short_description, char *long_description)
278*f22f0ef4Schristos {
279*f22f0ef4Schristos   MemObjType_t *mot;
280*f22f0ef4Schristos 
281*f22f0ef4Schristos   if (mname == NULL)
282*f22f0ef4Schristos     return dbe_strdup (GTXT ("No memory object name has been specified."));
283*f22f0ef4Schristos   if (isalpha ((int) (mname[0])) == 0)
284*f22f0ef4Schristos     return dbe_sprintf (GTXT ("Memory Object type name %s does not begin with an alphabetic character"),
285*f22f0ef4Schristos 			mname);
286*f22f0ef4Schristos   char *p = mname;
287*f22f0ef4Schristos   while (*p != 0)
288*f22f0ef4Schristos     {
289*f22f0ef4Schristos       if (isalnum ((int) (*p)) == 0 && *p != '_')
290*f22f0ef4Schristos 	return dbe_sprintf (GTXT ("Memory Object type name %s contains a non-alphanumeric character"),
291*f22f0ef4Schristos 			    mname);
292*f22f0ef4Schristos       p++;
293*f22f0ef4Schristos     }
294*f22f0ef4Schristos 
295*f22f0ef4Schristos   mot = findMemSpaceByName (mname);
296*f22f0ef4Schristos   if (mot != NULL)
297*f22f0ef4Schristos     {
298*f22f0ef4Schristos       if (strcmp (mot->index_expr, mindex_exp) == 0)
299*f22f0ef4Schristos 	// It's a redefinition, but the new definition is the same
300*f22f0ef4Schristos 	return NULL;
301*f22f0ef4Schristos       return dbe_sprintf (GTXT ("Memory/Index Object type name %s is already defined"),
302*f22f0ef4Schristos 			  mname);
303*f22f0ef4Schristos     }
304*f22f0ef4Schristos 
305*f22f0ef4Schristos   // make sure the name is not in use
306*f22f0ef4Schristos   if (dbeSession->findIndexSpaceByName (mname) >= 0)
307*f22f0ef4Schristos     return dbe_sprintf (GTXT ("Memory/Index Object type name %s is already defined"),
308*f22f0ef4Schristos 			mname);
309*f22f0ef4Schristos 
310*f22f0ef4Schristos   if (mindex_exp == NULL || *mindex_exp == 0)
311*f22f0ef4Schristos     return dbe_strdup (GTXT ("No index-expr has been specified."));
312*f22f0ef4Schristos 
313*f22f0ef4Schristos   // verify that the index expression parses correctly
314*f22f0ef4Schristos   Expression *e = dbeSession->ql_parse (mindex_exp);
315*f22f0ef4Schristos   if (e == NULL)
316*f22f0ef4Schristos     return dbe_sprintf (GTXT ("Memory Object index expression is invalid: %s"),
317*f22f0ef4Schristos 			mindex_exp);
318*f22f0ef4Schristos   delete e;
319*f22f0ef4Schristos 
320*f22f0ef4Schristos   // It's OK, create the new table entry
321*f22f0ef4Schristos   char *s = dbeSession->indxobj_define (mname, NULL, mindex_exp,
322*f22f0ef4Schristos 					short_description, long_description);
323*f22f0ef4Schristos   if (s)
324*f22f0ef4Schristos     return s;
325*f22f0ef4Schristos   IndexObjType_t *indObj = dbeSession->findIndexSpace (mname);
326*f22f0ef4Schristos 
327*f22f0ef4Schristos   mot = new MemObjType_t;
328*f22f0ef4Schristos   mot->type = indObj->type;
329*f22f0ef4Schristos   indObj->memObj = mot;
330*f22f0ef4Schristos   mot->name = dbe_strdup (mname);
331*f22f0ef4Schristos   mot->index_expr = dbe_strdup (mindex_exp);
332*f22f0ef4Schristos   mot->mnemonic = MemorySpace::pickMnemonic (mname);
333*f22f0ef4Schristos   mot->machmodel = dbe_strdup (_machmodel);
334*f22f0ef4Schristos   mot->short_description = dbe_strdup (short_description);
335*f22f0ef4Schristos   mot->long_description = dbe_strdup (long_description);
336*f22f0ef4Schristos 
337*f22f0ef4Schristos   // add it to the list
338*f22f0ef4Schristos   dyn_memobj->append (mot);
339*f22f0ef4Schristos 
340*f22f0ef4Schristos   // tell the session
341*f22f0ef4Schristos   if (dbeSession != NULL)
342*f22f0ef4Schristos     dbeSession->mobj_define (mot);
343*f22f0ef4Schristos   return NULL;
344*f22f0ef4Schristos }
345*f22f0ef4Schristos 
346*f22f0ef4Schristos // Static function to delete a new memory object type
347*f22f0ef4Schristos 
348*f22f0ef4Schristos char *
mobj_delete(char * mname)349*f22f0ef4Schristos MemorySpace::mobj_delete (char *mname)
350*f22f0ef4Schristos {
351*f22f0ef4Schristos   if (mname == NULL)
352*f22f0ef4Schristos     return dbe_strdup (GTXT ("No memory object name has been specified.\n"));
353*f22f0ef4Schristos 
354*f22f0ef4Schristos   // search the dynamic types
355*f22f0ef4Schristos   for (long idx = 0, sz = VecSize (dyn_memobj); idx < sz; idx++)
356*f22f0ef4Schristos     {
357*f22f0ef4Schristos       MemObjType_t *mt = dyn_memobj->get (idx);
358*f22f0ef4Schristos       if (strcasecmp (mt->name, mname) == 0)
359*f22f0ef4Schristos 	{
360*f22f0ef4Schristos 	  // delete it from the vector
361*f22f0ef4Schristos 	  mt = dyn_memobj->remove (idx);
362*f22f0ef4Schristos 	  delete mt;
363*f22f0ef4Schristos 	  dbeSession->removeIndexSpaceByName (mname);
364*f22f0ef4Schristos 	  return NULL;
365*f22f0ef4Schristos 	}
366*f22f0ef4Schristos     }
367*f22f0ef4Schristos   return dbe_sprintf (GTXT ("Memory object `%s' is not defined.\n"), mname);
368*f22f0ef4Schristos }
369*f22f0ef4Schristos 
370*f22f0ef4Schristos // Static function to get a list of memory object names from a machine model
371*f22f0ef4Schristos 
372*f22f0ef4Schristos Vector <char*> *
getMachineModelMemObjs(char * mname)373*f22f0ef4Schristos MemorySpace::getMachineModelMemObjs (char *mname)
374*f22f0ef4Schristos {
375*f22f0ef4Schristos   Vector <char *> *ret = new Vector <char *> ();
376*f22f0ef4Schristos   if (mname == NULL)
377*f22f0ef4Schristos     return ret;
378*f22f0ef4Schristos 
379*f22f0ef4Schristos   // search the memory objects
380*f22f0ef4Schristos   int idx;
381*f22f0ef4Schristos   MemObjType_t *mt;
382*f22f0ef4Schristos   Vec_loop (MemObjType_t*, dyn_memobj, idx, mt)
383*f22f0ef4Schristos   {
384*f22f0ef4Schristos     if (mt->machmodel != NULL && strcmp (mt->machmodel, mname) == 0)
385*f22f0ef4Schristos       {
386*f22f0ef4Schristos 	char *n = dbe_strdup (mt->name);
387*f22f0ef4Schristos 	ret->append (n);
388*f22f0ef4Schristos       }
389*f22f0ef4Schristos   }
390*f22f0ef4Schristos   return ret;
391*f22f0ef4Schristos }
392*f22f0ef4Schristos 
393*f22f0ef4Schristos char
pickMnemonic(char * name)394*f22f0ef4Schristos MemorySpace::pickMnemonic (char *name)
395*f22f0ef4Schristos {
396*f22f0ef4Schristos   return name[0];
397*f22f0ef4Schristos }
398*f22f0ef4Schristos 
399*f22f0ef4Schristos void
get_filter_keywords(Vector<void * > * res)400*f22f0ef4Schristos MemorySpace::get_filter_keywords (Vector <void*> *res)
401*f22f0ef4Schristos {
402*f22f0ef4Schristos   Vector <char*> *kwCategory = (Vector<char*>*) res->fetch (0);
403*f22f0ef4Schristos   Vector <char*> *kwCategoryI18N = (Vector<char*>*) res->fetch (1);
404*f22f0ef4Schristos   Vector <char*> *kwDataType = (Vector<char*>*) res->fetch (2);
405*f22f0ef4Schristos   Vector <char*> *kwKeyword = (Vector<char*>*) res->fetch (3);
406*f22f0ef4Schristos   Vector <char*> *kwFormula = (Vector<char*>*) res->fetch (4);
407*f22f0ef4Schristos   Vector <char*> *kwDescription = (Vector<char*>*) res->fetch (5);
408*f22f0ef4Schristos   Vector <void*> *kwEnumDescs = (Vector<void*>*) res->fetch (6);
409*f22f0ef4Schristos 
410*f22f0ef4Schristos   char *vtypeNames[] = VTYPE_TYPE_NAMES;
411*f22f0ef4Schristos   for (int i = 0, sz = dyn_memobj ? dyn_memobj->size () : 0; i < sz; i++)
412*f22f0ef4Schristos     {
413*f22f0ef4Schristos       MemObjType_t *obj = dyn_memobj->fetch (i);
414*f22f0ef4Schristos       kwCategory->append (dbe_strdup (NTXT ("FK_MEMOBJ")));
415*f22f0ef4Schristos       kwCategoryI18N->append (dbe_strdup (GTXT ("Memory Object Definitions")));
416*f22f0ef4Schristos       kwDataType->append (dbe_strdup (vtypeNames[TYPE_INT64]));
417*f22f0ef4Schristos       kwKeyword->append (dbe_strdup (obj->name));
418*f22f0ef4Schristos       kwFormula->append (dbe_strdup (obj->index_expr));
419*f22f0ef4Schristos       kwDescription->append (NULL);
420*f22f0ef4Schristos       kwEnumDescs->append (NULL);
421*f22f0ef4Schristos     }
422*f22f0ef4Schristos }
423*f22f0ef4Schristos 
424*f22f0ef4Schristos MemObjType_t *
findMemSpaceByName(const char * mname)425*f22f0ef4Schristos MemorySpace::findMemSpaceByName (const char *mname)
426*f22f0ef4Schristos {
427*f22f0ef4Schristos   int idx;
428*f22f0ef4Schristos   MemObjType_t *mt;
429*f22f0ef4Schristos 
430*f22f0ef4Schristos   // search the dynamic types
431*f22f0ef4Schristos   Vec_loop (MemObjType_t*, dyn_memobj, idx, mt)
432*f22f0ef4Schristos   {
433*f22f0ef4Schristos     if (strcasecmp (mt->name, mname) == 0)
434*f22f0ef4Schristos       return mt;
435*f22f0ef4Schristos   }
436*f22f0ef4Schristos   return NULL;
437*f22f0ef4Schristos }
438*f22f0ef4Schristos 
439*f22f0ef4Schristos MemObjType_t *
findMemSpaceByIndex(int index)440*f22f0ef4Schristos MemorySpace::findMemSpaceByIndex (int index)
441*f22f0ef4Schristos {
442*f22f0ef4Schristos   int idx;
443*f22f0ef4Schristos   MemObjType_t *mt;
444*f22f0ef4Schristos 
445*f22f0ef4Schristos   // search the dynamic types
446*f22f0ef4Schristos   Vec_loop (MemObjType_t*, dyn_memobj, idx, mt)
447*f22f0ef4Schristos   {
448*f22f0ef4Schristos     if (mt->type == index)
449*f22f0ef4Schristos       return mt;
450*f22f0ef4Schristos   }
451*f22f0ef4Schristos   return NULL;
452*f22f0ef4Schristos }
453