OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [exec/] [cmd/] [cmd_symb.cpp] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2017 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      Browse symbols command.
6
 */
7
 
8
#include "iservice.h"
9
#include "cmd_symb.h"
10
#include "coreservices/ielfreader.h"
11
 
12
namespace debugger {
13
 
14
CmdSymb::CmdSymb(ITap *tap, ISocInfo *info)
15
    : ICommand ("symb", tap, info) {
16
 
17
    briefDescr_.make_string("Get symbols list");
18
    detailedDescr_.make_string(
19
        "Description:\n"
20
        "    Read symbols list. Command 'loadelf' must be applied first to\n"
21
        "    make available debug information.\n"
22
        "Usage:\n"
23
        "    symb filter\n"
24
        "Example:\n"
25
        "    symb\n"
26
        "    symb *main*\n");
27
}
28
 
29
bool CmdSymb::isValid(AttributeType *args) {
30
    if ((*args)[0u].is_equal("symb")
31
        && (args->size() == 1 || args->size() == 2)) {
32
        return CMD_VALID;
33
    }
34
    return CMD_INVALID;
35
}
36
 
37
void CmdSymb::exec(AttributeType *args, AttributeType *res) {
38
    res->make_nil();
39
    if (!isValid(args)) {
40
        generateError(res, "Wrong argument list");
41
        return;
42
    }
43
 
44
    AttributeType lstServ;
45
    RISCV_get_services_with_iface(IFACE_ELFREADER, &lstServ);
46
    if (lstServ.size() == 0) {
47
        generateError(res, "Elf-service not found");
48
        return;
49
    }
50
    IService *iserv = static_cast<IService *>(lstServ[0u].to_iface());
51
    IElfReader *elf = static_cast<IElfReader *>(
52
                        iserv->getInterface(IFACE_ELFREADER));
53
 
54
    if (args->size() == 2 && (*args)[1].is_string()) {
55
        AttributeType allSymb;
56
        elf->getSymbols(&allSymb);
57
        applyFilter((*args)[1].to_string(), &allSymb, res);
58
    } else {
59
        elf->getSymbols(res);
60
    }
61
}
62
 
63
void CmdSymb::applyFilter(const char *filt, AttributeType *in,
64
                          AttributeType *out) {
65
    const char *symbname;
66
    out->make_list(0);
67
    for (unsigned i = 0; i < in->size(); i++) {
68
        AttributeType &item = (*in)[i];
69
        symbname = item[Symbol_Name].to_string();
70
        if (filt_pass(filt, symbname)) {
71
            out->add_to_list(&item);
72
        }
73
    }
74
}
75
 
76
bool CmdSymb::filt_pass(const char *filt, const char *symbname) {
77
    bool sequence;
78
    const char *pf, *ps;
79
    while ((*filt) && (*symbname)) {
80
        if (filt[0] == '*') {
81
            filt++;
82
            pf = filt;
83
            sequence = false;
84
            if (pf[0] == '\0') {
85
                return true;
86
            }
87
            while (symbname[0] != '\0') {
88
                if (pf[0] == '\0') {
89
                    return true;
90
                } else if (pf[0] == '*') {
91
                    return filt_pass(pf, symbname);
92
                } else if (pf[0] == symbname[0]) {
93
                    pf++;
94
                    if (!sequence) {
95
                        sequence = true;
96
                        ps = symbname;
97
                    }
98
                } else if (sequence) {
99
                    sequence = false;
100
                    pf = filt;
101
                    symbname = ps;
102
                }
103
                symbname++;
104
            }
105
            if ((pf[0] != 0) && (pf[0] != '*') && (pf[0] != '?')) {
106
                sequence = false;
107
            }
108
            return sequence;
109
        } else if (filt[0] == '?' || symbname[0] == filt[0]) {
110
            filt++;
111
        } else if (symbname[0] != filt[0]) {
112
            return false;
113
        }
114
 
115
        symbname++;
116
    }
117
    return false;
118
}
119
 
120
}  // namespace debugger

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.