1*fce4895dSRene Gollent /*
2*fce4895dSRene Gollent * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3*fce4895dSRene Gollent * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
4*fce4895dSRene Gollent * Distributed under the terms of the MIT License.
5*fce4895dSRene Gollent */
6*fce4895dSRene Gollent
7*fce4895dSRene Gollent
8*fce4895dSRene Gollent #include "BreakpointSetting.h"
9*fce4895dSRene Gollent
10*fce4895dSRene Gollent #include <Message.h>
11*fce4895dSRene Gollent
12*fce4895dSRene Gollent #include "ArchivingUtils.h"
13*fce4895dSRene Gollent #include "FunctionID.h"
14*fce4895dSRene Gollent #include "LocatableFile.h"
15*fce4895dSRene Gollent #include "UserBreakpoint.h"
16*fce4895dSRene Gollent
17*fce4895dSRene Gollent
BreakpointSetting()18*fce4895dSRene Gollent BreakpointSetting::BreakpointSetting()
19*fce4895dSRene Gollent :
20*fce4895dSRene Gollent fFunctionID(NULL),
21*fce4895dSRene Gollent fSourceFile(),
22*fce4895dSRene Gollent fSourceLocation(),
23*fce4895dSRene Gollent fRelativeAddress(0),
24*fce4895dSRene Gollent fEnabled(false),
25*fce4895dSRene Gollent fHidden(false),
26*fce4895dSRene Gollent fConditionExpression()
27*fce4895dSRene Gollent {
28*fce4895dSRene Gollent }
29*fce4895dSRene Gollent
30*fce4895dSRene Gollent
BreakpointSetting(const BreakpointSetting & other)31*fce4895dSRene Gollent BreakpointSetting::BreakpointSetting(const BreakpointSetting& other)
32*fce4895dSRene Gollent :
33*fce4895dSRene Gollent fFunctionID(other.fFunctionID),
34*fce4895dSRene Gollent fSourceFile(other.fSourceFile),
35*fce4895dSRene Gollent fSourceLocation(other.fSourceLocation),
36*fce4895dSRene Gollent fRelativeAddress(other.fRelativeAddress),
37*fce4895dSRene Gollent fEnabled(other.fEnabled),
38*fce4895dSRene Gollent fHidden(other.fHidden),
39*fce4895dSRene Gollent fConditionExpression(other.fConditionExpression)
40*fce4895dSRene Gollent {
41*fce4895dSRene Gollent if (fFunctionID != NULL)
42*fce4895dSRene Gollent fFunctionID->AcquireReference();
43*fce4895dSRene Gollent }
44*fce4895dSRene Gollent
45*fce4895dSRene Gollent
~BreakpointSetting()46*fce4895dSRene Gollent BreakpointSetting::~BreakpointSetting()
47*fce4895dSRene Gollent {
48*fce4895dSRene Gollent _Unset();
49*fce4895dSRene Gollent }
50*fce4895dSRene Gollent
51*fce4895dSRene Gollent
52*fce4895dSRene Gollent status_t
SetTo(const UserBreakpointLocation & location,bool enabled,bool hidden,const BString & conditionExpression)53*fce4895dSRene Gollent BreakpointSetting::SetTo(const UserBreakpointLocation& location, bool enabled,
54*fce4895dSRene Gollent bool hidden, const BString& conditionExpression)
55*fce4895dSRene Gollent {
56*fce4895dSRene Gollent _Unset();
57*fce4895dSRene Gollent
58*fce4895dSRene Gollent fFunctionID = location.GetFunctionID();
59*fce4895dSRene Gollent if (fFunctionID != NULL)
60*fce4895dSRene Gollent fFunctionID->AcquireReference();
61*fce4895dSRene Gollent
62*fce4895dSRene Gollent if (LocatableFile* file = location.SourceFile())
63*fce4895dSRene Gollent file->GetPath(fSourceFile);
64*fce4895dSRene Gollent
65*fce4895dSRene Gollent fSourceLocation = location.GetSourceLocation();
66*fce4895dSRene Gollent fRelativeAddress = location.RelativeAddress();
67*fce4895dSRene Gollent fEnabled = enabled;
68*fce4895dSRene Gollent fHidden = hidden;
69*fce4895dSRene Gollent fConditionExpression = conditionExpression;
70*fce4895dSRene Gollent
71*fce4895dSRene Gollent return B_OK;
72*fce4895dSRene Gollent }
73*fce4895dSRene Gollent
74*fce4895dSRene Gollent
75*fce4895dSRene Gollent status_t
SetTo(const BMessage & archive)76*fce4895dSRene Gollent BreakpointSetting::SetTo(const BMessage& archive)
77*fce4895dSRene Gollent {
78*fce4895dSRene Gollent _Unset();
79*fce4895dSRene Gollent
80*fce4895dSRene Gollent fFunctionID = ArchivingUtils::UnarchiveChild<FunctionID>(archive,
81*fce4895dSRene Gollent "function");
82*fce4895dSRene Gollent if (fFunctionID == NULL)
83*fce4895dSRene Gollent return B_BAD_VALUE;
84*fce4895dSRene Gollent
85*fce4895dSRene Gollent archive.FindString("sourceFile", &fSourceFile);
86*fce4895dSRene Gollent
87*fce4895dSRene Gollent int32 line;
88*fce4895dSRene Gollent if (archive.FindInt32("line", &line) != B_OK)
89*fce4895dSRene Gollent line = -1;
90*fce4895dSRene Gollent
91*fce4895dSRene Gollent int32 column;
92*fce4895dSRene Gollent if (archive.FindInt32("column", &column) != B_OK)
93*fce4895dSRene Gollent column = -1;
94*fce4895dSRene Gollent
95*fce4895dSRene Gollent fSourceLocation = SourceLocation(line, column);
96*fce4895dSRene Gollent
97*fce4895dSRene Gollent if (archive.FindUInt64("relativeAddress", &fRelativeAddress) != B_OK)
98*fce4895dSRene Gollent fRelativeAddress = 0;
99*fce4895dSRene Gollent
100*fce4895dSRene Gollent if (archive.FindBool("enabled", &fEnabled) != B_OK)
101*fce4895dSRene Gollent fEnabled = false;
102*fce4895dSRene Gollent
103*fce4895dSRene Gollent if (archive.FindBool("hidden", &fHidden) != B_OK)
104*fce4895dSRene Gollent fHidden = false;
105*fce4895dSRene Gollent
106*fce4895dSRene Gollent if (archive.FindString("condition", &fConditionExpression) != B_OK)
107*fce4895dSRene Gollent fConditionExpression.Truncate(0);
108*fce4895dSRene Gollent
109*fce4895dSRene Gollent return B_OK;
110*fce4895dSRene Gollent }
111*fce4895dSRene Gollent
112*fce4895dSRene Gollent
113*fce4895dSRene Gollent status_t
WriteTo(BMessage & archive) const114*fce4895dSRene Gollent BreakpointSetting::WriteTo(BMessage& archive) const
115*fce4895dSRene Gollent {
116*fce4895dSRene Gollent if (fFunctionID == NULL)
117*fce4895dSRene Gollent return B_BAD_VALUE;
118*fce4895dSRene Gollent
119*fce4895dSRene Gollent archive.MakeEmpty();
120*fce4895dSRene Gollent
121*fce4895dSRene Gollent status_t error;
122*fce4895dSRene Gollent if ((error = ArchivingUtils::ArchiveChild(fFunctionID, archive, "function"))
123*fce4895dSRene Gollent != B_OK
124*fce4895dSRene Gollent || (error = archive.AddString("sourceFile", fSourceFile)) != B_OK
125*fce4895dSRene Gollent || (error = archive.AddInt32("line", fSourceLocation.Line())) != B_OK
126*fce4895dSRene Gollent || (error = archive.AddInt32("column", fSourceLocation.Column()))
127*fce4895dSRene Gollent != B_OK
128*fce4895dSRene Gollent || (error = archive.AddUInt64("relativeAddress", fRelativeAddress))
129*fce4895dSRene Gollent != B_OK
130*fce4895dSRene Gollent || (error = archive.AddBool("enabled", fEnabled)) != B_OK
131*fce4895dSRene Gollent || (error = archive.AddBool("hidden", fHidden)) != B_OK
132*fce4895dSRene Gollent || (error = archive.AddString("condition", fConditionExpression))
133*fce4895dSRene Gollent != B_OK) {
134*fce4895dSRene Gollent return error;
135*fce4895dSRene Gollent }
136*fce4895dSRene Gollent
137*fce4895dSRene Gollent return B_OK;
138*fce4895dSRene Gollent }
139*fce4895dSRene Gollent
140*fce4895dSRene Gollent
141*fce4895dSRene Gollent BreakpointSetting&
operator =(const BreakpointSetting & other)142*fce4895dSRene Gollent BreakpointSetting::operator=(const BreakpointSetting& other)
143*fce4895dSRene Gollent {
144*fce4895dSRene Gollent if (this == &other)
145*fce4895dSRene Gollent return *this;
146*fce4895dSRene Gollent
147*fce4895dSRene Gollent _Unset();
148*fce4895dSRene Gollent
149*fce4895dSRene Gollent fFunctionID = other.fFunctionID;
150*fce4895dSRene Gollent if (fFunctionID != NULL)
151*fce4895dSRene Gollent fFunctionID->AcquireReference();
152*fce4895dSRene Gollent
153*fce4895dSRene Gollent fSourceFile = other.fSourceFile;
154*fce4895dSRene Gollent fSourceLocation = other.fSourceLocation;
155*fce4895dSRene Gollent fRelativeAddress = other.fRelativeAddress;
156*fce4895dSRene Gollent fEnabled = other.fEnabled;
157*fce4895dSRene Gollent fHidden = other.fHidden;
158*fce4895dSRene Gollent fConditionExpression = other.fConditionExpression;
159*fce4895dSRene Gollent
160*fce4895dSRene Gollent return *this;
161*fce4895dSRene Gollent }
162*fce4895dSRene Gollent
163*fce4895dSRene Gollent
164*fce4895dSRene Gollent void
_Unset()165*fce4895dSRene Gollent BreakpointSetting::_Unset()
166*fce4895dSRene Gollent {
167*fce4895dSRene Gollent if (fFunctionID != NULL) {
168*fce4895dSRene Gollent fFunctionID->ReleaseReference();
169*fce4895dSRene Gollent fFunctionID = NULL;
170*fce4895dSRene Gollent }
171*fce4895dSRene Gollent
172*fce4895dSRene Gollent fSourceFile.Truncate(0);
173*fce4895dSRene Gollent fSourceLocation = SourceLocation();
174*fce4895dSRene Gollent fRelativeAddress = 0;
175*fce4895dSRene Gollent fEnabled = false;
176*fce4895dSRene Gollent fConditionExpression.Truncate(0);
177*fce4895dSRene Gollent }
178