Skip to content

Commit a3730cc

Browse files
committed
Support multiple --patch/-P options per --match/-M
1 parent 267ca9d commit a3730cc

9 files changed

Lines changed: 193 additions & 128 deletions

File tree

src/e9tool/e9frontend.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ enum CallJump
9696
JUMP_GOTO, // if (addr = f(...)) goto addr; ...
9797
};
9898

99-
/*
100-
* Metadata.
101-
*/
102-
typedef std::map<const char *, const char *> Metadata;
103-
10499
/*
105100
* Mnemonics.
106101
*/
@@ -2321,8 +2316,6 @@ extern void sendCode(FILE *out, const char *code);
23212316
* High-level functions that send complete E9PATCH JSONRPC messages:
23222317
*/
23232318
extern unsigned sendOptionsMessage(FILE *out, std::vector<const char *> &argv);
2324-
// extern unsigned sendPatchMessage(FILE *out, const char *trampoline,
2325-
// off_t offset, const Metadata *metadata = nullptr);
23262319
extern unsigned sendReserveMessage(FILE *out, intptr_t addr, size_t len,
23272320
bool absolute = false);
23282321
extern unsigned sendReserveMessage(FILE *out, intptr_t addr,

src/e9tool/e9metadata.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,18 +1059,19 @@ static void sendBytesData(FILE *out, const uint8_t *bytes, size_t len)
10591059
static bool matchEval(const MatchExpr *expr, const Targets &targets,
10601060
const InstrInfo *I, const char *basename = nullptr,
10611061
const Record **record = nullptr);
1062-
static intptr_t lookupValue(const Action *action, const Targets &targets,
1063-
const InstrInfo *I, const char *basename, intptr_t idx)
1062+
static intptr_t lookupValue(const Action *action, size_t idx,
1063+
const Targets &targets, const InstrInfo *I, const char *basename,
1064+
intptr_t pos)
10641065
{
10651066
const Record *record = nullptr;
10661067
bool pass = matchEval(action->match, targets, I, basename, &record);
10671068
if (!pass || record == nullptr)
10681069
error("failed to lookup value from file \"%s.csv\"; matching is "
10691070
"ambiguous", basename);
1070-
if (idx >= (intptr_t)record->size())
1071+
if (pos >= (intptr_t)record->size())
10711072
error("failed to lookup value from file \"%s.csv\"; index %zd is "
1072-
"out-of-range 0..%zu", basename, idx, record->size()-1);
1073-
const char *str = record->at(idx);
1073+
"out-of-range 0..%zu", basename, pos, record->size()-1);
1074+
const char *str = record->at(pos);
10741075
intptr_t x = nameToInt(basename, str);
10751076
return x;
10761077
}
@@ -1079,24 +1080,24 @@ static intptr_t lookupValue(const Action *action, const Targets &targets,
10791080
* Send instructions to load an argument into a register.
10801081
*/
10811082
static Type sendLoadArgumentMetadata(FILE *out, CallInfo &info,
1082-
const ELF *elf, const Action *action, const Argument &arg,
1083+
const ELF *elf, const Action *action, size_t idx, const Argument &arg,
10831084
const InstrInfo *I, intptr_t id, int argno, int regno)
10841085
{
10851086
if (regno < 0)
10861087
error("failed to load argument; call instrumentation exceeds the "
10871088
"maximum number of arguments (%d)", argno);
10881089
sendSaveRegToStack(out, info, getReg(regno));
10891090

1090-
const Patch *patch = action->patch;
1091+
const Patch *patch = action->patch[idx];
10911092
const char *name = patch->name+1;
10921093
bool _static = arg._static;
10931094
Type t = TYPE_INT64;
10941095
switch (arg.kind)
10951096
{
10961097
case ARGUMENT_USER:
10971098
{
1098-
intptr_t value = lookupValue(action, elf->targets, I, arg.name,
1099-
arg.value);
1099+
intptr_t value = lookupValue(action, idx, elf->targets, I,
1100+
arg.name, arg.value);
11001101
sendLoadValueMetadata(out, value, regno);
11011102
break;
11021103
}
@@ -1491,11 +1492,11 @@ static void sendArgumentDataMetadata(FILE *out, const char *name,
14911492
* Build metadata.
14921493
*/
14931494
static bool sendMetadata(FILE *out, const ELF *elf, const Action *action,
1494-
const InstrInfo *I, intptr_t id)
1495+
size_t idx, const InstrInfo *I, intptr_t id)
14951496
{
14961497
if (action == nullptr)
14971498
return false;
1498-
const Patch *patch = action->patch;
1499+
const Patch *patch = action->patch[idx];
14991500
const char *name = patch->name+1;
15001501

15011502
switch (patch->kind)
@@ -1550,8 +1551,8 @@ static bool sendMetadata(FILE *out, const ELF *elf, const Action *action,
15501551
for (const auto &arg: patch->args)
15511552
{
15521553
int regno = getArgRegIdx(sysv, argno);
1553-
Type t = sendLoadArgumentMetadata(out, info, elf, action, arg,
1554-
I, id, argno, regno);
1554+
Type t = sendLoadArgumentMetadata(out, info, elf, action, idx,
1555+
arg, I, id, argno, regno);
15551556
sig = setType(sig, t, argno);
15561557
argno++;
15571558
}

0 commit comments

Comments
 (0)