vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / settings / BreakpointSetting.cpp
blob6ad3db18f581cf387d0cb2caacf7d4d1ada1a835
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
8 #include "BreakpointSetting.h"
10 #include <Message.h>
12 #include "ArchivingUtils.h"
13 #include "FunctionID.h"
14 #include "LocatableFile.h"
15 #include "UserBreakpoint.h"
18 BreakpointSetting::BreakpointSetting()
20 fFunctionID(NULL),
21 fSourceFile(),
22 fSourceLocation(),
23 fRelativeAddress(0),
24 fEnabled(false),
25 fHidden(false),
26 fConditionExpression()
31 BreakpointSetting::BreakpointSetting(const BreakpointSetting& other)
33 fFunctionID(other.fFunctionID),
34 fSourceFile(other.fSourceFile),
35 fSourceLocation(other.fSourceLocation),
36 fRelativeAddress(other.fRelativeAddress),
37 fEnabled(other.fEnabled),
38 fHidden(other.fHidden),
39 fConditionExpression(other.fConditionExpression)
41 if (fFunctionID != NULL)
42 fFunctionID->AcquireReference();
46 BreakpointSetting::~BreakpointSetting()
48 _Unset();
52 status_t
53 BreakpointSetting::SetTo(const UserBreakpointLocation& location, bool enabled,
54 bool hidden, const BString& conditionExpression)
56 _Unset();
58 fFunctionID = location.GetFunctionID();
59 if (fFunctionID != NULL)
60 fFunctionID->AcquireReference();
62 if (LocatableFile* file = location.SourceFile())
63 file->GetPath(fSourceFile);
65 fSourceLocation = location.GetSourceLocation();
66 fRelativeAddress = location.RelativeAddress();
67 fEnabled = enabled;
68 fHidden = hidden;
69 fConditionExpression = conditionExpression;
71 return B_OK;
75 status_t
76 BreakpointSetting::SetTo(const BMessage& archive)
78 _Unset();
80 fFunctionID = ArchivingUtils::UnarchiveChild<FunctionID>(archive,
81 "function");
82 if (fFunctionID == NULL)
83 return B_BAD_VALUE;
85 archive.FindString("sourceFile", &fSourceFile);
87 int32 line;
88 if (archive.FindInt32("line", &line) != B_OK)
89 line = -1;
91 int32 column;
92 if (archive.FindInt32("column", &column) != B_OK)
93 column = -1;
95 fSourceLocation = SourceLocation(line, column);
97 if (archive.FindUInt64("relativeAddress", &fRelativeAddress) != B_OK)
98 fRelativeAddress = 0;
100 if (archive.FindBool("enabled", &fEnabled) != B_OK)
101 fEnabled = false;
103 if (archive.FindBool("hidden", &fHidden) != B_OK)
104 fHidden = false;
106 if (archive.FindString("condition", &fConditionExpression) != B_OK)
107 fConditionExpression.Truncate(0);
109 return B_OK;
113 status_t
114 BreakpointSetting::WriteTo(BMessage& archive) const
116 if (fFunctionID == NULL)
117 return B_BAD_VALUE;
119 archive.MakeEmpty();
121 status_t error;
122 if ((error = ArchivingUtils::ArchiveChild(fFunctionID, archive, "function"))
123 != B_OK
124 || (error = archive.AddString("sourceFile", fSourceFile)) != B_OK
125 || (error = archive.AddInt32("line", fSourceLocation.Line())) != B_OK
126 || (error = archive.AddInt32("column", fSourceLocation.Column()))
127 != B_OK
128 || (error = archive.AddUInt64("relativeAddress", fRelativeAddress))
129 != B_OK
130 || (error = archive.AddBool("enabled", fEnabled)) != B_OK
131 || (error = archive.AddBool("hidden", fHidden)) != B_OK
132 || (error = archive.AddString("condition", fConditionExpression))
133 != B_OK) {
134 return error;
137 return B_OK;
141 BreakpointSetting&
142 BreakpointSetting::operator=(const BreakpointSetting& other)
144 if (this == &other)
145 return *this;
147 _Unset();
149 fFunctionID = other.fFunctionID;
150 if (fFunctionID != NULL)
151 fFunctionID->AcquireReference();
153 fSourceFile = other.fSourceFile;
154 fSourceLocation = other.fSourceLocation;
155 fRelativeAddress = other.fRelativeAddress;
156 fEnabled = other.fEnabled;
157 fHidden = other.fHidden;
158 fConditionExpression = other.fConditionExpression;
160 return *this;
164 void
165 BreakpointSetting::_Unset()
167 if (fFunctionID != NULL) {
168 fFunctionID->ReleaseReference();
169 fFunctionID = NULL;
172 fSourceFile.Truncate(0);
173 fSourceLocation = SourceLocation();
174 fRelativeAddress = 0;
175 fEnabled = false;
176 fConditionExpression.Truncate(0);