Merge pull request #3871 from rafaelrfreitas/feature-2259
feat #2259: add CB_DBOPERATION callbacks for plugin database synchronization
This commit is contained in:
commit
cd7aad9b61
|
|
@ -172,6 +172,7 @@ set(dbg_SOURCES
|
|||
"src/dbg/WinInet-Downloader/downslib.cpp"
|
||||
"src/dbg/WinInet-Downloader/downslib.h"
|
||||
"src/dbg/XEDParse/XEDParse.h"
|
||||
"src/dbg/_apichecker.c"
|
||||
"src/dbg/_dbgfunctions.cpp"
|
||||
"src/dbg/_dbgfunctions.h"
|
||||
"src/dbg/_exports.cpp"
|
||||
|
|
@ -304,6 +305,8 @@ set(dbg_SOURCES
|
|||
"src/dbg/console.h"
|
||||
"src/dbg/database.cpp"
|
||||
"src/dbg/database.h"
|
||||
"src/dbg/database_cb_batcher.cpp"
|
||||
"src/dbg/database_cb_batcher.h"
|
||||
"src/dbg/datainst_helper.cpp"
|
||||
"src/dbg/datainst_helper.h"
|
||||
"src/dbg/dbghelp_safe.cpp"
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ clang-any.compile-options = ["-Wno-self-assign-field"]
|
|||
type = "shared"
|
||||
sources = [
|
||||
"src/dbg/*.cpp",
|
||||
"src/dbg/*.c",
|
||||
"src/dbg/*.h",
|
||||
"src/dbg/analysis/*.cpp",
|
||||
"src/dbg/analysis/*.h",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <Windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
|
|
|
|||
|
|
@ -576,4 +576,12 @@ void dbgfunctionsinit()
|
|||
memcpy(result, escaped.c_str(), escaped.size() + 1);
|
||||
return true;
|
||||
};
|
||||
_dbgfunctions.ModNameFromHash = [](duint hash, char* modname)
|
||||
{
|
||||
auto name = ModNameFromHash(hash);
|
||||
if(name.empty())
|
||||
return false;
|
||||
strncpy_s(modname, MAX_MODULE_SIZE, name.c_str(), _TRUNCATE);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,6 +285,7 @@ typedef struct DBGFUNCTIONS_
|
|||
bool (*BpSetFieldText)(const BP_REF* ref, BP_FIELD field, const char* value);
|
||||
// Escapes argument contents for insertion between double quotes in a debugger command.
|
||||
bool (*CommandEscape)(const char* argument, char* result, size_t resultSize);
|
||||
bool (*ModNameFromHash)(duint hash, char* modname);
|
||||
} DBGFUNCTIONS;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -28,6 +28,24 @@
|
|||
#define PLUG_DB_LOADSAVE_DATA 1
|
||||
#define PLUG_DB_LOADSAVE_ALL 2
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define ENUM_U8_BEGIN(name) typedef enum : uint8_t
|
||||
#define ENUM_U8_END(name) name
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||
#define ENUM_U8_BEGIN(name) typedef enum : uint8_t
|
||||
#define ENUM_U8_END(name) name
|
||||
#elif defined(_MSC_VER)
|
||||
// MSVC does not support fixed underlying enum types in C mode. Keep the
|
||||
// constants in an anonymous enum and use an explicitly sized typedef.
|
||||
#define ENUM_U8_BEGIN(name) typedef uint8_t name; enum
|
||||
#define ENUM_U8_END(name)
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#define ENUM_U8_BEGIN(name) typedef enum __attribute__((packed))
|
||||
#define ENUM_U8_END(name) name
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
//structures
|
||||
typedef struct
|
||||
{
|
||||
|
|
@ -246,6 +264,67 @@ typedef struct
|
|||
void* reserved;
|
||||
} PLUG_CB_STOPTRACE;
|
||||
|
||||
ENUM_U8_BEGIN(DbItemType)
|
||||
{
|
||||
DbItemTypeBookmark,
|
||||
DbItemTypeLabel,
|
||||
DbItemTypeComment,
|
||||
DbItemTypeFunction,
|
||||
DbItemTypeLoop,
|
||||
DbItemTypeArgument,
|
||||
}
|
||||
ENUM_U8_END(DbItemType);
|
||||
|
||||
ENUM_U8_BEGIN(DbOperationType)
|
||||
{
|
||||
DbOperationTypeAdd,
|
||||
DbOperationTypeRemove,
|
||||
}
|
||||
ENUM_U8_END(DbOperationType);
|
||||
|
||||
#undef ENUM_U8_BEGIN
|
||||
#undef ENUM_U8_END
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DbOperationType opType;
|
||||
DbItemType itemType;
|
||||
bool manual;
|
||||
duint modhash; // Use DbgFunctions()->ModNameFromHash
|
||||
duint address; // RVA if modhash != 0 else VA
|
||||
// WARNING: DO NOT ACCESS DATA BEYOND ITEM TYPE
|
||||
union
|
||||
{
|
||||
// Bookmark (no fields)
|
||||
|
||||
// Label, Comment
|
||||
struct
|
||||
{
|
||||
const char* text;
|
||||
};
|
||||
|
||||
// Function, Loop, Argument
|
||||
struct
|
||||
{
|
||||
duint end;
|
||||
duint parent;
|
||||
duint icount;
|
||||
int32_t depth;
|
||||
};
|
||||
};
|
||||
} DbOperation;
|
||||
|
||||
#ifdef __cplusplus
|
||||
static_assert(offsetof(DbOperation, modhash) == sizeof(void*), "");
|
||||
#endif // __cplusplus
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const DbOperation** operations;
|
||||
size_t count;
|
||||
uint32_t batchId; // >0 if batched, 0 otherwise
|
||||
} PLUG_CB_DBOPERATION;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ValueTypeNumber,
|
||||
|
|
@ -307,6 +386,8 @@ typedef enum
|
|||
CB_STOPPINGDEBUG, //PLUG_CB_STOPDEBUG
|
||||
CB_STARTTRACE, //PLUG_CB_STARTTRACE
|
||||
CB_STOPTRACE, //PLUG_CB_STOPTRACE
|
||||
CB_DBOPERATION, //PLUG_CB_DBOPERATION
|
||||
CB_DBLOADOPERATION, //PLUG_CB_DBOPERATION
|
||||
CB_LAST
|
||||
} CBTYPE;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ SCRIPT_EXPORT void Script::Argument::DeleteRange(duint start, duint end, bool de
|
|||
|
||||
SCRIPT_EXPORT void Script::Argument::Clear()
|
||||
{
|
||||
ArgumentClear();
|
||||
ArgumentClear(false);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Argument::GetList(ListOf(ArgumentInfo) list)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ SCRIPT_EXPORT void Script::Bookmark::DeleteRange(duint start, duint end)
|
|||
|
||||
SCRIPT_EXPORT void Script::Bookmark::Clear()
|
||||
{
|
||||
BookmarkClear();
|
||||
BookmarkClear(false);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Bookmark::GetList(ListOf(BookmarkInfo) list)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ SCRIPT_EXPORT void Script::Comment::DeleteRange(duint start, duint end)
|
|||
|
||||
SCRIPT_EXPORT void Script::Comment::Clear()
|
||||
{
|
||||
CommentClear();
|
||||
CommentClear(false);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Comment::GetList(ListOf(CommentInfo) list)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ SCRIPT_EXPORT void Script::Function::DeleteRange(duint start, duint end)
|
|||
|
||||
SCRIPT_EXPORT void Script::Function::Clear()
|
||||
{
|
||||
FunctionClear();
|
||||
FunctionClear(false);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Function::GetList(ListOf(FunctionInfo) list)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ SCRIPT_EXPORT void Script::Label::DeleteRange(duint start, duint end)
|
|||
|
||||
SCRIPT_EXPORT void Script::Label::Clear()
|
||||
{
|
||||
LabelClear();
|
||||
LabelClear(false);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Label::GetList(ListOf(LabelInfo) list)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "debugger.h"
|
||||
#include "module.h"
|
||||
#include "function.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
FunctionPass::FunctionPass(duint VirtualStart, duint VirtualEnd, BBlockArray & MainBlocks)
|
||||
: AnalysisPass(VirtualStart, VirtualEnd, MainBlocks)
|
||||
|
|
@ -59,6 +60,7 @@ bool FunctionPass::Analyse()
|
|||
|
||||
dprintf(QT_TRANSLATE_NOOP("DBG", "%u functions\n"), DWORD(funcs.size()));
|
||||
|
||||
DbCallbackBatcher batcher;
|
||||
FunctionDelRange(m_VirtualStart, m_VirtualEnd - 1, false);
|
||||
for(auto & func : funcs)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "function.h"
|
||||
#include "xrefs.h"
|
||||
#include "encodemap.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
AdvancedAnalysis::AdvancedAnalysis(duint base, duint size, bool dump)
|
||||
: Analysis(base, size),
|
||||
|
|
@ -32,6 +33,8 @@ void AdvancedAnalysis::Analyse()
|
|||
|
||||
void AdvancedAnalysis::SetMarkers()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
if(mDump)
|
||||
for(const auto & function : mFunctions)
|
||||
FileHelper::WriteAllText(StringUtils::sprintf("cfgraph_%p.dot", function.entryPoint), function.ToDot());
|
||||
|
|
@ -51,7 +54,7 @@ void AdvancedAnalysis::SetMarkers()
|
|||
}
|
||||
}
|
||||
|
||||
FunctionClear();
|
||||
FunctionClear(false);
|
||||
for(const auto & function : mFunctions)
|
||||
{
|
||||
duint start = ~0;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "TitanEngine/TitanEngine.h"
|
||||
#include "memory.h"
|
||||
#include "function.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
ControlFlowAnalysis::ControlFlowAnalysis(duint base, duint size, bool exceptionDirectory)
|
||||
: Analysis(base, size)
|
||||
|
|
@ -49,6 +50,8 @@ void ControlFlowAnalysis::Analyse()
|
|||
|
||||
void ControlFlowAnalysis::SetMarkers()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
FunctionDelRange(mBase, mBase + mSize - 1, false);
|
||||
auto size = mFunctionRanges.size();
|
||||
for(auto i = size - 1; i != -1; i--)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "memory.h"
|
||||
#include "console.h"
|
||||
#include "function.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
ExceptionDirectoryAnalysis::ExceptionDirectoryAnalysis(duint base, duint size)
|
||||
: Analysis(base, size)
|
||||
|
|
@ -40,6 +41,8 @@ void ExceptionDirectoryAnalysis::Analyse()
|
|||
|
||||
void ExceptionDirectoryAnalysis::SetMarkers()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
FunctionDelRange(mBase, mBase + mSize - 1, false);
|
||||
for(const auto & function : mFunctions)
|
||||
FunctionAdd(function.first, function.second, false);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "console.h"
|
||||
#include "memory.h"
|
||||
#include "function.h"
|
||||
#include "database_cb_batcher.h"
|
||||
#include <algorithm>
|
||||
|
||||
LinearAnalysis::LinearAnalysis(duint base, duint size) : Analysis(base, size)
|
||||
|
|
@ -22,6 +23,8 @@ void LinearAnalysis::Analyse()
|
|||
|
||||
void LinearAnalysis::SetMarkers()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
FunctionDelRange(mBase, mBase + mSize - 1, false);
|
||||
for(auto & function : mFunctions)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "xrefs.h"
|
||||
#include "plugin_loader.h"
|
||||
#include "loop.h"
|
||||
#include "database_cb_batcher.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
|
@ -27,6 +28,8 @@ void RecursiveAnalysis::Analyse()
|
|||
|
||||
void RecursiveAnalysis::SetMarkers()
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
if(mDump)
|
||||
for(const auto & function : mFunctions)
|
||||
FileHelper::WriteAllText(StringUtils::sprintf("cfgraph_%p.dot", function.second.entryPoint), GraphToDot(function.second));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "module.h"
|
||||
#include "memory.h"
|
||||
#include "threading.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
struct ArgumentSerializer : JSONWrapper<ARGUMENTSINFO>
|
||||
{
|
||||
|
|
@ -48,6 +49,17 @@ protected:
|
|||
{
|
||||
return ModuleRange(value.modhash, Range(value.start, value.end));
|
||||
}
|
||||
|
||||
bool populateDbOperation(DbOperation & op, const ARGUMENTSINFO & value) const override
|
||||
{
|
||||
op.itemType = DbItemTypeArgument;
|
||||
op.manual = value.manual;
|
||||
op.modhash = value.modhash;
|
||||
op.address = value.start;
|
||||
op.end = value.end;
|
||||
op.icount = value.instructioncount;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static Arguments arguments;
|
||||
|
|
@ -112,7 +124,7 @@ void ArgumentDelRange(duint Start, duint End, bool DeleteManual)
|
|||
// 0x00000000 - 0xFFFFFFFF
|
||||
if(Start == 0 && End == ~0)
|
||||
{
|
||||
ArgumentClear();
|
||||
ArgumentClear(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -126,6 +138,8 @@ void ArgumentDelRange(duint Start, duint End, bool DeleteManual)
|
|||
Start -= moduleBase;
|
||||
End -= moduleBase;
|
||||
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
arguments.DeleteWhere([ = ](const ARGUMENTSINFO & value)
|
||||
{
|
||||
if(!DeleteManual && value.manual)
|
||||
|
|
@ -142,12 +156,14 @@ void ArgumentCacheSave(JSON Root)
|
|||
|
||||
void ArgumentCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
arguments.CacheLoad(Root);
|
||||
}
|
||||
|
||||
void ArgumentClear()
|
||||
void ArgumentClear(bool Terminating)
|
||||
{
|
||||
arguments.Clear();
|
||||
DbCallbackBatcher batcher;
|
||||
arguments.Clear(Terminating);
|
||||
}
|
||||
|
||||
void ArgumentGetList(std::vector<ARGUMENTSINFO> & list)
|
||||
|
|
@ -163,4 +179,4 @@ bool ArgumentGetInfo(duint Address, ARGUMENTSINFO & info)
|
|||
bool ArgumentEnum(ARGUMENTSINFO* List, size_t* Size)
|
||||
{
|
||||
return arguments.Enum(List, Size);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ bool ArgumentDelete(duint Address);
|
|||
void ArgumentDelRange(duint Start, duint End, bool DeleteManual = false);
|
||||
void ArgumentCacheSave(JSON Root);
|
||||
void ArgumentCacheLoad(JSON Root);
|
||||
void ArgumentClear();
|
||||
void ArgumentClear(bool Terminating);
|
||||
void ArgumentGetList(std::vector<ARGUMENTSINFO> & list);
|
||||
bool ArgumentGetInfo(duint Address, ARGUMENTSINFO & info);
|
||||
bool ArgumentEnum(ARGUMENTSINFO* List, size_t* Size);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "bookmark.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
struct BookmarkSerializer : AddrInfoSerializer<BOOKMARKSINFO>
|
||||
{
|
||||
|
|
@ -10,6 +11,16 @@ struct Bookmarks : AddrInfoHashMap<LockBookmarks, BOOKMARKSINFO, BookmarkSeriali
|
|||
{
|
||||
return "bookmarks";
|
||||
}
|
||||
|
||||
protected:
|
||||
bool populateDbOperation(DbOperation & op, const BOOKMARKSINFO & value) const override
|
||||
{
|
||||
op.itemType = DbItemTypeBookmark;
|
||||
op.manual = value.manual;
|
||||
op.modhash = value.modhash;
|
||||
op.address = value.addr;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static Bookmarks bookmarks;
|
||||
|
|
@ -37,6 +48,7 @@ bool BookmarkDelete(duint Address)
|
|||
|
||||
void BookmarkDelRange(duint Start, duint End, bool Manual)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
bookmarks.DeleteRange(Start, End, Manual);
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +59,7 @@ void BookmarkCacheSave(JSON Root)
|
|||
|
||||
void BookmarkCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
bookmarks.CacheLoad(Root);
|
||||
bookmarks.CacheLoad(Root, "auto"); //legacy support
|
||||
}
|
||||
|
|
@ -56,9 +69,10 @@ bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size)
|
|||
return bookmarks.Enum(List, Size);
|
||||
}
|
||||
|
||||
void BookmarkClear()
|
||||
void BookmarkClear(bool Terminating)
|
||||
{
|
||||
bookmarks.Clear();
|
||||
DbCallbackBatcher batcher;
|
||||
bookmarks.Clear(Terminating);
|
||||
}
|
||||
|
||||
void BookmarkGetList(std::vector<BOOKMARKSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ void BookmarkDelRange(duint Start, duint End, bool Manual);
|
|||
void BookmarkCacheSave(JSON Root);
|
||||
void BookmarkCacheLoad(JSON Root);
|
||||
bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size);
|
||||
void BookmarkClear();
|
||||
void BookmarkClear(bool Terminating);
|
||||
void BookmarkGetList(std::vector<BOOKMARKSINFO> & list);
|
||||
bool BookmarkGetInfo(duint Address, BOOKMARKSINFO* info);
|
||||
|
||||
|
|
|
|||
|
|
@ -1014,7 +1014,7 @@ void BpCacheLoad(JSON Root, bool migrateCommandCondition)
|
|||
}
|
||||
}
|
||||
|
||||
void BpClear()
|
||||
void BpClear(bool Terminating)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockBreakpoints);
|
||||
breakpoints.clear();
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ bool BpResetHitCount(duint Address, BP_TYPE Type, uint32 newHitCount);
|
|||
void BpToBridge(const BREAKPOINT* Bp, BRIDGEBP* BridgeBp);
|
||||
void BpCacheSave(JSON Root);
|
||||
void BpCacheLoad(JSON Root, bool migrateCommandCondition);
|
||||
void BpClear();
|
||||
void BpClear(bool Terminating);
|
||||
void BpLogFileAcquire(const std::string & logFile);
|
||||
void BpLogFileRelease(const std::string & logFile);
|
||||
HANDLE BpLogFileOpen(const std::string & logFile);
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ bool cbInstrVisualize(int argc, char* argv[])
|
|||
duint _size = maxaddr - start;
|
||||
Memory<unsigned char*> _data(_size);
|
||||
MemRead(_base, _data(), _size);
|
||||
FunctionClear();
|
||||
FunctionClear(false);
|
||||
|
||||
//linear search with some trickery
|
||||
duint end = 0;
|
||||
|
|
@ -367,9 +367,9 @@ bool cbInstrVisualize(int argc, char* argv[])
|
|||
for(duint addr = start, fardest = 0; addr < maxaddr;)
|
||||
{
|
||||
//update GUI
|
||||
BpClear();
|
||||
BookmarkClear();
|
||||
LabelClear();
|
||||
BpClear(false);
|
||||
BookmarkClear(false);
|
||||
LabelClear(false);
|
||||
SetContextDataEx(hActiveThread, UE_CIP, addr);
|
||||
if(end)
|
||||
BpNew(end, true, false, 0, BPNORMAL, 0, nullptr);
|
||||
|
|
@ -420,8 +420,8 @@ bool cbInstrVisualize(int argc, char* argv[])
|
|||
|
||||
//update GUI
|
||||
FunctionAdd(start, end, false);
|
||||
BpClear();
|
||||
BookmarkClear();
|
||||
BpClear(false);
|
||||
BookmarkClear(false);
|
||||
SetContextDataEx(hActiveThread, UE_CIP, start);
|
||||
DebugUpdateGuiAsync(start, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ bool cbInstrCommentList(int argc, char* argv[])
|
|||
|
||||
bool cbInstrCommentClear(int argc, char* argv[])
|
||||
{
|
||||
CommentClear();
|
||||
CommentClear(false);
|
||||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All comments deleted!"));
|
||||
return true;
|
||||
|
|
@ -193,7 +193,7 @@ bool cbInstrLabelList(int argc, char* argv[])
|
|||
|
||||
bool cbInstrLabelClear(int argc, char* argv[])
|
||||
{
|
||||
LabelClear();
|
||||
LabelClear(false);
|
||||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All labels deleted!"));
|
||||
return true;
|
||||
|
|
@ -276,7 +276,7 @@ bool cbInstrBookmarkList(int argc, char* argv[])
|
|||
|
||||
bool cbInstrBookmarkClear(int argc, char* argv[])
|
||||
{
|
||||
BookmarkClear();
|
||||
BookmarkClear(false);
|
||||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All bookmarks deleted!"));
|
||||
return true;
|
||||
|
|
@ -370,7 +370,7 @@ bool cbInstrFunctionList(int argc, char* argv[])
|
|||
|
||||
bool cbInstrFunctionClear(int argc, char* argv[])
|
||||
{
|
||||
FunctionClear();
|
||||
FunctionClear(false);
|
||||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All functions deleted!"));
|
||||
return true;
|
||||
|
|
@ -461,7 +461,7 @@ bool cbInstrArgumentList(int argc, char* argv[])
|
|||
|
||||
bool cbInstrArgumentClear(int argc, char* argv[])
|
||||
{
|
||||
ArgumentClear();
|
||||
ArgumentClear(false);
|
||||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All arguments deleted!"));
|
||||
return true;
|
||||
|
|
@ -561,7 +561,7 @@ bool cbInstrLoopList(int argc, char* argv[])
|
|||
|
||||
bool cbInstrLoopClear(int argc, char* argv[])
|
||||
{
|
||||
LoopClear();
|
||||
LoopClear(false);
|
||||
GuiUpdateAllViews();
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "All loops deleted!"));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "comment.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
struct CommentSerializer : AddrInfoSerializer<COMMENTSINFO>
|
||||
{
|
||||
|
|
@ -22,6 +23,17 @@ struct Comments : AddrInfoHashMap<LockComments, COMMENTSINFO, CommentSerializer>
|
|||
{
|
||||
return "comments";
|
||||
}
|
||||
|
||||
protected:
|
||||
bool populateDbOperation(DbOperation & op, const COMMENTSINFO & value) const override
|
||||
{
|
||||
op.itemType = DbItemTypeComment;
|
||||
op.manual = value.manual;
|
||||
op.modhash = value.modhash;
|
||||
op.address = value.addr;
|
||||
op.text = value.text.c_str();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static Comments comments;
|
||||
|
|
@ -64,6 +76,7 @@ bool CommentDelete(duint Address)
|
|||
|
||||
void CommentDelRange(duint Start, duint End, bool Manual)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
comments.DeleteRange(Start, End, Manual);
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +87,7 @@ void CommentCacheSave(JSON Root)
|
|||
|
||||
void CommentCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
comments.CacheLoad(Root);
|
||||
comments.CacheLoad(Root, "auto"); //legacy support
|
||||
}
|
||||
|
|
@ -83,9 +97,10 @@ bool CommentEnum(COMMENTSINFO* List, size_t* Size)
|
|||
return comments.Enum(List, Size);
|
||||
}
|
||||
|
||||
void CommentClear()
|
||||
void CommentClear(bool Terminating)
|
||||
{
|
||||
comments.Clear();
|
||||
DbCallbackBatcher batcher;
|
||||
comments.Clear(Terminating);
|
||||
}
|
||||
|
||||
void CommentGetList(std::vector<COMMENTSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ void CommentDelRange(duint Start, duint End, bool Manual);
|
|||
void CommentCacheSave(JSON Root);
|
||||
void CommentCacheLoad(JSON Root);
|
||||
bool CommentEnum(COMMENTSINFO* List, size_t* Size);
|
||||
void CommentClear();
|
||||
void CommentClear(bool Terminating);
|
||||
void CommentGetList(std::vector<COMMENTSINFO> & list);
|
||||
bool CommentGetInfo(duint Address, COMMENTSINFO* info);
|
||||
|
||||
#endif // _COMMENT_H
|
||||
#endif // _COMMENT_H
|
||||
|
|
|
|||
|
|
@ -332,18 +332,18 @@ void DbClose()
|
|||
|
||||
void DbClear(bool terminating)
|
||||
{
|
||||
CommentClear();
|
||||
LabelClear();
|
||||
BookmarkClear();
|
||||
FunctionClear();
|
||||
ArgumentClear();
|
||||
LoopClear();
|
||||
XrefClear();
|
||||
EncodeMapClear();
|
||||
CommentClear(terminating);
|
||||
LabelClear(terminating);
|
||||
BookmarkClear(terminating);
|
||||
FunctionClear(terminating);
|
||||
ArgumentClear(terminating);
|
||||
LoopClear(terminating);
|
||||
XrefClear(terminating);
|
||||
EncodeMapClear(terminating);
|
||||
TraceRecord.clear();
|
||||
BpClear();
|
||||
ModCacheClear();
|
||||
WatchClear();
|
||||
BpClear(terminating);
|
||||
ModCacheClear(terminating);
|
||||
WatchClear(terminating);
|
||||
GuiSetDebuggeeNotes("");
|
||||
|
||||
if(terminating)
|
||||
|
|
@ -460,4 +460,4 @@ bool DbCheckHash(duint currentHash)
|
|||
duint DbGetHash()
|
||||
{
|
||||
return dbhash;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,231 @@
|
|||
#include "database_cb_batcher.h"
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
#include "_plugins.h"
|
||||
#include "plugin_loader.h"
|
||||
|
||||
thread_local DbCallbackBatcher* DbCallbackBatcher::tActiveBatcher = nullptr;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct PendingDbCallback
|
||||
{
|
||||
explicit PendingDbCallback(bool loading, uint32_t batchId)
|
||||
: loading(loading), batchId(batchId)
|
||||
{
|
||||
}
|
||||
|
||||
void add(const DbOperation & operation)
|
||||
{
|
||||
auto copy = operation;
|
||||
if((copy.itemType == DbItemTypeComment || copy.itemType == DbItemTypeLabel) && copy.text != nullptr)
|
||||
{
|
||||
strings.emplace_back(copy.text);
|
||||
copy.text = strings.back().c_str();
|
||||
}
|
||||
operations.emplace_back(copy);
|
||||
}
|
||||
|
||||
void deliver()
|
||||
{
|
||||
auto string = strings.begin();
|
||||
for(auto & operation : operations)
|
||||
{
|
||||
if((operation.itemType == DbItemTypeComment || operation.itemType == DbItemTypeLabel) && operation.text != nullptr)
|
||||
{
|
||||
ASSERT_ALWAYS(string != strings.end());
|
||||
operation.text = string++->c_str();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const DbOperation*> operationList;
|
||||
operationList.reserve(operations.size());
|
||||
for(const auto & operation : operations)
|
||||
operationList.push_back(&operation);
|
||||
|
||||
PLUG_CB_DBOPERATION info;
|
||||
info.operations = operationList.data();
|
||||
info.count = operationList.size();
|
||||
info.batchId = batchId;
|
||||
plugincbcall(loading ? CB_DBLOADOPERATION : CB_DBOPERATION, &info);
|
||||
}
|
||||
|
||||
std::vector<DbOperation> operations;
|
||||
std::deque<std::string> strings;
|
||||
bool loading;
|
||||
uint32_t batchId;
|
||||
};
|
||||
|
||||
std::recursive_mutex dbCallbackMutex;
|
||||
thread_local size_t dbCallbackOperationDepth = 0;
|
||||
thread_local DbCallbackOperation* dbCallbackOperationOwner = nullptr;
|
||||
bool deliveringDbCallbacks = false;
|
||||
std::deque<PendingDbCallback> pendingDbCallbacks;
|
||||
|
||||
void drainDbCallbacks()
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> lock(dbCallbackMutex);
|
||||
if(deliveringDbCallbacks)
|
||||
return;
|
||||
|
||||
deliveringDbCallbacks = true;
|
||||
while(!pendingDbCallbacks.empty())
|
||||
{
|
||||
auto current = std::move(pendingDbCallbacks.front());
|
||||
pendingDbCallbacks.pop_front();
|
||||
lock.unlock();
|
||||
current.deliver();
|
||||
lock.lock();
|
||||
}
|
||||
deliveringDbCallbacks = false;
|
||||
}
|
||||
|
||||
void deliverDbCallback(PendingDbCallback callback)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(dbCallbackMutex);
|
||||
pendingDbCallbacks.emplace_back(std::move(callback));
|
||||
}
|
||||
if(dbCallbackOperationDepth == 0)
|
||||
drainDbCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
DbCallbackOperation::DbCallbackOperation()
|
||||
{
|
||||
mPreviousOwner = dbCallbackOperationOwner;
|
||||
mOwner = dbCallbackOperationDepth++ == 0;
|
||||
if(mOwner)
|
||||
{
|
||||
dbCallbackOperationOwner = this;
|
||||
mLock = std::unique_lock<std::recursive_mutex>(dbCallbackMutex);
|
||||
}
|
||||
}
|
||||
|
||||
DbCallbackOperation::~DbCallbackOperation()
|
||||
{
|
||||
ASSERT_ALWAYS(dbCallbackOperationDepth > 0);
|
||||
dbCallbackOperationDepth--;
|
||||
if(mOwner)
|
||||
{
|
||||
ASSERT_ALWAYS(dbCallbackOperationDepth == 0);
|
||||
dbCallbackOperationOwner = mPreviousOwner;
|
||||
mLock.unlock();
|
||||
drainDbCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
void DbCallbackOperation::DrainAndRelock()
|
||||
{
|
||||
if(!mOwner)
|
||||
{
|
||||
ASSERT_ALWAYS(dbCallbackOperationOwner != nullptr);
|
||||
dbCallbackOperationOwner->DrainAndRelock();
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT_ALWAYS(mLock.owns_lock());
|
||||
const auto operationDepth = dbCallbackOperationDepth;
|
||||
dbCallbackOperationDepth = 0;
|
||||
mLock.unlock();
|
||||
drainDbCallbacks();
|
||||
mLock.lock();
|
||||
dbCallbackOperationDepth = operationDepth;
|
||||
}
|
||||
|
||||
DbCallbackBatcher::DbCallbackBatcher(bool loading)
|
||||
: mLoading(loading)
|
||||
{
|
||||
mPrevious = tActiveBatcher;
|
||||
mOwner = (mPrevious == nullptr);
|
||||
|
||||
if(mOwner)
|
||||
{
|
||||
static std::atomic_uint32_t gBatchId(1);
|
||||
mBatchId = gBatchId++;
|
||||
mActive = IsActive(loading);
|
||||
tActiveBatcher = this;
|
||||
}
|
||||
}
|
||||
|
||||
DbCallbackBatcher::~DbCallbackBatcher()
|
||||
{
|
||||
if(mOwner)
|
||||
{
|
||||
this->flush();
|
||||
DbCallbackBatcher::tActiveBatcher = mPrevious;
|
||||
}
|
||||
}
|
||||
|
||||
bool DbCallbackBatcher::IsActive(bool loading)
|
||||
{
|
||||
if(tActiveBatcher)
|
||||
{
|
||||
ASSERT_ALWAYS(loading == tActiveBatcher->mLoading);
|
||||
return tActiveBatcher->mActive;
|
||||
}
|
||||
return !plugincbempty(loading ? CB_DBLOADOPERATION : CB_DBOPERATION);
|
||||
}
|
||||
|
||||
void DbCallbackBatcher::Add(DbOperation & op, bool loading)
|
||||
{
|
||||
if(tActiveBatcher != nullptr)
|
||||
{
|
||||
tActiveBatcher->add(op, loading);
|
||||
}
|
||||
else
|
||||
{
|
||||
PendingDbCallback callback(loading, 0);
|
||||
callback.add(op);
|
||||
deliverDbCallback(std::move(callback));
|
||||
}
|
||||
}
|
||||
|
||||
void DbCallbackBatcher::add(DbOperation & op, bool loading)
|
||||
{
|
||||
ASSERT_ALWAYS(loading == mLoading);
|
||||
|
||||
// NOTE: bad, we already paid the DbOperation construction
|
||||
if(!mActive)
|
||||
return;
|
||||
|
||||
if((op.itemType == DbItemTypeComment || op.itemType == DbItemTypeLabel) && op.text != nullptr) // save c string in temporary string vector which will be cleared on flush
|
||||
{
|
||||
mStrings.emplace_back(op.text);
|
||||
op.text = mStrings.back().c_str();
|
||||
}
|
||||
|
||||
mOperations.emplace_back(op);
|
||||
|
||||
// Flush if we exceed the batch size threshold
|
||||
if(mOperations.size() >= 8096)
|
||||
{
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
void DbCallbackBatcher::flush()
|
||||
{
|
||||
if(mOperations.empty())
|
||||
return;
|
||||
|
||||
PendingDbCallback callback(mLoading, mBatchId);
|
||||
callback.operations.reserve(mOperations.size());
|
||||
for(const auto & operation : mOperations)
|
||||
callback.add(operation);
|
||||
|
||||
mOperations.clear();
|
||||
mStrings.clear();
|
||||
|
||||
// A callback can mutate the database. Queue those nested notifications and
|
||||
// deliver them only after every plugin has received this older batch.
|
||||
auto activeBatcher = DbCallbackBatcher::tActiveBatcher;
|
||||
if(activeBatcher == this)
|
||||
DbCallbackBatcher::tActiveBatcher = mPrevious;
|
||||
|
||||
deliverDbCallback(std::move(callback));
|
||||
mOperation.DrainAndRelock();
|
||||
|
||||
if(activeBatcher == this)
|
||||
DbCallbackBatcher::tActiveBatcher = activeBatcher;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include "_plugins.h"
|
||||
|
||||
class DbCallbackOperation
|
||||
{
|
||||
public:
|
||||
DbCallbackOperation();
|
||||
~DbCallbackOperation();
|
||||
|
||||
void DrainAndRelock();
|
||||
|
||||
DbCallbackOperation(const DbCallbackOperation &) = delete;
|
||||
DbCallbackOperation & operator=(const DbCallbackOperation &) = delete;
|
||||
|
||||
private:
|
||||
std::unique_lock<std::recursive_mutex> mLock;
|
||||
DbCallbackOperation* mPreviousOwner = nullptr;
|
||||
bool mOwner = false;
|
||||
};
|
||||
|
||||
class DbCallbackBatcher
|
||||
{
|
||||
public:
|
||||
explicit DbCallbackBatcher(bool loading = false);
|
||||
~DbCallbackBatcher();
|
||||
|
||||
static bool IsActive(bool loading = false);
|
||||
static void Add(DbOperation & op, bool loading = false);
|
||||
|
||||
private:
|
||||
static thread_local DbCallbackBatcher* tActiveBatcher; // per thread batch object
|
||||
|
||||
DbCallbackOperation mOperation;
|
||||
|
||||
void add(DbOperation & op, bool loading);
|
||||
void flush();
|
||||
|
||||
std::vector<DbOperation> mOperations;
|
||||
std::deque<std::string> mStrings;
|
||||
DbCallbackBatcher* mPrevious = nullptr;
|
||||
uint32_t mBatchId = 0;
|
||||
bool mLoading = false;
|
||||
bool mActive = false;
|
||||
bool mOwner = false; // if a batcher is defined in a thread where there's already a batcher on the stack, this is set to false
|
||||
};
|
||||
|
|
@ -3276,7 +3276,7 @@ static void debugLoopFunction(INIT_STRUCT* init)
|
|||
dbgClearRtuBreakpoints();
|
||||
ModClear();
|
||||
ThreadClear();
|
||||
WatchClear();
|
||||
WatchClear(true);
|
||||
TraceRecord.clear();
|
||||
TraceRecord.enableTraceRecording(false, nullptr); // Stop trace recording
|
||||
bIsDebugging = false;
|
||||
|
|
@ -3527,4 +3527,4 @@ bool dbgisdepenabled()
|
|||
depEnabled = true;
|
||||
#endif //_WIN64
|
||||
return depEnabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "encodemap.h"
|
||||
#include <unordered_map>
|
||||
#include "addrinfo.h"
|
||||
#include "database_cb_batcher.h"
|
||||
#include <zydis_wrapper.h>
|
||||
|
||||
struct ENCODEMAP : AddrInfo
|
||||
|
|
@ -78,6 +79,12 @@ struct EncodeMap : AddrInfoHashMap<LockEncodeMaps, ENCODEMAP, EncodeMapSerialize
|
|||
{
|
||||
return "encodemaps";
|
||||
}
|
||||
|
||||
protected:
|
||||
bool populateDbOperation(DbOperation & op, const ENCODEMAP & value) const override // Encode maps don't have database notifications
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static EncodeMap encmaps;
|
||||
|
|
@ -352,14 +359,15 @@ void EncodeMapCacheSave(JSON Root)
|
|||
|
||||
void EncodeMapCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
encmaps.CacheLoad(Root);
|
||||
}
|
||||
|
||||
void EncodeMapClear()
|
||||
void EncodeMapClear(bool Terminating)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockEncodeMaps);
|
||||
for(auto & encmap : encmaps.GetDataUnsafe())
|
||||
EncodeMapReleaseBuffer(encmap.second.data, false);
|
||||
EXCLUSIVE_RELEASE();
|
||||
encmaps.Clear();
|
||||
encmaps.Clear(Terminating);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@ void EncodeMapDelRange(duint start, duint end);
|
|||
bool EncodeMapSetType(duint addr, duint size, ENCODETYPE type, bool* created = nullptr);
|
||||
void EncodeMapCacheSave(JSON Root);
|
||||
void EncodeMapCacheLoad(JSON Root);
|
||||
void EncodeMapClear();
|
||||
void EncodeMapClear(bool Terminating);
|
||||
duint GetEncodeTypeSize(ENCODETYPE type);
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#include "module.h"
|
||||
#include "memory.h"
|
||||
#include "threading.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
struct FunctionSerializer : JSONWrapper<FUNCTIONSINFO>
|
||||
{
|
||||
|
|
@ -54,6 +55,18 @@ protected:
|
|||
{
|
||||
return ModuleRange(value.modhash, Range(value.start, value.end));
|
||||
}
|
||||
|
||||
bool populateDbOperation(DbOperation & op, const FUNCTIONSINFO & value) const override
|
||||
{
|
||||
op.itemType = DbItemTypeFunction;
|
||||
op.manual = value.manual;
|
||||
op.modhash = value.modhash;
|
||||
op.address = value.start;
|
||||
op.end = value.end;
|
||||
op.parent = value.parent;
|
||||
op.icount = value.instructioncount;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static Functions functions;
|
||||
|
|
@ -122,7 +135,7 @@ void FunctionDelRange(duint Start, duint End, bool DeleteManual)
|
|||
// 0x00000000 - 0xFFFFFFFF
|
||||
if(Start == 0 && End == ~0)
|
||||
{
|
||||
FunctionClear();
|
||||
FunctionClear(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -136,6 +149,8 @@ void FunctionDelRange(duint Start, duint End, bool DeleteManual)
|
|||
Start -= moduleBase;
|
||||
End -= moduleBase;
|
||||
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
functions.DeleteWhere([ = ](const FUNCTIONSINFO & value)
|
||||
{
|
||||
if(!DeleteManual && value.manual)
|
||||
|
|
@ -152,6 +167,7 @@ void FunctionCacheSave(JSON Root)
|
|||
|
||||
void FunctionCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
functions.CacheLoad(Root);
|
||||
functions.CacheLoad(Root, "auto"); //legacy support
|
||||
}
|
||||
|
|
@ -161,9 +177,10 @@ bool FunctionEnum(FUNCTIONSINFO* List, size_t* Size)
|
|||
return functions.Enum(List, Size);
|
||||
}
|
||||
|
||||
void FunctionClear()
|
||||
void FunctionClear(bool Terminating)
|
||||
{
|
||||
functions.Clear();
|
||||
DbCallbackBatcher batcher;
|
||||
functions.Clear(Terminating);
|
||||
}
|
||||
|
||||
void FunctionGetList(std::vector<FUNCTIONSINFO> & list)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void FunctionDelRange(duint Start, duint End, bool DeleteManual = false);
|
|||
void FunctionCacheSave(JSON Root);
|
||||
void FunctionCacheLoad(JSON Root);
|
||||
bool FunctionEnum(FUNCTIONSINFO* List, size_t* Size);
|
||||
void FunctionClear();
|
||||
void FunctionClear(bool Terminating);
|
||||
void FunctionGetList(std::vector<FUNCTIONSINFO> & list);
|
||||
bool FunctionGetInfo(duint Address, FUNCTIONSINFO & info);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "label.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
struct LabelSerializer : AddrInfoSerializer<LABELSINFO>
|
||||
{
|
||||
|
|
@ -22,6 +23,17 @@ struct Labels : AddrInfoHashMap<LockLabels, LABELSINFO, LabelSerializer>
|
|||
{
|
||||
return "labels";
|
||||
}
|
||||
|
||||
protected:
|
||||
bool populateDbOperation(DbOperation & op, const LABELSINFO & value) const override
|
||||
{
|
||||
op.itemType = DbItemTypeLabel;
|
||||
op.manual = value.manual;
|
||||
op.modhash = value.modhash;
|
||||
op.address = value.addr;
|
||||
op.text = value.text.c_str();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static Labels labels;
|
||||
|
|
@ -106,6 +118,7 @@ bool LabelDelete(duint Address)
|
|||
|
||||
void LabelDelRange(duint Start, duint End, bool Manual)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
labels.DeleteRange(Start, End, Manual);
|
||||
if(Start == 0 && End == ~0)
|
||||
{
|
||||
|
|
@ -130,13 +143,15 @@ void LabelCacheSave(JSON Root)
|
|||
|
||||
void LabelCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
labels.CacheLoad(Root);
|
||||
labels.CacheLoad(Root, "auto"); //legacy support
|
||||
}
|
||||
|
||||
void LabelClear()
|
||||
void LabelClear(bool Terminating)
|
||||
{
|
||||
labels.Clear();
|
||||
DbCallbackBatcher batcher;
|
||||
labels.Clear(Terminating);
|
||||
tempLabels.clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ bool LabelDelete(duint Address);
|
|||
void LabelDelRange(duint Start, duint End, bool Manual);
|
||||
void LabelCacheSave(JSON root);
|
||||
void LabelCacheLoad(JSON root);
|
||||
void LabelClear();
|
||||
void LabelClear(bool Terminating);
|
||||
void LabelGetList(std::vector<LABELSINFO> & list);
|
||||
bool LabelGetInfo(duint Address, LABELSINFO* info);
|
||||
std::vector<std::string> LabelFindPrefix(const std::string & prefix, int maxCount, bool isCaseSensitive);
|
||||
|
|
|
|||
174
src/dbg/loop.cpp
174
src/dbg/loop.cpp
|
|
@ -1,11 +1,34 @@
|
|||
#include "loop.h"
|
||||
#include "_plugins.h"
|
||||
#include "memory.h"
|
||||
#include "plugin_loader.h"
|
||||
#include "threading.h"
|
||||
#include "module.h"
|
||||
#include "debugger.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
static std::map<DepthModuleRange, LOOPSINFO, DepthModuleRangeCompare> loops;
|
||||
|
||||
static void populateDbOperation(DbOperation & op, const LOOPSINFO & info)
|
||||
{
|
||||
op.itemType = DbItemTypeLoop;
|
||||
op.manual = info.manual;
|
||||
op.modhash = info.modhash;
|
||||
op.address = info.start;
|
||||
op.end = info.end;
|
||||
op.parent = info.parent;
|
||||
op.icount = info.instructioncount;
|
||||
op.depth = info.depth;
|
||||
}
|
||||
|
||||
static void notifyDbOperation(DbOperationType opType, const LOOPSINFO & info, bool loading = false)
|
||||
{
|
||||
DbOperation op {};
|
||||
op.opType = opType;
|
||||
populateDbOperation(op, info);
|
||||
DbCallbackBatcher::Add(op, loading);
|
||||
}
|
||||
|
||||
bool LoopAdd(duint Start, duint End, bool Manual, duint instructionCount)
|
||||
{
|
||||
ASSERT_DEBUGGING("Export call");
|
||||
|
|
@ -24,6 +47,8 @@ bool LoopAdd(duint Start, duint End, bool Manual, duint instructionCount)
|
|||
if(moduleBase != ModBaseFromAddr(End))
|
||||
return false;
|
||||
|
||||
DbCallbackOperation callbackOperation;
|
||||
|
||||
// Loops cannot overlap other loops
|
||||
int finalDepth = 0;
|
||||
|
||||
|
|
@ -60,36 +85,57 @@ bool LoopAdd(duint Start, duint End, bool Manual, duint instructionCount)
|
|||
if(loopInfo.parent)
|
||||
loopInfo.parent -= moduleBase;
|
||||
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
|
||||
if(surround)
|
||||
std::vector<std::pair<LOOPSINFO, LOOPSINFO>> depthChanges;
|
||||
{
|
||||
// TODO: make this algorithm smarter, now it's O(n), but can be O(logn) with lower_bound
|
||||
// However, this is probably an edge case, so we can not care for now
|
||||
std::vector<std::pair<DepthModuleRange, LOOPSINFO>> reinsert;
|
||||
for(auto loopItr = loops.begin(); loopItr != loops.end();)
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
|
||||
if(surround)
|
||||
{
|
||||
auto & loop = loopItr->second;
|
||||
if(loopInfo.modhash == loop.modhash && loopInfo.start <= loop.start && loopInfo.end >= loop.end)
|
||||
// TODO: make this algorithm smarter, now it's O(n), but can be O(logn) with lower_bound
|
||||
// However, this is probably an edge case, so we can not care for now
|
||||
std::vector<std::pair<DepthModuleRange, LOOPSINFO>> reinsert;
|
||||
for(auto loopItr = loops.begin(); loopItr != loops.end();)
|
||||
{
|
||||
reinsert.emplace_back(loopItr->first, loopItr->second);
|
||||
loopItr = loops.erase(loopItr);
|
||||
auto & loop = loopItr->second;
|
||||
if(loopInfo.modhash == loop.modhash && loopInfo.start <= loop.start && loopInfo.end >= loop.end)
|
||||
{
|
||||
reinsert.emplace_back(loopItr->first, loopItr->second);
|
||||
loopItr = loops.erase(loopItr);
|
||||
}
|
||||
else
|
||||
{
|
||||
++loopItr;
|
||||
}
|
||||
}
|
||||
else
|
||||
depthChanges.reserve(reinsert.size());
|
||||
for(auto & loop : reinsert)
|
||||
{
|
||||
++loopItr;
|
||||
LOOPSINFO oldInfo = loop.second;
|
||||
loop.first.first++;
|
||||
loop.second.depth++;
|
||||
depthChanges.emplace_back(oldInfo, loop.second);
|
||||
loops.insert(loop);
|
||||
}
|
||||
}
|
||||
for(auto & loop : reinsert)
|
||||
{
|
||||
loop.first.first++;
|
||||
loop.second.depth++;
|
||||
loops.insert(loop);
|
||||
}
|
||||
|
||||
// Insert into list
|
||||
loops.emplace(DepthModuleRange(finalDepth, ModuleRange(loopInfo.modhash, Range(loopInfo.start, loopInfo.end))), loopInfo);
|
||||
}
|
||||
|
||||
if(depthChanges.empty())
|
||||
{
|
||||
notifyDbOperation(DbOperationTypeAdd, loopInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
for(const auto & depthChange : depthChanges)
|
||||
notifyDbOperation(DbOperationTypeRemove, depthChange.first);
|
||||
notifyDbOperation(DbOperationTypeAdd, loopInfo);
|
||||
for(const auto & depthChange : depthChanges)
|
||||
notifyDbOperation(DbOperationTypeAdd, depthChange.second);
|
||||
}
|
||||
|
||||
// Insert into list
|
||||
loops.emplace(DepthModuleRange(finalDepth, ModuleRange(loopInfo.modhash, Range(loopInfo.start, loopInfo.end))), loopInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -159,47 +205,68 @@ bool LoopOverlaps(int Depth, duint Start, duint End, int* FinalDepth, duint* Fin
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool LoopDeleteAllRange(const DepthModuleRange & range)
|
||||
static bool LoopDeleteAllRange(const DepthModuleRange & range, std::vector<LOOPSINFO> & erasedLoops)
|
||||
{
|
||||
auto erased = 0;
|
||||
for(auto found = loops.find(range); found != loops.end(); found = loops.find(range), erased++)
|
||||
{
|
||||
erasedLoops.push_back(found->second);
|
||||
loops.erase(found);
|
||||
}
|
||||
return erased > 0;
|
||||
}
|
||||
|
||||
void LoopDeleteRange(duint Start, duint End)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
auto modBase = ModBaseFromAddr(Start);
|
||||
auto modHash = ModHashFromAddr(modBase);
|
||||
|
||||
// Delete all loops in the given range increasing the depth until nothing is left to delete
|
||||
auto range = DepthModuleRange(0, ModuleRange(modHash, Range(Start - modBase, End - modBase)));
|
||||
while(LoopDeleteAllRange(range))
|
||||
range.first++;
|
||||
std::vector<LOOPSINFO> erasedLoops;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
|
||||
// Delete all loops in the given range increasing the depth until nothing is left to delete
|
||||
auto range = DepthModuleRange(0, ModuleRange(modHash, Range(Start - modBase, End - modBase)));
|
||||
while(LoopDeleteAllRange(range, erasedLoops))
|
||||
range.first++;
|
||||
}
|
||||
for(const LOOPSINFO & loop : erasedLoops)
|
||||
{
|
||||
notifyDbOperation(DbOperationTypeRemove, loop);
|
||||
}
|
||||
}
|
||||
|
||||
// This should delete a loop and all sub-loops that matches a certain addr
|
||||
bool LoopDelete(int Depth, duint Address)
|
||||
{
|
||||
DbCallbackBatcher batcher;
|
||||
|
||||
// Get the virtual address module
|
||||
const duint moduleBase = ModBaseFromAddr(Address);
|
||||
|
||||
// Virtual address to relative address
|
||||
Address -= moduleBase;
|
||||
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
std::vector<LOOPSINFO> erasedLoops;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
|
||||
// Search with this address range
|
||||
auto found = loops.find(DepthModuleRange(Depth, ModuleRange(ModHashFromAddr(moduleBase), Range(Address, Address))));
|
||||
if(found == loops.end())
|
||||
return false;
|
||||
// Search with this address range
|
||||
auto found = loops.find(DepthModuleRange(Depth, ModuleRange(ModHashFromAddr(moduleBase), Range(Address, Address))));
|
||||
if(found == loops.end())
|
||||
return false;
|
||||
|
||||
// Delete all loops in the given range increasing the depth until nothing is left to delete
|
||||
auto range = found->first;
|
||||
while(LoopDeleteAllRange(range))
|
||||
range.first++;
|
||||
// Delete all loops in the given range increasing the depth until nothing is left to delete
|
||||
auto range = found->first;
|
||||
while(LoopDeleteAllRange(range, erasedLoops))
|
||||
range.first++;
|
||||
}
|
||||
for(const LOOPSINFO & loop : erasedLoops)
|
||||
{
|
||||
notifyDbOperation(DbOperationTypeRemove, loop);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -245,11 +312,12 @@ void LoopCacheSave(JSON Root)
|
|||
|
||||
void LoopCacheLoad(JSON Root)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
DbCallbackBatcher batcher(true);
|
||||
|
||||
// Inline lambda to parse each JSON entry
|
||||
auto AddLoops = [](const JSON Object, bool Manual)
|
||||
{
|
||||
auto active = DbCallbackBatcher::IsActive(true);
|
||||
size_t i;
|
||||
JSON value;
|
||||
|
||||
|
|
@ -273,8 +341,15 @@ void LoopCacheLoad(JSON Root)
|
|||
if(loopInfo.end < loopInfo.start)
|
||||
continue;
|
||||
|
||||
// Insert into global list
|
||||
loops[DepthModuleRange(loopInfo.depth, ModuleRange(loopInfo.modhash, Range(loopInfo.start, loopInfo.end)))] = loopInfo;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
|
||||
// Insert into global list
|
||||
loops[DepthModuleRange(loopInfo.depth, ModuleRange(loopInfo.modhash, Range(loopInfo.start, loopInfo.end)))] = loopInfo;
|
||||
}
|
||||
|
||||
if(active)
|
||||
notifyDbOperation(DbOperationTypeAdd, loopInfo, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -320,9 +395,22 @@ bool LoopEnum(LOOPSINFO* List, size_t* Size)
|
|||
return true;
|
||||
}
|
||||
|
||||
void LoopClear()
|
||||
void LoopClear(bool Terminating)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
DbCallbackBatcher batcher;
|
||||
std::map<DepthModuleRange, LOOPSINFO, DepthModuleRangeCompare> empty;
|
||||
std::swap(loops, empty);
|
||||
}
|
||||
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(LockLoops);
|
||||
std::swap(loops, empty);
|
||||
}
|
||||
|
||||
// Do not report termination clear as a DbOperation
|
||||
if(Terminating)
|
||||
return;
|
||||
|
||||
for(auto & itr : empty)
|
||||
{
|
||||
notifyDbOperation(DbOperationTypeRemove, itr.second);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,6 @@ bool LoopDelete(int Depth, duint Address);
|
|||
void LoopCacheSave(JSON Root);
|
||||
void LoopCacheLoad(JSON Root);
|
||||
bool LoopEnum(LOOPSINFO* List, size_t* Size);
|
||||
void LoopClear();
|
||||
void LoopClear(bool Terminating);
|
||||
|
||||
#endif //_LOOP_H
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#include "database_cb_batcher.h"
|
||||
#include "ntdll/ntdll.h"
|
||||
#include "module.h"
|
||||
#include "filemap.h"
|
||||
|
|
@ -870,6 +871,12 @@ struct ModulePartyInfo : AddrInfoHashMap<LockModuleHashes, MODULEPARTYINFO, Modu
|
|||
{
|
||||
return "modules";
|
||||
}
|
||||
|
||||
protected:
|
||||
bool populateDbOperation(DbOperation & op, const MODULEPARTYINFO & value) const override // Modules don't have database notifications
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static ModulePartyInfo modulePartyInfo;
|
||||
|
|
@ -1373,7 +1380,7 @@ std::string ModNameFromHash(duint Hash)
|
|||
SHARED_ACQUIRE(LockModuleHashes);
|
||||
auto found = hashNameMap.find(Hash);
|
||||
if(found == hashNameMap.end())
|
||||
return std::string();
|
||||
return {};
|
||||
return found->second;
|
||||
}
|
||||
|
||||
|
|
@ -1474,12 +1481,13 @@ void ModCacheSave(JSON root)
|
|||
|
||||
void ModCacheLoad(JSON root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
modulePartyInfo.CacheLoad(root);
|
||||
}
|
||||
|
||||
void ModCacheClear()
|
||||
void ModCacheClear(bool Terminating)
|
||||
{
|
||||
modulePartyInfo.Clear();
|
||||
modulePartyInfo.Clear(Terminating);
|
||||
}
|
||||
|
||||
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO> & Relocations)
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ MODULEPARTY ModGetParty(duint Address);
|
|||
void ModSetParty(duint Address, MODULEPARTY Party);
|
||||
void ModCacheSave(JSON root);
|
||||
void ModCacheLoad(JSON root);
|
||||
void ModCacheClear();
|
||||
void ModCacheClear(bool Terminating);
|
||||
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO> & Relocations);
|
||||
bool ModRelocationAtAddr(duint Address, MODRELOCATIONINFO* Relocation);
|
||||
bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONINFO> & Relocations);
|
||||
|
|
|
|||
|
|
@ -431,6 +431,8 @@ bool pluginload(const char* pluginName, bool loadall)
|
|||
regExport("CBVALFROMSTRING", CB_VALFROMSTRING);
|
||||
regExport("CBVALTOSTRING", CB_VALTOSTRING);
|
||||
regExport("CBMENUPREPARE", CB_MENUPREPARE);
|
||||
regExport("CBDBOPERATION", CB_DBOPERATION);
|
||||
regExport("CBDBLOADOPERATION", CB_DBLOADOPERATION);
|
||||
|
||||
// Add plugin menus
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@
|
|||
#define _SERIALIZABLEMAP_H
|
||||
|
||||
#include "_global.h"
|
||||
#include "_plugins.h"
|
||||
#include "threading.h"
|
||||
#include "module.h"
|
||||
#include "memory.h"
|
||||
#include "jansson/jansson_x64dbg.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
template<class TValue>
|
||||
class JSONWrapper
|
||||
{
|
||||
public:
|
||||
virtual ~JSONWrapper()
|
||||
{
|
||||
}
|
||||
virtual ~JSONWrapper() = default;
|
||||
|
||||
void SetJson(JSON json)
|
||||
{
|
||||
|
|
@ -106,14 +106,27 @@ class SerializableTMap
|
|||
public:
|
||||
using TValuePred = std::function<bool(const TValue & value)>;
|
||||
|
||||
virtual ~SerializableTMap()
|
||||
{
|
||||
}
|
||||
virtual ~SerializableTMap() = default;
|
||||
|
||||
bool Add(const TValue & value)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
return addNoLock(value);
|
||||
DbCallbackOperation callbackOperation;
|
||||
bool added;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
added = addNoLock(value);
|
||||
}
|
||||
if(added && DbCallbackBatcher::IsActive())
|
||||
{
|
||||
DbOperation op {};
|
||||
op.opType = DbOperationTypeAdd;
|
||||
|
||||
if(populateDbOperation(op, value))
|
||||
{
|
||||
DbCallbackBatcher::Add(op);
|
||||
}
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
bool Get(const TKey & key, TValue & value) const
|
||||
|
|
@ -134,19 +147,63 @@ public:
|
|||
|
||||
bool Delete(const TKey & key)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
return mMap.erase(key) > 0;
|
||||
DbCallbackOperation callbackOperation;
|
||||
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 && DbCallbackBatcher::IsActive())
|
||||
{
|
||||
DbOperation op {};
|
||||
op.opType = DbOperationTypeRemove;
|
||||
|
||||
if(populateDbOperation(op, value))
|
||||
{
|
||||
DbCallbackBatcher::Add(op);
|
||||
}
|
||||
}
|
||||
return erased;
|
||||
}
|
||||
|
||||
void DeleteWhere(TValuePred predicate)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
for(auto itr = mMap.begin(); itr != mMap.end();)
|
||||
DbCallbackOperation callbackOperation;
|
||||
std::vector<TValue> erased;
|
||||
{
|
||||
if(predicate(itr->second))
|
||||
itr = mMap.erase(itr);
|
||||
else
|
||||
++itr;
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
for(auto itr = mMap.begin(); itr != mMap.end();)
|
||||
{
|
||||
if(predicate(itr->second))
|
||||
{
|
||||
erased.emplace_back(std::move(itr->second));
|
||||
|
||||
itr = mMap.erase(itr);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
if(DbCallbackBatcher::IsActive())
|
||||
{
|
||||
for(const TValue & value : erased)
|
||||
{
|
||||
DbOperation op {};
|
||||
op.opType = DbOperationTypeRemove;
|
||||
|
||||
if(populateDbOperation(op, value))
|
||||
{
|
||||
DbCallbackBatcher::Add(op);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -160,11 +217,29 @@ public:
|
|||
return getWhere(predicate, nullptr);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
void Clear(bool terminating)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
DbCallbackOperation callbackOperation;
|
||||
TMap empty;
|
||||
std::swap(mMap, empty);
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
std::swap(mMap, empty);
|
||||
}
|
||||
|
||||
// Do not report termination clear or inactive callback as a DbOperation
|
||||
if(terminating || !DbCallbackBatcher::IsActive())
|
||||
return;
|
||||
|
||||
for(const auto & kv : empty)
|
||||
{
|
||||
DbOperation op {};
|
||||
op.opType = DbOperationTypeRemove;
|
||||
|
||||
if(populateDbOperation(op, kv.second))
|
||||
{
|
||||
DbCallbackBatcher::Add(op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CacheSave(JSON root) const
|
||||
|
|
@ -187,10 +262,11 @@ public:
|
|||
|
||||
void CacheLoad(JSON root, const char* keyprefix = nullptr)
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
DbCallbackOperation callbackOperation;
|
||||
auto jsonValues = json_object_get(root, keyprefix ? (keyprefix + String(jsonKey())).c_str() : jsonKey());
|
||||
if(!jsonValues)
|
||||
return;
|
||||
auto active = DbCallbackBatcher::IsActive(true);
|
||||
size_t i;
|
||||
JSON jsonValue;
|
||||
TSerializer deserializer;
|
||||
|
|
@ -199,7 +275,24 @@ public:
|
|||
deserializer.SetJson(jsonValue);
|
||||
TValue value;
|
||||
if(deserializer.Load(value))
|
||||
addNoLock(value);
|
||||
{
|
||||
bool added;
|
||||
{
|
||||
EXCLUSIVE_ACQUIRE(TLock);
|
||||
added = addNoLock(value);
|
||||
}
|
||||
|
||||
if(added && active)
|
||||
{
|
||||
DbOperation op {};
|
||||
op.opType = DbOperationTypeAdd;
|
||||
|
||||
if(populateDbOperation(op, value))
|
||||
{
|
||||
DbCallbackBatcher::Add(op, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -252,6 +345,7 @@ public:
|
|||
protected:
|
||||
virtual const char* jsonKey() const = 0;
|
||||
virtual TKey makeKey(const TValue & value) const = 0;
|
||||
virtual bool populateDbOperation(DbOperation & op, const TValue & value) const = 0; // Should return whether a database notification is necessary or not
|
||||
|
||||
private:
|
||||
TMap mMap;
|
||||
|
|
@ -307,7 +401,7 @@ struct SerializableModuleHashMap : SerializableUnorderedMap<TLock, duint, TValue
|
|||
// 0x00000000 - 0xFFFFFFFF
|
||||
if(start == 0 && end == ~0)
|
||||
{
|
||||
this->Clear();
|
||||
this->Clear(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -405,4 +499,4 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
#endif // _SERIALIZABLEMAP_H
|
||||
#endif // _SERIALIZABLEMAP_H
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ void GuiUpdateWatchViewAsync()
|
|||
|
||||
// Global functions
|
||||
// Clear all watch
|
||||
void WatchClear()
|
||||
void WatchClear(bool Terminating)
|
||||
{
|
||||
if(!watchexpr.empty())
|
||||
{
|
||||
|
|
@ -430,4 +430,4 @@ void WatchCacheLoad(JSON root)
|
|||
WatchSetWatchdogModeUnlocked(id, watchdog_mode);
|
||||
}
|
||||
WatchInitIdCounter(); // Initialize id counter so that it begin with a unused value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public:
|
|||
extern std::map<unsigned int, WatchExpr*> watchexpr;
|
||||
|
||||
void GuiUpdateWatchViewAsync();
|
||||
void WatchClear();
|
||||
void WatchClear(bool Terminating);
|
||||
unsigned int WatchAddExpr(const char* expr, WATCHVARTYPE type);
|
||||
bool WatchModifyExpr(unsigned int id, const char* expr, WATCHVARTYPE type);
|
||||
void WatchModifyName(unsigned int id, const char* newName);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "xrefs.h"
|
||||
#include "addrinfo.h"
|
||||
#include "database_cb_batcher.h"
|
||||
|
||||
struct XREFSINFO : AddrInfo
|
||||
{
|
||||
|
|
@ -53,6 +54,12 @@ struct Xrefs : AddrInfoHashMap<LockCrossReferences, XREFSINFO, XrefSerializer>
|
|||
{
|
||||
return "xrefs";
|
||||
}
|
||||
|
||||
protected:
|
||||
bool populateDbOperation(DbOperation & op, const XREFSINFO & value) const override // Xrefs don't have database notifications
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static Xrefs xrefs;
|
||||
|
|
@ -218,10 +225,11 @@ void XrefCacheSave(JSON Root)
|
|||
|
||||
void XrefCacheLoad(JSON Root)
|
||||
{
|
||||
DbCallbackBatcher batcher(true);
|
||||
xrefs.CacheLoad(Root);
|
||||
}
|
||||
|
||||
void XrefClear()
|
||||
void XrefClear(bool Terminating)
|
||||
{
|
||||
xrefs.Clear();
|
||||
xrefs.Clear(Terminating);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ bool XrefDeleteAll(duint Address);
|
|||
void XrefDelRange(duint Start, duint End);
|
||||
void XrefCacheSave(JSON Root);
|
||||
void XrefCacheLoad(JSON Root);
|
||||
void XrefClear();
|
||||
void XrefClear(bool Terminating);
|
||||
|
||||
#endif // _FUNCTION_H
|
||||
|
|
@ -184,6 +184,7 @@ set(X64DBG_STANDARD_TESTS
|
|||
scriptcmd_call_threads
|
||||
swbp_stale
|
||||
trace_cmd_condition
|
||||
database_callbacks
|
||||
)
|
||||
|
||||
foreach(test_name IN LISTS X64DBG_STANDARD_TESTS)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
# database callback test fixture
|
||||
|
||||
This directory contains the shared executable and plugin harness for validating database operation callbacks emitted.
|
||||
|
||||
The fixture focuses on verifying that database mutations generate the correct `CB_DBOPERATION` callback payloads, including:
|
||||
|
||||
* operation type
|
||||
* item type
|
||||
* target address
|
||||
* module hash
|
||||
* optional text payload
|
||||
* optional function end address
|
||||
* optional loop nesting depth
|
||||
* single vs bulk callback behavior
|
||||
* exported callback auto-registration
|
||||
* ordering of mutations made reentrantly from a callback
|
||||
|
||||
## Why
|
||||
|
||||
The debugger supports both singular and batch-style database mutations for items such as:
|
||||
|
||||
* bookmarks
|
||||
* comments
|
||||
* labels
|
||||
* functions
|
||||
* loops
|
||||
* arguments
|
||||
|
||||
These tests ensure callback consumers can reliably distinguish:
|
||||
|
||||
* single-item operations from bulk operations
|
||||
* add/remove events
|
||||
* item categories
|
||||
* associated metadata and payloads
|
||||
|
||||
---
|
||||
|
||||
# Executable Layout
|
||||
|
||||
`target.cpp` builds a small target module exposing both code and data symbols used by the tests.
|
||||
|
||||
Exports include:
|
||||
|
||||
* `VariableTarget`
|
||||
* `FunctionTarget`
|
||||
|
||||
## Bookmark Tests
|
||||
|
||||
### `bookmark-single`
|
||||
|
||||
Validates that singular bookmark operations emit exactly one non-bulk callback.
|
||||
|
||||
### `bookmark-batch`
|
||||
|
||||
Validates that batch bookmark operations emit bulk callbacks.
|
||||
|
||||
---
|
||||
|
||||
## Comment Tests
|
||||
|
||||
### `comment-single`
|
||||
|
||||
Validates that singular comment operations emit exactly one non-bulk callback.
|
||||
|
||||
### `comment-batch`
|
||||
|
||||
Validates that batch comment operations emit bulk callbacks.
|
||||
|
||||
### `comment-reentrant`
|
||||
|
||||
Validates that a comment added reentrantly from a batch callback is delivered only
|
||||
after every plugin has received the older batch.
|
||||
|
||||
### `comment-reentrant-threaded`
|
||||
|
||||
Validates that callback delivery does not hold the writer lock while a callback waits
|
||||
for a worker thread that performs a database mutation.
|
||||
|
||||
### `comment-threaded`
|
||||
|
||||
Validates that callbacks from concurrent comment writers preserve database commit
|
||||
order, leaving the callback mirror equal to the final database value.
|
||||
|
||||
---
|
||||
|
||||
## Label Tests
|
||||
|
||||
### `label-single`
|
||||
|
||||
Validates that singular label operations emit exactly one non-bulk callback.
|
||||
|
||||
### `label-batch`
|
||||
|
||||
Validates that batch label operations emit bulk callbacks.
|
||||
|
||||
---
|
||||
|
||||
## Loop Tests
|
||||
|
||||
Loops are range items (start/end) that additionally carry a nesting `depth` and a
|
||||
`parent`. The `depth` field is surfaced through the callback payload and asserted here.
|
||||
|
||||
### `loop-single`
|
||||
|
||||
Validates that singular loop operations emit exactly one non-bulk callback, including
|
||||
the correct end address and depth (0 for a top-level loop).
|
||||
|
||||
### `loop-batch`
|
||||
|
||||
Validates that batch loop operations (e.g. `loopclear`) emit bulk callbacks.
|
||||
|
||||
---
|
||||
|
||||
## Argument Tests
|
||||
|
||||
Arguments are range items (start/end) with an instruction count, but no depth or parent.
|
||||
|
||||
### `argument-single`
|
||||
|
||||
Validates that singular argument operations emit exactly one non-bulk callback, including
|
||||
the correct end address.
|
||||
|
||||
### `argument-batch`
|
||||
|
||||
Validates that batch argument operations (e.g. `argumentclear`) emit bulk callbacks.
|
||||
|
|
@ -0,0 +1,397 @@
|
|||
#include <stdio.h>
|
||||
#define WIN32_NO_STATUS
|
||||
#include <Windows.h>
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "_plugins.h"
|
||||
#include "bridgemain.h"
|
||||
#include "database.h"
|
||||
|
||||
struct TestOperation
|
||||
{
|
||||
DbOperation operation;
|
||||
std::string text; // keep text alive
|
||||
bool bulk;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
int gPluginHandle = 0;
|
||||
std::mutex gOperationsMutex;
|
||||
std::vector<TestOperation> operations;
|
||||
bool gOpLogEnabled = false;
|
||||
bool gReentrantCommentSetPending = false;
|
||||
bool gReentrantCommentSetThreaded = false;
|
||||
duint gReentrantCommentAddress = 0;
|
||||
std::string gReentrantCommentText;
|
||||
|
||||
void resetState()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(gOperationsMutex);
|
||||
operations.clear();
|
||||
gReentrantCommentSetPending = false;
|
||||
gReentrantCommentSetThreaded = false;
|
||||
}
|
||||
|
||||
void printOperation(const DbOperation & op, bool dbLoad)
|
||||
{
|
||||
std::string text = op.opType == DbOperationTypeAdd ? "[+]" : "[-]";
|
||||
char temp[256] = "";
|
||||
{
|
||||
text += " address=0x";
|
||||
sprintf_s(temp, "%zx", op.address);
|
||||
text += temp;
|
||||
}
|
||||
|
||||
{
|
||||
char module[MAX_MODULE_SIZE] = "";
|
||||
auto hasModule = DbgFunctions()->ModNameFromHash(op.modhash, module);
|
||||
text += ", module=";
|
||||
if(hasModule)
|
||||
text += module;
|
||||
else
|
||||
text += "<none>";
|
||||
}
|
||||
|
||||
text += ", manual=";
|
||||
text += op.manual ? "true" : "false";
|
||||
text += ", dbload=";
|
||||
text += dbLoad ? "true" : "false";
|
||||
|
||||
auto printRange = [&](const char* type)
|
||||
{
|
||||
text += type;
|
||||
|
||||
text += ", end=0x";
|
||||
sprintf_s(temp, "%zx", op.end);
|
||||
text += temp;
|
||||
|
||||
text += ", parent=0x";
|
||||
sprintf_s(temp, "%zx", op.parent);
|
||||
text += temp;
|
||||
|
||||
text += ", icount=";
|
||||
sprintf_s(temp, "%zu", (size_t)op.icount);
|
||||
text += temp;
|
||||
|
||||
text += ", depth=";
|
||||
sprintf_s(temp, "%d", op.depth);
|
||||
text += temp;
|
||||
};
|
||||
|
||||
text += " type=";
|
||||
switch(op.itemType)
|
||||
{
|
||||
case DbItemTypeBookmark:
|
||||
text += "bookmark";
|
||||
break;
|
||||
case DbItemTypeLabel:
|
||||
text += "label, text=";
|
||||
text += op.text ? op.text : "<nullptr>";
|
||||
break;
|
||||
case DbItemTypeComment:
|
||||
text += "comment, text=";
|
||||
text += op.text ? op.text : "<nullptr>";
|
||||
break;
|
||||
case DbItemTypeFunction:
|
||||
printRange("function");
|
||||
break;
|
||||
case DbItemTypeLoop:
|
||||
printRange("loop");
|
||||
break;
|
||||
case DbItemTypeArgument:
|
||||
printRange("argument");
|
||||
break;
|
||||
}
|
||||
|
||||
_plugin_logputs(text.c_str());
|
||||
}
|
||||
|
||||
void cbPlugin(CBTYPE cbType, void* callbackInfo)
|
||||
{
|
||||
if(cbType == CB_INITDEBUG)
|
||||
{
|
||||
resetState();
|
||||
return;
|
||||
}
|
||||
|
||||
if(cbType == CB_DBOPERATION || cbType == CB_DBLOADOPERATION)
|
||||
{
|
||||
auto info = (PLUG_CB_DBOPERATION*) callbackInfo;
|
||||
|
||||
if(cbType == CB_DBOPERATION && gReentrantCommentSetPending)
|
||||
{
|
||||
gReentrantCommentSetPending = false;
|
||||
if(gReentrantCommentSetThreaded)
|
||||
{
|
||||
gReentrantCommentSetThreaded = false;
|
||||
std::atomic_bool success = false;
|
||||
std::thread worker([&success]()
|
||||
{
|
||||
success = DbgSetCommentAt(gReentrantCommentAddress, gReentrantCommentText.c_str());
|
||||
});
|
||||
worker.join();
|
||||
_plugin_testassert(success, "threaded reentrant comment update failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
char command[MAX_SETTING_SIZE];
|
||||
sprintf_s(command, "commentset 0x%llX, \"%s\"", (unsigned long long)gReentrantCommentAddress, gReentrantCommentText.c_str());
|
||||
_plugin_testassert(DbgCmdExecDirect(command), "reentrant command failed: %s", command);
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(gOperationsMutex);
|
||||
for(size_t i = 0; i < info->count; i ++)
|
||||
{
|
||||
const DbOperation & operation = *info->operations[i];
|
||||
|
||||
if(gOpLogEnabled)
|
||||
printOperation(operation, cbType == CB_DBLOADOPERATION);
|
||||
|
||||
std::string saved;
|
||||
|
||||
if(operation.text && (operation.itemType == DbItemTypeComment || operation.itemType == DbItemTypeLabel))
|
||||
{
|
||||
saved = std::string(operation.text);
|
||||
}
|
||||
|
||||
bool is_bulk = info->count > 1;
|
||||
operations.push_back({operation, saved, is_bulk});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
duint evalExpr(const char* expr)
|
||||
{
|
||||
return expr ? DbgValFromString(expr) : 0;
|
||||
}
|
||||
|
||||
bool cbReset(int, char**)
|
||||
{
|
||||
resetState();
|
||||
return _plugin_testassert(true, "state reset");
|
||||
}
|
||||
|
||||
bool getOpType(char s, DbOperationType & type)
|
||||
{
|
||||
if(s == 'a')
|
||||
type = DbOperationTypeAdd;
|
||||
else if(s == 'r')
|
||||
type = DbOperationTypeRemove;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getItemType(char s, DbItemType & type)
|
||||
{
|
||||
if(s == 'f')
|
||||
type = DbItemTypeFunction;
|
||||
else if(s == 'l')
|
||||
type = DbItemTypeLabel;
|
||||
else if(s == 'c')
|
||||
type = DbItemTypeComment;
|
||||
else if(s == 'b')
|
||||
type = DbItemTypeBookmark;
|
||||
else if(s == 'p')
|
||||
type = DbItemTypeLoop;
|
||||
else if(s == 'g')
|
||||
type = DbItemTypeArgument;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cbAssertLastOperation(int argc, char** argv)
|
||||
{
|
||||
if(argc < 6)
|
||||
return false;
|
||||
|
||||
std::lock_guard<std::mutex> lock(gOperationsMutex);
|
||||
if(!_plugin_testassert(operations.size() > 0, "no operations in memory"))
|
||||
return false;
|
||||
|
||||
TestOperation & last = operations.back();
|
||||
|
||||
const duint modhash = evalExpr(argv[1]);
|
||||
if(!_plugin_testassert(modhash == last.operation.modhash, "modhash passed to callback doesn't match (%llu != %llu)", (unsigned long long)last.operation.modhash, (unsigned long long)modhash))
|
||||
return false;
|
||||
|
||||
const duint target = evalExpr(argv[2]);
|
||||
if(!_plugin_testassert(target != 0, "failed to resolve target expression '%s'", argv[2]))
|
||||
return false;
|
||||
|
||||
DbItemType itemType;
|
||||
if(!_plugin_testassert(strlen(argv[3]) && getItemType(argv[3][0], itemType), "failed to resolve item type '%s'", argv[3]))
|
||||
return false;
|
||||
|
||||
if(!_plugin_testassert(last.operation.itemType == itemType, "item type passed to callback doesn't match (%d != %d)", last.operation.itemType, itemType))
|
||||
return false;
|
||||
|
||||
DbOperationType opType;
|
||||
if(!_plugin_testassert(strlen(argv[4]) && getOpType(argv[4][0], opType), "failed to resolve op type '%s'", argv[4]))
|
||||
return false;
|
||||
|
||||
if(!_plugin_testassert(last.operation.opType == opType, "operation type passed to callback doesn't match (%d != %d)", last.operation.opType, opType))
|
||||
return false;
|
||||
|
||||
bool bulk = (bool) evalExpr(argv[5]);
|
||||
|
||||
const char* text = NULL;
|
||||
if((itemType == DbItemTypeLabel || itemType == DbItemTypeComment) && argc >= 7)
|
||||
{
|
||||
text = argv[6];
|
||||
if(!_plugin_testassert(last.text == text, "text passed to callback doesn't match (%s != %s)", last.text.c_str(), text))
|
||||
return false;
|
||||
}
|
||||
|
||||
if((itemType == DbItemTypeFunction || itemType == DbItemTypeArgument || itemType == DbItemTypeLoop) && argc >= 7)
|
||||
{
|
||||
const duint end = evalExpr(argv[6]);
|
||||
if(!_plugin_testassert(last.operation.end == end, "end passed to callback doesn't match (%llu != %llu)", (unsigned long long)last.operation.end, (unsigned long long)end))
|
||||
return false;
|
||||
}
|
||||
|
||||
if(itemType == DbItemTypeLoop && argc >= 8)
|
||||
{
|
||||
const int depth = (int) evalExpr(argv[7]);
|
||||
if(!_plugin_testassert(last.operation.depth == depth, "depth passed to callback doesn't match (%d != %d)", last.operation.depth, depth))
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!_plugin_testassert(last.operation.address == target, "address passed to callback doesn't match (%llu != %llu)", (unsigned long long)last.operation.address, (unsigned long long)target))
|
||||
return false;
|
||||
|
||||
if(!_plugin_testassert(last.bulk == bulk, "bulk passed to callback doesn't match (%d != %d)", last.bulk, bulk))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cbAssertOperationsSize(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
return false;
|
||||
|
||||
std::lock_guard<std::mutex> lock(gOperationsMutex);
|
||||
const duint size = evalExpr(argv[1]);
|
||||
if(!_plugin_testassert(size == operations.size(), "total operations size doesn't match (%llu != %llu)", (unsigned long long)size, (unsigned long long)operations.size()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cbOpLog(int argc, char** argv)
|
||||
{
|
||||
bool newState = !gOpLogEnabled;
|
||||
if(argc > 1)
|
||||
newState = evalExpr(argv[1]);
|
||||
gOpLogEnabled = newState;
|
||||
_plugin_logprintf("oplog state: %s\n", gOpLogEnabled ? "on" : "off");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cbReentrantCommentSet(int argc, char** argv)
|
||||
{
|
||||
if(argc != 3)
|
||||
return false;
|
||||
|
||||
gReentrantCommentAddress = evalExpr(argv[1]);
|
||||
gReentrantCommentText = argv[2];
|
||||
gReentrantCommentSetPending = true;
|
||||
gReentrantCommentSetThreaded = false;
|
||||
return _plugin_testassert(gReentrantCommentAddress != 0, "failed to resolve reentrant comment address '%s'", argv[1]);
|
||||
}
|
||||
|
||||
bool cbThreadedReentrantCommentSet(int argc, char** argv)
|
||||
{
|
||||
if(!cbReentrantCommentSet(argc, argv))
|
||||
return false;
|
||||
gReentrantCommentSetThreaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cbThreadedComments(int argc, char** argv)
|
||||
{
|
||||
if(argc != 2)
|
||||
return false;
|
||||
|
||||
const auto address = evalExpr(argv[1]);
|
||||
if(!_plugin_testassert(address != 0, "failed to resolve threaded comment address '%s'", argv[1]))
|
||||
return false;
|
||||
|
||||
resetState();
|
||||
std::atomic_bool success = true;
|
||||
std::vector<std::thread> threads;
|
||||
for(size_t thread = 0; thread < 4; thread++)
|
||||
{
|
||||
threads.emplace_back([address, thread, &success]()
|
||||
{
|
||||
for(size_t iteration = 0; iteration < 100; iteration++)
|
||||
{
|
||||
char text[64];
|
||||
sprintf_s(text, "thread-%zu-%zu", thread, iteration);
|
||||
if(!DbgSetCommentAt(address, text))
|
||||
success = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
for(auto & thread : threads)
|
||||
thread.join();
|
||||
|
||||
char actual[MAX_COMMENT_SIZE] = "";
|
||||
if(!DbgGetCommentAt(address, actual))
|
||||
success = false;
|
||||
|
||||
std::lock_guard<std::mutex> lock(gOperationsMutex);
|
||||
const auto mirrorMatches = !operations.empty() && operations.back().text == actual;
|
||||
return _plugin_testassert(success, "a threaded comment update failed") &&
|
||||
_plugin_testassert(mirrorMatches, "callback mirror '%s' does not match database '%s'", operations.empty() ? "<empty>" : operations.back().text.c_str(), actual);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void CBDBOPERATION(CBTYPE cbType, void* callbackInfo)
|
||||
{
|
||||
cbPlugin(cbType, callbackInfo);
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void CBDBLOADOPERATION(CBTYPE cbType, void* callbackInfo)
|
||||
{
|
||||
cbPlugin(cbType, callbackInfo);
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) bool pluginit(PLUG_INITSTRUCT* initStruct)
|
||||
{
|
||||
initStruct->pluginVersion = 1;
|
||||
initStruct->sdkVersion = PLUG_SDKVERSION;
|
||||
strncpy_s(initStruct->pluginName, sizeof(initStruct->pluginName), X64DBG_TEST_NAME, _TRUNCATE);
|
||||
gPluginHandle = initStruct->pluginHandle;
|
||||
_plugin_registercallback(gPluginHandle, CB_INITDEBUG, cbPlugin);
|
||||
_plugin_registercommand(gPluginHandle, "dbreset", cbReset, false);
|
||||
_plugin_registercommand(gPluginHandle, "dboplog", cbOpLog, false);
|
||||
_plugin_registercommand(gPluginHandle, "dbreentrantcommentset", cbReentrantCommentSet, false);
|
||||
_plugin_registercommand(gPluginHandle, "dbthreadedreentrantcommentset", cbThreadedReentrantCommentSet, false);
|
||||
_plugin_registercommand(gPluginHandle, "dbthreadedcomments", cbThreadedComments, false);
|
||||
_plugin_registercommand(gPluginHandle, "assertlastop", cbAssertLastOperation, false);
|
||||
_plugin_registercommand(gPluginHandle, "assertopsize", cbAssertOperationsSize, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void plugstop()
|
||||
{
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void plugsetup(PLUG_SETUPSTRUCT*)
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#include <Windows.h>
|
||||
|
||||
#pragma section(".mbd3", read, write)
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec(allocate(".mbd3")) __declspec(dllexport) volatile signed char VariableTarget = 1;
|
||||
|
||||
#pragma code_seg(push, database_cb_code, ".mbc")
|
||||
__declspec(dllexport) __declspec(noinline) void FunctionTarget()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Sleep(1000);
|
||||
};
|
||||
#pragma code_seg(pop, membp_code)
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_g1 = database_callbacks:FunctionTarget
|
||||
_g2 = _g1 + 2
|
||||
|
||||
argumentadd _g1, _g1 + 1
|
||||
assertlastop mod.hash(mod.base(_g1)), (_g1-mod.base(_g1)), g, a, 0, (_g1+1-mod.base(_g1))
|
||||
|
||||
argumentadd _g2, _g2 + 1
|
||||
assertlastop mod.hash(mod.base(_g2)), (_g2-mod.base(_g2)), g, a, 0, (_g2+1-mod.base(_g2))
|
||||
|
||||
argumentclear
|
||||
assertlastop mod.hash(mod.base(_g2)), (_g2-mod.base(_g2)), g, r, 1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_g1 = database_callbacks:FunctionTarget
|
||||
|
||||
argumentadd _g1, _g1 + 1
|
||||
assertlastop mod.hash(mod.base(_g1)), (_g1-mod.base(_g1)), g, a, 0, (_g1+1-mod.base(_g1))
|
||||
|
||||
argumentdel _g1
|
||||
assertlastop mod.hash(mod.base(_g1)), (_g1-mod.base(_g1)), g, r, 0
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_b1 = database_callbacks:VariableTarget
|
||||
_b2 = _b1 + 4
|
||||
|
||||
bookmarkset _b1
|
||||
assertlastop mod.hash(mod.base(_b1)), (_b1-mod.base(_b1)), b, a, 0
|
||||
|
||||
bookmarkset _b2
|
||||
assertlastop mod.hash(mod.base(_b2)), (_b2-mod.base(_b2)), b, a, 0
|
||||
|
||||
bookmarkclear
|
||||
assertlastop mod.hash(mod.base(_b2)), (_b2-mod.base(_b2)), b, r, 1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_b1 = database_callbacks:VariableTarget
|
||||
|
||||
bookmarkset _b1
|
||||
assertlastop mod.hash(mod.base(_b1)), (_b1-mod.base(_b1)), b, a, 0
|
||||
|
||||
bookmarkdel _b1
|
||||
assertlastop mod.hash(mod.base(_b1)), (_b1-mod.base(_b1)), b, r, 0
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_c1 = database_callbacks:VariableTarget
|
||||
_c2 = _c1 + 4
|
||||
|
||||
commentset _c1, test1
|
||||
assertlastop mod.hash(mod.base(_c1)), (_c1-mod.base(_c1)), c, a, 0, test1
|
||||
|
||||
commentset _c2, test2
|
||||
assertlastop mod.hash(mod.base(_c2)), (_c2-mod.base(_c2)), c, a, 0, test2
|
||||
|
||||
commentclear
|
||||
assertlastop mod.hash(mod.base(_c2)), (_c2-mod.base(_c2)), c, r, 1
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_c1 = database_callbacks:VariableTarget
|
||||
_c2 = _c1 + 4
|
||||
|
||||
commentset _c1, old1
|
||||
commentset _c2, old2
|
||||
dbreset
|
||||
|
||||
dbthreadedreentrantcommentset _c1, reentrant-threaded
|
||||
commentclear
|
||||
|
||||
// Callback delivery must not hold the writer lock while waiting for a worker.
|
||||
assertopsize 3
|
||||
assertlastop mod.hash(mod.base(_c1)), (_c1-mod.base(_c1)), c, a, 0, reentrant-threaded
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_c1 = database_callbacks:VariableTarget
|
||||
_c2 = _c1 + 4
|
||||
|
||||
commentset _c1, old1
|
||||
commentset _c2, old2
|
||||
dbreset
|
||||
|
||||
dbreentrantcommentset _c1, reentrant
|
||||
commentclear
|
||||
|
||||
// Both removals must reach every plugin before the reentrant add.
|
||||
assertopsize 3
|
||||
assertlastop mod.hash(mod.base(_c1)), (_c1-mod.base(_c1)), c, a, 0, reentrant
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_c1 = database_callbacks:VariableTarget
|
||||
|
||||
commentset _c1, test
|
||||
assertlastop mod.hash(mod.base(_c1)), (_c1-mod.base(_c1)), c, a, 0, test
|
||||
|
||||
commentdel _c1
|
||||
assertlastop mod.hash(mod.base(_c1)), (_c1-mod.base(_c1)), c, r, 0
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_c1 = database_callbacks:VariableTarget
|
||||
|
||||
dbthreadedcomments _c1
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_f1 = database_callbacks:FunctionTarget
|
||||
|
||||
functionadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), f, a, 0, (_f1+1-mod.base(_f1))
|
||||
|
||||
labelset _f1, test1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), l, a, 0, test1
|
||||
|
||||
commentset _f1, test2
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), c, a, 0, test2
|
||||
|
||||
bookmarkset _f1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), b, a, 0
|
||||
|
||||
argumentadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), g, a, 0, (_f1+1-mod.base(_f1))
|
||||
|
||||
loopadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), p, a, 0, (_f1+1-mod.base(_f1)), 0
|
||||
|
||||
assertopsize 6
|
||||
|
||||
dbclear
|
||||
|
||||
assertopsize C
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_f1 = database_callbacks:FunctionTarget
|
||||
|
||||
functionadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), f, a, 0, (_f1+1-mod.base(_f1))
|
||||
|
||||
labelset _f1, test1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), l, a, 0, test1
|
||||
|
||||
commentset _f1, test2
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), c, a, 0, test2
|
||||
|
||||
bookmarkset _f1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), b, a, 0
|
||||
|
||||
argumentadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), g, a, 0, (_f1+1-mod.base(_f1))
|
||||
|
||||
loopadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), p, a, 0, (_f1+1-mod.base(_f1)), 0
|
||||
|
||||
assertopsize 6
|
||||
|
||||
stop
|
||||
init tests/database_callbacks.exe // clears the operations vector
|
||||
|
||||
assertopsize 6
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_f1 = database_callbacks:FunctionTarget
|
||||
_f2 = _f1 + 2
|
||||
|
||||
functionadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), f, a, 0, (_f1+1-mod.base(_f1))
|
||||
|
||||
functionadd _f2, _f2 + 1
|
||||
assertlastop mod.hash(mod.base(_f2)), (_f2-mod.base(_f2)), f, a, 0, (_f2+1-mod.base(_f2))
|
||||
|
||||
functionclear
|
||||
assertlastop mod.hash(mod.base(_f2)), (_f2-mod.base(_f2)), f, r, 1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_f1 = database_callbacks:FunctionTarget
|
||||
|
||||
functionadd _f1, _f1 + 1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), f, a, 0, (_f1+1-mod.base(_f1))
|
||||
|
||||
functiondel _f1
|
||||
assertlastop mod.hash(mod.base(_f1)), (_f1-mod.base(_f1)), f, r, 0
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_l1 = database_callbacks:VariableTarget
|
||||
_l2 = _l1 + 4
|
||||
|
||||
labelset _l1, test1
|
||||
assertlastop mod.hash(mod.base(_l1)), (_l1-mod.base(_l1)), l, a, 0, test1
|
||||
|
||||
labelset _l2, test2
|
||||
assertlastop mod.hash(mod.base(_l2)), (_l2-mod.base(_l2)), l, a, 0, test2
|
||||
|
||||
labelclear
|
||||
assertlastop mod.hash(mod.base(_l2)), (_l2-mod.base(_l2)), l, r, 1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_l1 = database_callbacks:VariableTarget
|
||||
|
||||
labelset _l1, test
|
||||
assertlastop mod.hash(mod.base(_l1)), (_l1-mod.base(_l1)), l, a, 0, test
|
||||
|
||||
labeldel _l1
|
||||
assertlastop mod.hash(mod.base(_l1)), (_l1-mod.base(_l1)), l, r, 0
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_p1 = database_callbacks:FunctionTarget
|
||||
_p2 = _p1 + 2
|
||||
|
||||
loopadd _p1, _p1 + 1
|
||||
assertlastop mod.hash(mod.base(_p1)), (_p1-mod.base(_p1)), p, a, 0, (_p1+1-mod.base(_p1)), 0
|
||||
|
||||
loopadd _p2, _p2 + 1
|
||||
assertlastop mod.hash(mod.base(_p2)), (_p2-mod.base(_p2)), p, a, 0, (_p2+1-mod.base(_p2)), 0
|
||||
|
||||
loopclear
|
||||
assertlastop mod.hash(mod.base(_p2)), (_p2-mod.base(_p2)), p, r, 1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
init tests/database_callbacks.exe
|
||||
|
||||
_p1 = database_callbacks:FunctionTarget
|
||||
|
||||
loopadd _p1, _p1 + 1
|
||||
assertlastop mod.hash(mod.base(_p1)), (_p1-mod.base(_p1)), p, a, 0, (_p1+1-mod.base(_p1)), 0
|
||||
|
||||
loopdel _p1
|
||||
assertlastop mod.hash(mod.base(_p1)), (_p1-mod.base(_p1)), p, r, 0
|
||||
Loading…
Reference in New Issue