aboutsummaryrefslogtreecommitdiff
path: root/decoder/tests/snapshot_parser_lib/source/ss_to_dcdtree.cpp
blob: c3782a2d39c5143cf2020046840913adc73ee044 (plain)
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
/*
 * \file       ss_to_dcdtree.cpp
 * \brief      OpenCSD : 
 * 
 * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
 */

/* 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 * this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution. 
 * 
 * 3. Neither the name of the copyright holder nor the names of its contributors 
 * may be used to endorse or promote products derived from this software without 
 * specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */ 

#include "ss_to_dcdtree.h"
#include "ss_key_value_names.h"


CreateDcdTreeFromSnapShot::CreateDcdTreeFromSnapShot() :
    m_bInit(false),
    m_pDecodeTree(0),
    m_pReader(0),
    m_pErrLogInterface(0),    
    m_bPacketProcOnly(false),
    m_BufferFileName("")
{
    m_errlog_handle = 0;
    m_add_create_flags = 0;
}

CreateDcdTreeFromSnapShot::~CreateDcdTreeFromSnapShot()
{
    destroyDecodeTree();
}
    
void CreateDcdTreeFromSnapShot::initialise(SnapShotReader *pReader, ITraceErrorLog *pErrLogInterface)
{
    if((pErrLogInterface != 0) && (pReader != 0))
    {
        m_pReader = pReader;
        m_pErrLogInterface = pErrLogInterface;
        m_errlog_handle = m_pErrLogInterface->RegisterErrorSource("ss2_dcdtree");
        m_bInit = true;
    }
}

bool CreateDcdTreeFromSnapShot::createDecodeTree(const std::string &SourceName, bool bPacketProcOnly, uint32_t add_create_flags)
{    
    m_add_create_flags = add_create_flags;
    if(m_bInit)
    {
        if(!m_pReader->snapshotReadOK())
        {
            LogError("Supplied snapshot reader has not correctly read the snapshot.\n");
            return false;
        }

        m_bPacketProcOnly = bPacketProcOnly;
        Parser::TraceBufferSourceTree tree;

        if(m_pReader->getTraceBufferSourceTree(SourceName, tree))
        {
            int numDecodersCreated = 0; // count how many we create - if none then give up.
            uint32_t formatter_flags = OCSD_DFRMTR_FRAME_MEM_ALIGN;

            /* make a note of the trace binary file name + path to ss directory */            
            m_BufferFileName = m_pReader->getSnapShotDir() + tree.buffer_info.dataFileName;

            ocsd_dcd_tree_src_t src_format = tree.buffer_info.dataFormat == "source_data" ? OCSD_TRC_SRC_SINGLE : OCSD_TRC_SRC_FRAME_FORMATTED;

            if (tree.buffer_info.dataFormat == "dstream_coresight")
                formatter_flags = OCSD_DFRMTR_HAS_FSYNCS;

            /* create the initial device tree */
            // TBD:     handle syncs / hsyncs data from TPIU
            m_pDecodeTree = DecodeTree::CreateDecodeTree(src_format, formatter_flags);
            if(m_pDecodeTree == 0)
            {
                LogError("Failed to create decode tree object\n");
                return false;
            }

            // use our error logger - don't use the tree default.
            m_pDecodeTree->setAlternateErrorLogger(m_pErrLogInterface);

            if(!bPacketProcOnly)
            {
                m_pDecodeTree->createMemAccMapper();
            }

            /* run through each protocol source to this buffer... */
            std::map<std::string, std::string>::iterator it = tree.source_core_assoc.begin();

            while(it != tree.source_core_assoc.end())
            {
                Parser::Parsed *etm_dev, *core_dev;
                if(m_pReader->getDeviceData(it->first,&etm_dev))
                {
                    // found the device data for this device.

                    // see if we have a core name (STM / ITM not associated with a core);
                    std::string coreDevName = it->second;
                    if(coreDevName.size() > 0)
                    {
                        if(m_pReader->getDeviceData(coreDevName,&core_dev))
                        {
                            if(createPEDecoder(core_dev->deviceTypeName,etm_dev))
                            {
                                numDecodersCreated++;
                                if(!bPacketProcOnly &&(core_dev->dumpDefs.size() > 0))
                                {
                                    processDumpfiles(core_dev->dumpDefs);
                                }
                            }
                            else
                            {
                                std::ostringstream oss;
                                oss << "Failed to create decoder for source " << it->first << ".\n";
                                LogError(oss.str());
                            }
                        }
                        else
                        {
                            // Could not find the device data for the core.
                            // unexpected - since we created the associations.
                            std::ostringstream oss;
                            oss << "Failed to get device data for source " << it->first << ".\n";
                            LogError(oss.str());
                        }
                    }
                    else
                    {
                        // none-core source 
                        if(createSTDecoder(etm_dev))
                        {
                             numDecodersCreated++;
                        }
                        else
                        {
                            std::ostringstream oss;
                            oss << "Failed to create decoder for none core source " << it->first << ".\n";
                            LogError(oss.str());
                        }
                    }
                }
                else
                {
                    // TBD: could not find the device data for the source.
                    // again unexpected - suggests ss format error.
                    std::ostringstream oss;
                    oss << "Failed to find device data for source " << it->first << ".\n";
                    LogError(oss.str());
                }
                if(src_format == OCSD_TRC_SRC_SINGLE)
                    it = tree.source_core_assoc.end();
                else
                    it++;
            }

            if(numDecodersCreated == 0)
            {
                // nothing useful found 
                destroyDecodeTree();
            }
        }
        else
        {
            std::ostringstream oss;
            oss << "Failed to get parsed source tree for buffer " << SourceName << ".\n";
            LogError(oss.str());
        }
    }
    return (bool)(m_pDecodeTree != 0);
}

