Skip to content

Commit af782bc

Browse files
authored
Merge pull request #461 from BrianGodd/lab6
[LAB6] 111550083
2 parents c74ab02 + c3fd9b3 commit af782bc

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

lab6/llvm-pass.so.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@ PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1515
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
1616

1717
for (auto &F : M) {
18-
errs() << "func: " << F.getName() << "\n";
18+
//errs() << "func: " << F.getName() << "\n";
19+
if(F.getName() == "main")
20+
{
21+
//1. get into debug mode with id = 48763
22+
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
23+
Builder.CreateCall(debug_func, {debug_arg});
24+
25+
//2. let argv[1] to custom string
26+
Argument *argvArg = F.getArg(1);
27+
Value *index = ConstantInt::get(Int32Ty, 1);
28+
Value *argv_ptr = Builder.CreateInBoundsGEP(Builder.getInt8PtrTy(), argvArg, index); //指標指向的型別 (i8*)
29+
Value *custom = Builder.CreateGlobalStringPtr("hayaku... motohayaku!");
30+
Builder.CreateStore(custom, argv_ptr); //將argv[1]位址指向custom並儲存
31+
32+
//3. change argc to 48763
33+
Argument *argcArg = F.getArg(0);
34+
argcArg->replaceAllUsesWith(debug_arg);
35+
}
1936

2037
}
2138
return PreservedAnalyses::none();

0 commit comments

Comments
 (0)