12bf55b39SIngo Weinhold/*
22bf55b39SIngo Weinhold * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
365a10b50SRene Gollent * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
42bf55b39SIngo Weinhold * Distributed under the terms of the MIT License.
52bf55b39SIngo Weinhold */
62bf55b39SIngo Weinhold
72bf55b39SIngo Weinhold
82bf55b39SIngo Weinhold#include "BreakpointSetting.h"
92bf55b39SIngo Weinhold
102bf55b39SIngo Weinhold#include <Message.h>
112bf55b39SIngo Weinhold
122bf55b39SIngo Weinhold#include "ArchivingUtils.h"
132bf55b39SIngo Weinhold#include "FunctionID.h"
142bf55b39SIngo Weinhold#include "LocatableFile.h"
152bf55b39SIngo Weinhold#include "UserBreakpoint.h"
162bf55b39SIngo Weinhold
172bf55b39SIngo Weinhold
182bf55b39SIngo WeinholdBreakpointSetting::BreakpointSetting()
192bf55b39SIngo Weinhold	:
202bf55b39SIngo Weinhold	fFunctionID(NULL),
212bf55b39SIngo Weinhold	fSourceFile(),
222bf55b39SIngo Weinhold	fSourceLocation(),
232bf55b39SIngo Weinhold	fRelativeAddress(0),
24b9461dc8SRene Gollent	fEnabled(false),
2565a10b50SRene Gollent	fHidden(false),
2665a10b50SRene Gollent	fConditionExpression()
272bf55b39SIngo Weinhold{
282bf55b39SIngo Weinhold}
292bf55b39SIngo Weinhold
302bf55b39SIngo Weinhold
312bf55b39SIngo WeinholdBreakpointSetting::BreakpointSetting(const BreakpointSetting& other)
322bf55b39SIngo Weinhold	:
332bf55b39SIngo Weinhold	fFunctionID(other.fFunctionID),
342bf55b39SIngo Weinhold	fSourceFile(other.fSourceFile),
352bf55b39SIngo Weinhold	fSourceLocation(other.fSourceLocation),
362bf55b39SIngo Weinhold	fRelativeAddress(other.fRelativeAddress),
37b9461dc8SRene Gollent	fEnabled(other.fEnabled),
3865a10b50SRene Gollent	fHidden(other.fHidden),
3965a10b50SRene Gollent	fConditionExpression(other.fConditionExpression)
402bf55b39SIngo Weinhold{
412bf55b39SIngo Weinhold	if (fFunctionID != NULL)
422bf55b39SIngo Weinhold		fFunctionID->AcquireReference();
432bf55b39SIngo Weinhold}
442bf55b39SIngo Weinhold
452bf55b39SIngo Weinhold
462bf55b39SIngo WeinholdBreakpointSetting::~BreakpointSetting()
472bf55b39SIngo Weinhold{
482bf55b39SIngo Weinhold	_Unset();
492bf55b39SIngo Weinhold}
502bf55b39SIngo Weinhold
512bf55b39SIngo Weinhold
522bf55b39SIngo Weinholdstatus_t
53b9461dc8SRene GollentBreakpointSetting::SetTo(const UserBreakpointLocation& location, bool enabled,
5465a10b50SRene Gollent	bool hidden, const BString& conditionExpression)
552bf55b39SIngo Weinhold{
562bf55b39SIngo Weinhold	_Unset();
572bf55b39SIngo Weinhold
582bf55b39SIngo Weinhold	fFunctionID = location.GetFunctionID();
592bf55b39SIngo Weinhold	if (fFunctionID != NULL)
602bf55b39SIngo Weinhold		fFunctionID->AcquireReference();
612bf55b39SIngo Weinhold
622bf55b39SIngo Weinhold	if (LocatableFile* file = location.SourceFile())
632bf55b39SIngo Weinhold		file->GetPath(fSourceFile);
642bf55b39SIngo Weinhold
652bf55b39SIngo Weinhold	fSourceLocation = location.GetSourceLocation();
662bf55b39SIngo Weinhold	fRelativeAddress = location.RelativeAddress();
672bf55b39SIngo Weinhold	fEnabled = enabled;
68b9461dc8SRene Gollent	fHidden = hidden;
6965a10b50SRene Gollent	fConditionExpression = conditionExpression;
702bf55b39SIngo Weinhold
712bf55b39SIngo Weinhold	return B_OK;
722bf55b39SIngo Weinhold}
732bf55b39SIngo Weinhold
742bf55b39SIngo Weinhold
752bf55b39SIngo Weinholdstatus_t
762bf55b39SIngo WeinholdBreakpointSetting::SetTo(const BMessage& archive)
772bf55b39SIngo Weinhold{
782bf55b39SIngo Weinhold	_Unset();
792bf55b39SIngo Weinhold
802bf55b39SIngo Weinhold	fFunctionID = ArchivingUtils::UnarchiveChild<FunctionID>(archive,
812bf55b39SIngo Weinhold		"function");
822bf55b39SIngo Weinhold	if (fFunctionID == NULL)
832bf55b39SIngo Weinhold		return B_BAD_VALUE;
842bf55b39SIngo Weinhold
852bf55b39SIngo Weinhold	archive.FindString("sourceFile", &fSourceFile);
862bf55b39SIngo Weinhold
872bf55b39SIngo Weinhold	int32 line;
882bf55b39SIngo Weinhold	if (archive.FindInt32("line", &line) != B_OK)
892bf55b39SIngo Weinhold		line = -1;
902bf55b39SIngo Weinhold
912bf55b39SIngo Weinhold	int32 column;
922bf55b39SIngo Weinhold	if (archive.FindInt32("column", &column) != B_OK)
932bf55b39SIngo Weinhold		column = -1;
942bf55b39SIngo Weinhold
952bf55b39SIngo Weinhold	fSourceLocation = SourceLocation(line, column);
962bf55b39SIngo Weinhold
972bf55b39SIngo Weinhold	if (archive.FindUInt64("relativeAddress", &fRelativeAddress) != B_OK)
982bf55b39SIngo Weinhold		fRelativeAddress = 0;
992bf55b39SIngo Weinhold
1002bf55b39SIngo Weinhold	if (archive.FindBool("enabled", &fEnabled) != B_OK)
1012bf55b39SIngo Weinhold		fEnabled = false;
1022bf55b39SIngo Weinhold
103b9461dc8SRene Gollent	if (archive.FindBool("hidden", &fHidden) != B_OK)
104b9461dc8SRene Gollent		fHidden = false;
105b9461dc8SRene Gollent
10665a10b50SRene Gollent	if (archive.FindString("condition", &fConditionExpression) != B_OK)
10765a10b50SRene Gollent		fConditionExpression.Truncate(0);
10865a10b50SRene Gollent
1092bf55b39SIngo Weinhold	return B_OK;
1102bf55b39SIngo Weinhold}
1112bf55b39SIngo Weinhold
1122bf55b39SIngo Weinhold
1132bf55b39SIngo Weinholdstatus_t
1142bf55b39SIngo WeinholdBreakpointSetting::WriteTo(BMessage& archive) const
1152bf55b39SIngo Weinhold{
1162bf55b39SIngo Weinhold	if (fFunctionID == NULL)
1172bf55b39SIngo Weinhold		return B_BAD_VALUE;
1182bf55b39SIngo Weinhold
1194c43e539SRene Gollent	archive.MakeEmpty();
1204c43e539SRene Gollent
1212bf55b39SIngo Weinhold	status_t error;
1222bf55b39SIngo Weinhold	if ((error = ArchivingUtils::ArchiveChild(fFunctionID, archive, "function"))
1232bf55b39SIngo Weinhold			!= B_OK
1242bf55b39SIngo Weinhold		|| (error = archive.AddString("sourceFile", fSourceFile)) != B_OK
1252bf55b39SIngo Weinhold		|| (error = archive.AddInt32("line", fSourceLocation.Line())) != B_OK
1262bf55b39SIngo Weinhold		|| (error = archive.AddInt32("column", fSourceLocation.Column()))
1272bf55b39SIngo Weinhold			!= B_OK
1282bf55b39SIngo Weinhold		|| (error = archive.AddUInt64("relativeAddress", fRelativeAddress))
1292bf55b39SIngo Weinhold			!= B_OK
130b9461dc8SRene Gollent		|| (error = archive.AddBool("enabled", fEnabled)) != B_OK
13165a10b50SRene Gollent		|| (error = archive.AddBool("hidden", fHidden)) != B_OK
13265a10b50SRene Gollent		|| (error = archive.AddString("condition", fConditionExpression))
13365a10b50SRene Gollent			!= B_OK) {
1342bf55b39SIngo Weinhold		return error;
1352bf55b39SIngo Weinhold	}
1362bf55b39SIngo Weinhold
1372bf55b39SIngo Weinhold	return B_OK;
1382bf55b39SIngo Weinhold}
1392bf55b39SIngo Weinhold
1402bf55b39SIngo Weinhold
1412bf55b39SIngo WeinholdBreakpointSetting&
1422bf55b39SIngo WeinholdBreakpointSetting::operator=(const BreakpointSetting& other)
1432bf55b39SIngo Weinhold{
1442bf55b39SIngo Weinhold	if (this == &other)
1452bf55b39SIngo Weinhold		return *this;
1462bf55b39SIngo Weinhold
1472bf55b39SIngo Weinhold	_Unset();
1482bf55b39SIngo Weinhold
1492bf55b39SIngo Weinhold	fFunctionID = other.fFunctionID;
1502bf55b39SIngo Weinhold	if (fFunctionID != NULL)
1512bf55b39SIngo Weinhold		fFunctionID->AcquireReference();
1522bf55b39SIngo Weinhold
1532bf55b39SIngo Weinhold	fSourceFile = other.fSourceFile;
1542bf55b39SIngo Weinhold	fSourceLocation = other.fSourceLocation;
1552bf55b39SIngo Weinhold	fRelativeAddress = other.fRelativeAddress;
1562bf55b39SIngo Weinhold	fEnabled = other.fEnabled;
157b9461dc8SRene Gollent	fHidden = other.fHidden;
15865a10b50SRene Gollent	fConditionExpression = other.fConditionExpression;
1592bf55b39SIngo Weinhold
1602bf55b39SIngo Weinhold	return *this;
1612bf55b39SIngo Weinhold}
1622bf55b39SIngo Weinhold
1632bf55b39SIngo Weinhold
1642bf55b39SIngo Weinholdvoid
1652bf55b39SIngo WeinholdBreakpointSetting::_Unset()
1662bf55b39SIngo Weinhold{
1672bf55b39SIngo Weinhold	if (fFunctionID != NULL) {
1682bf55b39SIngo Weinhold		fFunctionID->ReleaseReference();
1692bf55b39SIngo Weinhold		fFunctionID = NULL;
1702bf55b39SIngo Weinhold	}
1712bf55b39SIngo Weinhold
1722bf55b39SIngo Weinhold	fSourceFile.Truncate(0);
1732bf55b39SIngo Weinhold	fSourceLocation = SourceLocation();
1742bf55b39SIngo Weinhold	fRelativeAddress = 0;
1752bf55b39SIngo Weinhold	fEnabled = false;
17665a10b50SRene Gollent	fConditionExpression.Truncate(0);
1772bf55b39SIngo Weinhold}
178