void CreateDcdTreeFromSnapShot::destroyDecodeTree()
{
    if(m_pDecodeTree)
        DecodeTree::DestroyDecodeTree(m_pDecodeTree);
    m_pDecodeTree = 0;
    m_pReader = 0;
    m_pErrLogInterface = 0;
    m_errlog_handle = 0;
    m_BufferFileName = "";
}

void  CreateDcdTreeFromSnapShot::LogError(const std::string &msg)
{
    ocsdError err(OCSD_ERR_SEV_ERROR,OCSD_ERR_TEST_SS_TO_DECODER,msg);
    m_pErrLogInterface->LogError(m_errlog_handle,&err);
}

void CreateDcdTreeFromSnapShot::LogError(const ocsdError &err)
{
    m_pErrLogInterface->LogError(m_errlog_handle,&err);
}

bool CreateDcdTreeFromSnapShot::createPEDecoder(const std::string &coreName, Parser::Parsed *devSrc)
{
    bool bCreatedDecoder = false;
    std::string devTypeName = devSrc->deviceTypeName;

    // split off .x from type name.
    std::string::size_type pos = devTypeName.find_first_of('.');
    if(pos != std::string::npos)
        devTypeName = devTypeName.substr(0,pos);

    // split according to protocol 
    if(devTypeName == ETMv4Protocol)
    {
        bCreatedDecoder = createETMv4Decoder(coreName,devSrc);
    }
    else if(devTypeName == ETMv3Protocol)
    {
        bCreatedDecoder = createETMv3Decoder(coreName,devSrc);
    }
    else if(devTypeName == PTMProtocol || devTypeName == PFTProtocol)
    {
        bCreatedDecoder = createPTMDecoder(coreName,devSrc);
    }
    else if (devTypeName == ETEProtocol)
    {
        bCreatedDecoder = createETEDecoder(coreName, devSrc);
    }

    return bCreatedDecoder;
}

// create an ETMv4 decoder based on the deviceN.ini file.
bool CreateDcdTreeFromSnapShot::createETMv4Decoder(const std::string &coreName, Parser::Parsed *devSrc, const bool bDataChannel /* = false*/)
{
    bool createdDecoder = false;
    bool configOK = true;
    
    // generate the config data from the device data.
    ocsd_etmv4_cfg config;

    regs_to_access_t regs_to_access[] = {
        { ETMv4RegCfg, true, &config.reg_configr, 0 },
        { ETMv4RegIDR, true, &config.reg_traceidr, 0 },
        { ETMv4RegIDR0, true, &config.reg_idr0, 0 },
        { ETMv4RegIDR1, false, &config.reg_idr1, 0x4100F403 },
        { ETMv4RegIDR2, true, &config.reg_idr2, 0 },
        { ETMv4RegIDR8, false, &config.reg_idr8, 0 },
        { ETMv4RegIDR9, false, &config.reg_idr9, 0 },
        { ETMv4RegIDR10, false, &config.reg_idr10, 0 },
        { ETMv4RegIDR11, false, &config.reg_idr11, 0 },
        { ETMv4RegIDR12, false, &config.reg_idr12, 0 },
        { ETMv4RegIDR13,false, &config.reg_idr13, 0 },
    };

    // extract registers
    configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);

    // extract core profile
    if(configOK)
        configOK = getCoreProfile(coreName,config.arch_ver,config.core_prof);

    // good config - generate the decoder on the tree.
    if(configOK)
    {
        ocsd_err_t err = OCSD_OK;
        EtmV4Config configObj(&config);
        const char *decoderName = bDataChannel ? OCSD_BUILTIN_DCD_ETMV4D : OCSD_BUILTIN_DCD_ETMV4I;

        err = m_pDecodeTree->createDecoder(decoderName, m_add_create_flags | (m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER),&configObj);
        
        if(err ==  OCSD_OK)
            createdDecoder = true;
        else
        {
            std::string msg = "Snapshot processor : failed to create " +  (std::string)decoderName + " decoder on decode tree.";
            LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,msg));
        }
    }

    return createdDecoder;
}

