fix: replace notification calls with virtual function
- Switch notification mechanism to virtual function on SerializableTMap - Remove unused includes of database_cb_batcher.h - Restore original database types Add and Remove logic Co-authored-by: Pedro Filipe Llussa Tavares <pedro.llussa.tavares@tecnico.ulisboa.pt>
This commit is contained in:
parent
0a622b83f3
commit
ff73065d61
|
|
@ -18,7 +18,6 @@
|
|||
#include "thread.h"
|
||||
#include "disasm_fast.h"
|
||||
#include "plugin_loader.h"
|
||||
#include "database_cb_batcher.h"
|
||||
#include "_dbgfunctions.h"
|
||||
#include "module.h"
|
||||
#include "comment.h"
|
||||
|
|
|
|||
|
|
@ -49,6 +49,16 @@ protected:
|
|||
{
|
||||
return ModuleRange(value.modhash, Range(value.start, value.end));
|
||||
}
|
||||
|
||||
void notifyAdd(const ARGUMENTSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyArgument(DbOperationType::Add, value.modhash, value.start, value.end, value.instructioncount, value.manual);
|
||||
}
|
||||
|
||||
void notifyRemove(const ARGUMENTSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyArgument(DbOperationType::Remove, value.modhash, value.start);
|
||||
}
|
||||
};
|
||||
|
||||
static Arguments arguments;
|
||||
|
|
@ -76,12 +86,7 @@ bool ArgumentAdd(duint Start, duint End, bool Manual, duint InstructionCount)
|
|||
argument.manual = Manual;
|
||||
argument.instructioncount = InstructionCount;
|
||||
|
||||
if(arguments.Add(argument))
|
||||
{
|
||||
DbCbNotifyArgument(DbOperationType::Add, argument.modhash, argument.start, argument.end, InstructionCount, Manual);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return arguments.Add(argument);
|
||||
}
|
||||
|
||||
bool ArgumentGet(duint Address, duint* Start, duint* End, duint* InstrCount)
|
||||
|
|
@ -109,18 +114,7 @@ bool ArgumentOverlaps(duint Start, duint End)
|
|||
|
||||
bool ArgumentDelete(duint Address)
|
||||
{
|
||||
ARGUMENTSINFO info;
|
||||
if(arguments.Get(Arguments::VaKey(Address, Address), info))
|
||||
{
|
||||
if(arguments.Delete(Arguments::VaKey(Address, Address)))
|
||||
{
|
||||
DbCbNotifyArgument(DbOperationType::Remove, info.modhash, info.start);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return arguments.Delete(Arguments::VaKey(Address, Address));
|
||||
}
|
||||
|
||||
void ArgumentDelRange(duint Start, duint End, bool DeleteManual)
|
||||
|
|
@ -150,9 +144,6 @@ void ArgumentDelRange(duint Start, duint End, bool DeleteManual)
|
|||
if(!DeleteManual && value.manual)
|
||||
return false;
|
||||
return value.end >= Start && value.start <= End;
|
||||
}, [](const ARGUMENTSINFO & argument)
|
||||
{
|
||||
DbCbNotifyArgument(DbOperationType::Remove, argument.modhash, argument.start);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -170,10 +161,7 @@ void ArgumentCacheLoad(JSON Root)
|
|||
void ArgumentClear()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
arguments.Clear([](const ARGUMENTSINFO & argument)
|
||||
{
|
||||
DbCbNotifyArgument(DbOperationType::Remove, argument.modhash, argument.start);
|
||||
});
|
||||
arguments.Clear();
|
||||
}
|
||||
|
||||
void ArgumentGetList(std::vector<ARGUMENTSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,17 @@ struct Bookmarks : AddrInfoHashMap<LockBookmarks, BOOKMARKSINFO, BookmarkSeriali
|
|||
{
|
||||
return "bookmarks";
|
||||
}
|
||||
|
||||
protected:
|
||||
void notifyAdd(const BOOKMARKSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyBookmark(DbOperationType::Add, value.modhash, value.addr, value.manual);
|
||||
}
|
||||
|
||||
void notifyRemove(const BOOKMARKSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyBookmark(DbOperationType::Remove, value.modhash, value.addr);
|
||||
}
|
||||
};
|
||||
|
||||
static Bookmarks bookmarks;
|
||||
|
|
@ -23,12 +34,7 @@ bool BookmarkSet(duint Address, bool Manual)
|
|||
auto key = Bookmarks::VaKey(Address);
|
||||
if(bookmarks.Contains(key))
|
||||
return bookmarks.Delete(key);
|
||||
if(bookmarks.Add(bookmark))
|
||||
{
|
||||
DbCbNotifyBookmark(DbOperationType::Add, bookmark.modhash, bookmark.addr, Manual);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return bookmarks.Add(bookmark);
|
||||
}
|
||||
|
||||
bool BookmarkGet(duint Address)
|
||||
|
|
@ -38,27 +44,13 @@ bool BookmarkGet(duint Address)
|
|||
|
||||
bool BookmarkDelete(duint Address)
|
||||
{
|
||||
BOOKMARKSINFO info;
|
||||
if(bookmarks.Get(Bookmarks::VaKey(Address),info))
|
||||
{
|
||||
if(bookmarks.Delete(Bookmarks::VaKey(Address)))
|
||||
{
|
||||
DbCbNotifyBookmark(DbOperationType::Remove, info.modhash, info.addr);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return bookmarks.Delete(Bookmarks::VaKey(Address));
|
||||
}
|
||||
|
||||
void BookmarkDelRange(duint Start, duint End, bool Manual)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
bookmarks.DeleteRange(Start, End, Manual, [](const BOOKMARKSINFO & bookmark)
|
||||
{
|
||||
DbCbNotifyBookmark(DbOperationType::Remove, bookmark.modhash, bookmark.addr);
|
||||
});
|
||||
bookmarks.DeleteRange(Start, End, Manual);
|
||||
}
|
||||
|
||||
void BookmarkCacheSave(JSON Root)
|
||||
|
|
@ -80,10 +72,7 @@ bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size)
|
|||
void BookmarkClear()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
bookmarks.Clear([](const BOOKMARKSINFO & bookmark)
|
||||
{
|
||||
DbCbNotifyBookmark(DbOperationType::Remove, bookmark.modhash, bookmark.addr);
|
||||
});
|
||||
bookmarks.Clear();
|
||||
}
|
||||
|
||||
void BookmarkGetList(std::vector<BOOKMARKSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "cmd-user-database.h"
|
||||
#include "database_cb_batcher.h"
|
||||
#include "database.h"
|
||||
#include "console.h"
|
||||
#include "comment.h"
|
||||
|
|
@ -566,4 +565,4 @@ bool cbInstrLoopClear(int argc, char* argv[])
|
|||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All loops deleted!"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,17 @@ struct Comments : AddrInfoHashMap<LockComments, COMMENTSINFO, CommentSerializer>
|
|||
{
|
||||
return "comments";
|
||||
}
|
||||
|
||||
protected:
|
||||
void notifyAdd(const COMMENTSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyComment(DbOperationType::Add, value.modhash, value.addr, value.text.c_str(), value.manual);
|
||||
}
|
||||
|
||||
void notifyRemove(const COMMENTSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyComment(DbOperationType::Remove, value.modhash, value.addr);
|
||||
}
|
||||
};
|
||||
|
||||
static Comments comments;
|
||||
|
|
@ -43,12 +54,7 @@ bool CommentSet(duint Address, const char* Text, bool Manual)
|
|||
if(!comments.PrepareValue(comment, Address, Manual))
|
||||
return false;
|
||||
comment.text = Text;
|
||||
if(comments.Add(comment))
|
||||
{
|
||||
DbCbNotifyComment(DbOperationType::Add, comment.modhash, comment.addr, Text, Manual);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return comments.Add(comment);
|
||||
}
|
||||
|
||||
bool CommentGet(duint Address, char* Text)
|
||||
|
|
@ -65,27 +71,13 @@ bool CommentGet(duint Address, char* Text)
|
|||
|
||||
bool CommentDelete(duint Address)
|
||||
{
|
||||
COMMENTSINFO info;
|
||||
if(comments.Get(Comments::VaKey(Address),info))
|
||||
{
|
||||
if(comments.Delete(Comments::VaKey(Address)))
|
||||
{
|
||||
DbCbNotifyComment(DbOperationType::Remove, info.modhash, info.addr);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return comments.Delete(Comments::VaKey(Address));
|
||||
}
|
||||
|
||||
void CommentDelRange(duint Start, duint End, bool Manual)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
comments.DeleteRange(Start, End, Manual, [](const COMMENTSINFO & comment)
|
||||
{
|
||||
DbCbNotifyComment(DbOperationType::Remove, comment.modhash, comment.addr);
|
||||
});
|
||||
comments.DeleteRange(Start, End, Manual);
|
||||
}
|
||||
|
||||
void CommentCacheSave(JSON Root)
|
||||
|
|
@ -107,10 +99,7 @@ bool CommentEnum(COMMENTSINFO* List, size_t* Size)
|
|||
void CommentClear()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
comments.Clear([](const COMMENTSINFO & comment)
|
||||
{
|
||||
DbCbNotifyComment(DbOperationType::Remove, comment.modhash, comment.addr);
|
||||
});
|
||||
comments.Clear();
|
||||
}
|
||||
|
||||
void CommentGetList(std::vector<COMMENTSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,16 @@ protected:
|
|||
{
|
||||
return ModuleRange(value.modhash, Range(value.start, value.end));
|
||||
}
|
||||
|
||||
void notifyAdd(const FUNCTIONSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyFunction(DbOperationType::Add, value.modhash, value.start, value.end, value.instructioncount, value.parent, value.manual);
|
||||
}
|
||||
|
||||
void notifyRemove(const FUNCTIONSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyFunction(DbOperationType::Remove, value.modhash, value.start);
|
||||
}
|
||||
};
|
||||
|
||||
static Functions functions;
|
||||
|
|
@ -84,12 +94,7 @@ bool FunctionAdd(duint Start, duint End, bool Manual, duint InstructionCount, du
|
|||
function.parent = Parent ? Parent : Start;
|
||||
function.parent -= moduleBase;
|
||||
|
||||
if(functions.Add(function))
|
||||
{
|
||||
DbCbNotifyFunction(DbOperationType::Add, function.modhash, function.start, function.end, InstructionCount, function.parent, Manual);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return functions.Add(function);
|
||||
}
|
||||
|
||||
bool FunctionGet(duint Address, duint* Start, duint* End, duint* InstrCount, duint* Parent)
|
||||
|
|
@ -119,18 +124,7 @@ bool FunctionOverlaps(duint Start, duint End)
|
|||
|
||||
bool FunctionDelete(duint Address)
|
||||
{
|
||||
FUNCTIONSINFO info;
|
||||
if(functions.Get(Functions::VaKey(Address, Address),info))
|
||||
{
|
||||
if(functions.Delete(Functions::VaKey(Address, Address)))
|
||||
{
|
||||
DbCbNotifyFunction(DbOperationType::Remove, info.modhash, info.start);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return functions.Delete(Functions::VaKey(Address, Address));
|
||||
}
|
||||
|
||||
void FunctionDelRange(duint Start, duint End, bool DeleteManual)
|
||||
|
|
@ -160,9 +154,6 @@ void FunctionDelRange(duint Start, duint End, bool DeleteManual)
|
|||
if(!DeleteManual && value.manual)
|
||||
return false;
|
||||
return value.end >= Start && value.start <= End;
|
||||
}, [](const FUNCTIONSINFO & function)
|
||||
{
|
||||
DbCbNotifyFunction(DbOperationType::Remove, function.modhash, function.start);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -186,10 +177,7 @@ bool FunctionEnum(FUNCTIONSINFO* List, size_t* Size)
|
|||
void FunctionClear()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
functions.Clear([](const FUNCTIONSINFO & function)
|
||||
{
|
||||
DbCbNotifyFunction(DbOperationType::Remove, function.modhash, function.start);
|
||||
});
|
||||
functions.Clear();
|
||||
}
|
||||
|
||||
void FunctionGetList(std::vector<FUNCTIONSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,17 @@ struct Labels : AddrInfoHashMap<LockLabels, LABELSINFO, LabelSerializer>
|
|||
{
|
||||
return "labels";
|
||||
}
|
||||
|
||||
protected:
|
||||
void notifyAdd(const LABELSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyLabel(DbOperationType::Add, value.modhash, value.addr, value.text.c_str(), value.manual);
|
||||
}
|
||||
|
||||
void notifyRemove(const LABELSINFO & value) const override
|
||||
{
|
||||
DbCbNotifyLabel(DbOperationType::Remove, value.modhash, value.addr);
|
||||
}
|
||||
};
|
||||
|
||||
static Labels labels;
|
||||
|
|
@ -49,12 +60,7 @@ bool LabelSet(duint Address, const char* Text, bool Manual, bool Temp)
|
|||
if(!labels.PrepareValue(label, Address, Manual))
|
||||
return false;
|
||||
label.text = Text;
|
||||
if(labels.Add(label))
|
||||
{
|
||||
DbCbNotifyLabel(DbOperationType::Add, label.modhash, label.addr, Text, Manual);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return labels.Add(label);
|
||||
}
|
||||
|
||||
bool LabelFromString(const char* Text, duint* Address)
|
||||
|
|
@ -107,29 +113,13 @@ bool LabelIsTemporary(duint Address)
|
|||
|
||||
bool LabelDelete(duint Address)
|
||||
{
|
||||
LABELSINFO info;
|
||||
if(labels.Get(Labels::VaKey(Address),info))
|
||||
{
|
||||
if(labels.Delete(Labels::VaKey(Address)))
|
||||
{
|
||||
DbCbNotifyLabel(DbOperationType::Remove, info.modhash, info.addr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return tempLabels.erase(Address) > 0;
|
||||
return labels.Delete(Labels::VaKey(Address)) || tempLabels.erase(Address) > 0;
|
||||
}
|
||||
|
||||
void LabelDelRange(duint Start, duint End, bool Manual)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
labels.DeleteRange(Start, End, Manual, [](const LABELSINFO & label)
|
||||
{
|
||||
DbCbNotifyLabel(DbOperationType::Remove, label.modhash, label.addr);
|
||||
});
|
||||
labels.DeleteRange(Start, End, Manual);
|
||||
if(Start == 0 && End == ~0)
|
||||
{
|
||||
tempLabels.clear();
|
||||
|
|
@ -160,10 +150,7 @@ void LabelCacheLoad(JSON Root)
|
|||
void LabelClear()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
labels.Clear([](const LABELSINFO & label)
|
||||
{
|
||||
DbCbNotifyLabel(DbOperationType::Remove, label.modhash, label.addr);
|
||||
});
|
||||
labels.Clear();
|
||||
tempLabels.clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,8 +112,14 @@ public:
|
|||
|
||||
bool Add(const TValue & value)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
return addNoLock(value);
|
||||
bool added;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
added = addNoLock(value);
|
||||
}
|
||||
if(added)
|
||||
notifyAdd(value);
|
||||
return added;
|
||||
}
|
||||
|
||||
bool Get(const TKey & key, TValue & value) const
|
||||
|
|
@ -134,20 +140,31 @@ public:
|
|||
|
||||
bool Delete(const TKey & key)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
return mMap.erase(key) > 0;
|
||||
TValue value;
|
||||
bool erased;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
auto found = mMap.find(key);
|
||||
erased = found != mMap.end();
|
||||
if(erased)
|
||||
{
|
||||
value = std::move(found->second);
|
||||
mMap.erase(found);
|
||||
}
|
||||
}
|
||||
if(erased)
|
||||
notifyRemove(value);
|
||||
return erased;
|
||||
}
|
||||
|
||||
void DeleteWhere(TValuePred predicate, std::function<void(const TValue&)> onEvict = nullptr)
|
||||
void DeleteWhere(TValuePred predicate)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
for(auto itr = mMap.begin(); itr != mMap.end();)
|
||||
{
|
||||
if(predicate(itr->second))
|
||||
{
|
||||
if(onEvict)
|
||||
onEvict(itr->second);
|
||||
|
||||
notifyRemove(itr->second);
|
||||
itr = mMap.erase(itr);
|
||||
}
|
||||
else
|
||||
|
|
@ -165,20 +182,15 @@ public:
|
|||
return getWhere(predicate, nullptr);
|
||||
}
|
||||
|
||||
void Clear(std::function<void(const TValue&)> onEvict = nullptr)
|
||||
void Clear()
|
||||
{
|
||||
TMap empty;
|
||||
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
std::swap(mMap, empty);
|
||||
}
|
||||
|
||||
if(onEvict)
|
||||
{
|
||||
for(const auto& kv : empty)
|
||||
onEvict(kv.second);
|
||||
}
|
||||
for(const auto & kv : empty)
|
||||
notifyRemove(kv.second);
|
||||
}
|
||||
|
||||
void CacheSave(JSON root) const
|
||||
|
|
@ -266,6 +278,8 @@ public:
|
|||
protected:
|
||||
virtual const char* jsonKey() const = 0;
|
||||
virtual TKey makeKey(const TValue & value) const = 0;
|
||||
virtual void notifyAdd(const TValue &) const {}
|
||||
virtual void notifyRemove(const TValue &) const {}
|
||||
|
||||
private:
|
||||
TMap mMap;
|
||||
|
|
@ -315,13 +329,13 @@ struct SerializableModuleHashMap : SerializableUnorderedMap<TLock, duint, TValue
|
|||
return ModHashFromAddr(addr);
|
||||
}
|
||||
|
||||
void DeleteRangeWhere(duint start, duint end, std::function<bool(duint, duint, const TValue &)> inRange, std::function<void(const TValue&)> onEvict = nullptr)
|
||||
void DeleteRangeWhere(duint start, duint end, std::function<bool(duint, duint, const TValue &)> inRange)
|
||||
{
|
||||
// Are all comments going to be deleted?
|
||||
// 0x00000000 - 0xFFFFFFFF
|
||||
if(start == 0 && end == ~0)
|
||||
{
|
||||
this->Clear(onEvict);
|
||||
this->Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -338,7 +352,7 @@ struct SerializableModuleHashMap : SerializableUnorderedMap<TLock, duint, TValue
|
|||
this->DeleteWhere([start, end, inRange](const TValue & value)
|
||||
{
|
||||
return inRange(start, end, value);
|
||||
}, onEvict);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -402,14 +416,14 @@ struct AddrInfoHashMap : SerializableModuleHashMap<TLock, TValue, TSerializer>
|
|||
return true;
|
||||
}
|
||||
|
||||
void DeleteRange(duint start, duint end, bool manual, std::function<void(const TValue&)> onEvict = nullptr)
|
||||
void DeleteRange(duint start, duint end, bool manual)
|
||||
{
|
||||
this->DeleteRangeWhere(start, end, [manual](duint start, duint end, const TValue & value)
|
||||
{
|
||||
if(manual ? !value.manual : value.manual) //ignore non-matching entries
|
||||
return false;
|
||||
return value.addr >= start && value.addr < end;
|
||||
}, onEvict);
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Reference in New Issue