File: LLDBReply.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (124 lines) | stat: -rw-r--r-- 4,607 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : LLDBReply.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    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 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "LLDBReply.h"
#include "LLDBEnums.h"

LLDBReply::~LLDBReply() {}

LLDBReply::LLDBReply(const wxString& str)
{
    JSON root(str);
    FromJSON(root.toElement());
}

void LLDBReply::FromJSON(const JSONItem& json)
{
    m_replyType = json.namedObject("m_replyType").toInt(kReplyTypeInvalid);
    m_interruptResaon = json.namedObject("m_stopResaon").toInt(kInterruptReasonNone);
    m_line = json.namedObject("m_line").toInt(wxNOT_FOUND);
    m_filename = json.namedObject("m_filename").toString();
    m_lldbId = json.namedObject("m_lldbId").toInt();
    m_expression = json.namedObject("m_expression").toString();
    m_debugSessionType = json.namedObject("m_debugSessionType").toInt(kDebugSessionTypeNormal);
    m_text = json.namedObject("m_text").toString();
    
    m_breakpoints.clear();
    JSONItem arr = json.namedObject("m_breakpoints");
    for(int i = 0; i < arr.arraySize(); ++i) {
        LLDBBreakpoint::Ptr_t bp(new LLDBBreakpoint());
        bp->FromJSON(arr.arrayItem(i));
        m_breakpoints.push_back(bp);
    }

    m_variables.clear();
    JSONItem localsArr = json.namedObject("m_locals");
    m_variables.reserve(localsArr.arraySize());
    for(int i = 0; i < localsArr.arraySize(); ++i) {
        LLDBVariable::Ptr_t variable(new LLDBVariable());
        variable->FromJSON(localsArr.arrayItem(i));
        m_variables.push_back(variable);
    }

    m_backtrace.Clear();
    JSONItem backtrace = json.namedObject("m_backtrace");
    m_backtrace.FromJSON(backtrace);

    m_threads = LLDBThread::FromJSON(json, "m_threads");
}

JSONItem LLDBReply::ToJSON() const
{
    JSONItem json = JSONItem::createObject();
    json.addProperty("m_replyType", m_replyType);
    json.addProperty("m_stopResaon", m_interruptResaon);
    json.addProperty("m_line", m_line);
    json.addProperty("m_filename", m_filename);
    json.addProperty("m_lldbId", m_lldbId);
    json.addProperty("m_expression", m_expression);
    json.addProperty("m_debugSessionType", m_debugSessionType);
    json.addProperty("m_text", m_text);
    JSONItem bparr = JSONItem::createArray("m_breakpoints");
    json.append(bparr);
    for(size_t i = 0; i < m_breakpoints.size(); ++i) {
        bparr.arrayAppend(m_breakpoints.at(i)->ToJSON());
    }

    JSONItem localsArr = JSONItem::createArray("m_locals");
    json.append(localsArr);
    for(size_t i = 0; i < m_variables.size(); ++i) {
        localsArr.arrayAppend(m_variables.at(i)->ToJSON());
    }

    json.addProperty("m_backtrace", m_backtrace.ToJSON());
    json.append(LLDBThread::ToJSON(m_threads, "m_threads"));
    return json;
}

void LLDBReply::UpdatePaths(const LLDBPivot& pivot)
{
    if(pivot.IsValid()) {

        // Update the file name
        m_filename = pivot.ToLocal(m_filename);

        // Update the breakpoint list
        for(size_t i = 0; i < m_breakpoints.size(); ++i) {
            m_breakpoints.at(i)->SetFilename(pivot.ToLocal(m_breakpoints.at(i)->GetFilename()), false);
        }

        // Update the call stack entries
        LLDBBacktrace::EntryVec_t callstack = m_backtrace.GetCallstack();
        for(size_t i = 0; i < callstack.size(); ++i) {
            callstack.at(i).filename = pivot.ToLocal(callstack.at(i).filename);
        }
        m_backtrace.SetCallstack(callstack);

        // Update the thread stack
        for(size_t i = 0; i < m_threads.size(); ++i) {
            m_threads.at(i).SetFile(pivot.ToLocal(m_threads.at(i).GetFile()));
        }
    }
}