bool CreateDcdTreeFromSnapShot::createETEDecoder(const std::string &coreName, Parser::Parsed *devSrc)
{
    bool createdDecoder = false;
    bool configOK = true;

    // generate the config data from the device data.
    ocsd_ete_cfg config;   

    // ete regs are same names Etmv4 in places...
    regs_to_access_t regs_to_access[] = {
        { ETMv4RegCfg, true, &config.reg_configr, 0 },
        { ETMv4RegIDR, true, &config.reg_traceidr, 0 },
        { ETMv4RegIDR0, true, &config.reg_idr0, 0 },
        { ETMv4RegIDR1, false, &config.reg_idr1, 0x4100F403 },
        { ETMv4RegIDR2, true, &config.reg_idr2, 0 },
        { ETMv4RegIDR8, false, &config.reg_idr8, 0 },
        { ETERegDevArch, false, &config.reg_devarch, 0x47705A13 },
    };

    // extract registers
    configOK = getRegisters(devSrc->regDefs, sizeof(regs_to_access) / sizeof(regs_to_access_t), regs_to_access);

    // extract core profile
    if (configOK)
        configOK = getCoreProfile(coreName, config.arch_ver, config.core_prof);

    // good config - generate the decoder on the tree.
    if (configOK)
    {
        ocsd_err_t err = OCSD_OK;
        ETEConfig configObj(&config);
        const char *decoderName = OCSD_BUILTIN_DCD_ETE;

        err = m_pDecodeTree->createDecoder(decoderName, m_add_create_flags | (m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER), &configObj);

        if (err == OCSD_OK)
            createdDecoder = true;
        else
        {
            std::string msg = "Snapshot processor : failed to create " + (std::string)decoderName + " decoder on decode tree.";
            LogError(ocsdError(OCSD_ERR_SEV_ERROR, err, msg));
        }
    }

    return createdDecoder;
}

// create an ETMv3 decoder based on the register values in the deviceN.ini file.
bool CreateDcdTreeFromSnapShot::createETMv3Decoder(const std::string &coreName, Parser::Parsed *devSrc)
{
    bool createdDecoder = false;
    bool configOK = true;
    
    // generate the config data from the device data.
    ocsd_etmv3_cfg cfg_regs;

    regs_to_access_t regs_to_access[] = {
        { ETMv3PTMRegIDR, true, &cfg_regs.reg_idr, 0 },
        { ETMv3PTMRegCR, true, &cfg_regs.reg_ctrl, 0 },
        { ETMv3PTMRegCCER, true, &cfg_regs.reg_ccer, 0 },
        { ETMv3PTMRegTraceIDR, true, &cfg_regs.reg_trc_id, 0}
    };

    // extract registers
    configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);

    // extract core profile
    if(configOK)
        configOK = getCoreProfile(coreName,cfg_regs.arch_ver,cfg_regs.core_prof);

    // good config - generate the decoder on the tree.
    if(configOK)
    {
        EtmV3Config config(&cfg_regs);
        ocsd_err_t err = OCSD_OK;
        err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_ETMV3, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&config);

        if(err ==  OCSD_OK)
            createdDecoder = true;
        else
            LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create ETMV3 decoder on decode tree."));
    }
    return createdDecoder;
}

bool CreateDcdTreeFromSnapShot::createPTMDecoder(const std::string &coreName, Parser::Parsed *devSrc)
{
    bool createdDecoder = false;
    bool configOK = true;
    
    // generate the config data from the device data.
    
    ocsd_ptm_cfg config;

    regs_to_access_t regs_to_access[] = {
        { ETMv3PTMRegIDR, true, &config.reg_idr, 0 },
        { ETMv3PTMRegCR, true, &config.reg_ctrl, 0 },
        { ETMv3PTMRegCCER, true, &config.reg_ccer, 0 },
        { ETMv3PTMRegTraceIDR, true, &config.reg_trc_id, 0}
    };

    // extract registers
    configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);

    // extract core profile
    if(configOK)
        configOK = getCoreProfile(coreName,config.arch_ver,config.core_prof);

    // good config - generate the decoder on the tree.
    if(configOK)
    {
        PtmConfig configObj(&config);
        ocsd_err_t err = OCSD_OK;
        err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_PTM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);

        if(err ==  OCSD_OK)
            createdDecoder = true;
        else
            LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create PTM decoder on decode tree."));
    }
    return createdDecoder;
}

bool CreateDcdTreeFromSnapShot::createSTDecoder(Parser::Parsed *devSrc)
{
    bool bCreatedDecoder = false;
    std::string devTypeName = devSrc->deviceTypeName;

    // split off .x from type name.
    std::string::size_type pos = devTypeName.find_first_of('.');
    if(pos != std::string::npos)
        devTypeName = devTypeName.substr(0,pos);

    if(devTypeName == STMProtocol)
    {
        bCreatedDecoder = createSTMDecoder(devSrc);
    }

    return bCreatedDecoder;
}

bool CreateDcdTreeFromSnapShot::createSTMDecoder(Parser::Parsed *devSrc)
{
    bool createdDecoder = false;
    bool configOK = true;

    // generate the config data from the device data.
    
    ocsd_stm_cfg config;

    regs_to_access_t regs_to_access[] = {
        { STMRegTCSR, true, &config.reg_tcsr, 0 }
    };

    configOK = getRegisters(devSrc->regDefs,sizeof(regs_to_access)/sizeof(regs_to_access_t), regs_to_access);
    if(configOK)
    {
        ocsd_err_t err = OCSD_OK;
        STMConfig configObj(&config);

        err = m_pDecodeTree->createDecoder(OCSD_BUILTIN_DCD_STM, m_bPacketProcOnly ? OCSD_CREATE_FLG_PACKET_PROC : OCSD_CREATE_FLG_FULL_DECODER,&configObj);

        if(err ==  OCSD_OK)
            createdDecoder = true;
        else
            LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,"Snapshot processor : failed to create STM decoder on decode tree."));
    }

    return createdDecoder;
}



// get a set of register values.
bool CreateDcdTreeFromSnapShot::getRegisters(std::map<std::string, std::string, Util::CaseInsensitiveLess> &regDefs, int numRegs, regs_to_access_t *reg_access_array)
{
    bool regsOK = true;

    for(int rv = 0; rv < numRegs; rv++)
    {
        if(!getRegByPrefix( regDefs,reg_access_array[rv]))
            regsOK = false;
    }
    return regsOK;
}

// strip out any parts with brackets
bool CreateDcdTreeFromSnapShot::getRegByPrefix(std::map<std::string, std::string, Util::CaseInsensitiveLess> &regDefs, 
    regs_to_access_t &reg_accessor)
{
    std::ostringstream oss;
    bool bFound = false;
    std::map<std::string, std::string, Util::CaseInsensitiveLess>::iterator it;
    std::string prefix_cmp;
    std::string::size_type pos;
    std::string strval;
    
    *reg_accessor.value = 0;

    it = regDefs.begin();
    while((it != regDefs.end()) && !bFound)
    {
        prefix_cmp = it->first;
        pos = prefix_cmp.find_first_of('(');
        if(pos != std::string::npos)
        {
            prefix_cmp = prefix_cmp.substr(0, pos);
        }
        if(prefix_cmp == reg_accessor.pszName)
        {
            strval = it->second;
            bFound = true;
        }
        it++;
    }

    if(bFound)
        *reg_accessor.value = strtoul(strval.c_str(),0,0);
    else
    {
        ocsd_err_severity_t sev = OCSD_ERR_SEV_ERROR;
        if(reg_accessor.failIfMissing)
        {
            oss << "Error:";
        }
        else
        {
            // no fail if missing - set any default and just warn.
            bFound = true;
            oss << "Warning: Default set for register. ";
            sev = OCSD_ERR_SEV_WARN;
            *reg_accessor.value = reg_accessor.val_default;
        }
        oss << "Missing " << reg_accessor.pszName << "\n";
        m_pErrLogInterface->LogMessage(m_errlog_handle, sev, oss.str());
    }
    return bFound;
}

bool CreateDcdTreeFromSnapShot::getCoreProfile(const std::string &coreName, ocsd_arch_version_t &arch_ver, ocsd_core_profile_t &core_prof)
{
    bool profileOK = true;
    ocsd_arch_profile_t ap = m_arch_profiles.getArchProfile(coreName);
    if(ap.arch != ARCH_UNKNOWN)
    {
        arch_ver = ap.arch;
        core_prof = ap.profile;
    }
    else
    {
        std::ostringstream oss;
        oss << "Unrecognized Core name " << coreName << ". Cannot evaluate profile or architecture.";
        LogError(oss.str());
        profileOK = false;
    }
    return profileOK;
}

typedef struct mem_space_keys {
    const char* key_name;
    ocsd_mem_space_acc_t memspace;
} mem_space_keys_t;

static mem_space_keys_t space_map[] = {
    /* single spaces */
    { "EL1S", OCSD_MEM_SPACE_EL1S },
    { "EL1N", OCSD_MEM_SPACE_EL1N },
    { "EL1R", OCSD_MEM_SPACE_EL1R },
    { "EL2S", OCSD_MEM_SPACE_EL2S },
    { "EL2" , OCSD_MEM_SPACE_EL2 }, /* old EL2 NS name - prior to EL2S existing */
    { "EL2N", OCSD_MEM_SPACE_EL2 },
    { "EL2R", OCSD_MEM_SPACE_EL2R },
    { "EL3" , OCSD_MEM_SPACE_EL3  },
    { "ROOT", OCSD_MEM_SPACE_ROOT },
    /* multiple memory spaces */
    { "S"   , OCSD_MEM_SPACE_S},
    { "N"   , OCSD_MEM_SPACE_N},
    { "R"   , OCSD_MEM_SPACE_R},
    { "ANY" , OCSD_MEM_SPACE_ANY},
    /* older names - from spec but not expected to be used in future. */
    { "H"   , OCSD_MEM_SPACE_EL2 }, /* hypervisor - EL2 NS */
    { "P"   , OCSD_MEM_SPACE_EL1N }, /* privileged - EL1 NS */
    { "NP"   , OCSD_MEM_SPACE_EL1N }, /* non secure privileged - EL1 NS */
    { "SP"   , OCSD_MEM_SPACE_EL1S }, /* secure privileged - EL1 S */
    /* table terminator */
    { "", OCSD_MEM_SPACE_NONE},
};

/* get mem space from input string */
ocsd_mem_space_acc_t CreateDcdTreeFromSnapShot::getMemSpaceFromString(const std::string& memspace)
{
    
    
    ocsd_mem_space_acc_t mem_space = OCSD_MEM_SPACE_ANY;
    if (memspace.length() > 0) {
        int i = 0;

        while (space_map[i].memspace != OCSD_MEM_SPACE_NONE) {
            if (space_map[i].key_name == memspace) {
                mem_space = space_map[i].memspace;
                break;
            }
            i++;
        }
    }
    return mem_space;
}

void CreateDcdTreeFromSnapShot::processDumpfiles(std::vector<Parser::DumpDef> &dumps)
{
    std::string dumpFilePathName;
    std::vector<Parser::DumpDef>::const_iterator it;
    ocsd_mem_space_acc_t mem_space;

    it = dumps.begin();
    while(it != dumps.end())
    {        
        dumpFilePathName = m_pReader->getSnapShotDir() + it->path;
        ocsd_file_mem_region_t region;
        ocsd_err_t err = OCSD_OK;

        region.start_address = it->address;
        region.file_offset = it->offset;
        region.region_size = it->length;
        mem_space = getMemSpaceFromString(it->space);

        // ensure we respect optional length and offset parameter and
        // allow multiple dump entries with same file name to define regions
        if (!TrcMemAccessorFile::isExistingFileAccessor(dumpFilePathName))
            err = m_pDecodeTree->addBinFileRegionMemAcc(&region, 1, mem_space, dumpFilePathName);
        else
            err = m_pDecodeTree->updateBinFileRegionMemAcc(&region, 1, mem_space, dumpFilePathName);
        if(err != OCSD_OK)
        {                            
            std::ostringstream oss;
            oss << "Failed to create memory accessor for file " << dumpFilePathName << ".";
            LogError(ocsdError(OCSD_ERR_SEV_ERROR,err,oss.str()));
        }
        it++;
    }
}

/* End of File ss_to_dcdtree.cpp */