Skip to content

Commit e709a23

Browse files
committed
add some code to debug
Signed-off-by: cppbear <[email protected]>
1 parent c9109c6 commit e709a23

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

.vscode/launch.json

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
// ],
2424
"args": [
2525
"--project",
26-
"/home/chubei/utgen-focal/json",
26+
"/home/chubei/utgen-focal/lz4",
2727
"-p",
28-
"/home/chubei/utgen-focal/json/build",
29-
"/home/chubei/utgen-focal/json/include/nlohmann/detail/input/lexer.hpp",
30-
// "/home/chubei/utgen-focal/json/single_include/nlohmann/json.hpp",
28+
"/home/chubei/utgen-focal/lz4/build-cmake",
29+
"/home/chubei/utgen-focal/lz4/lib/lz4hc.c",
3130
"-f",
32-
// "scan_number",
33-
"scan_comment",
31+
"LZ4HC_compress_optimal",
3432
// "--cfg",
3533
// "--",
3634
// "-ferror-limit=0"
@@ -48,15 +46,13 @@
4846
"program": "build/release/bin/brinfo",
4947
"args": [
5048
"--project",
51-
"clang-tools-extra/brinfo/test",
52-
"clang-tools-extra/brinfo/test/c.cpp",
49+
"/home/chubei/utgen-focal/lz4",
50+
"-p",
51+
"/home/chubei/utgen-focal/lz4/build-cmake",
52+
"/home/chubei/utgen-focal/lz4/lib/lz4hc.c",
5353
"-f",
54-
"readComment",
55-
// "-c",
56-
// "Reader",
57-
"--cfg",
58-
"--",
59-
"-ferror-limit=0"
54+
"LZ4HC_compress_optimal",
55+
// "--cfg",
6056
],
6157
// "args": [
6258
// "--project",

clang-tools-extra/brinfo/Analysis.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void Analysis::setSignature() {
103103
}
104104
Signature += ")";
105105
DEBUG_PRINT("Signature: " << Signature);
106+
// outs() << "Signature: " << Signature << "\n";
106107
}
107108

108109
void Analysis::extractCondChains() {
@@ -327,11 +328,15 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
327328
BaseCond *Condition = BlkCond.Condition;
328329
bool Flag = BlkCond.Flag;
329330
bool InLoop = BlkCond.InLoop;
331+
vector<unsigned> LoopBlks = BlkCond.LoopBlks;
330332
unsigned ID = Blk->getBlockID();
331333

332334
DEBUG_PRINT("Block: " << ID << " Parent: " << Parent);
333335
// DEBUG_EXEC(dumpBlkChain());
334336

337+
if (ID == 43)
338+
int A = 0;
339+
335340
if (ColorOfBlk[ID] == 0)
336341
ColorOfBlk[ID] = 1;
337342

@@ -351,6 +356,8 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
351356
if (binary_search(SortedPath.begin(), SortedPath.end(), Blk)) {
352357
DEBUG_PRINT("Loop detected at Block " << Blk->getBlockID() << " in "
353358
<< Signature);
359+
if (Blk->getBlockID() == 44)
360+
int A = 0;
354361
DEBUG_EXEC(unsigned I = 0; for (const CFGBlock *Blk
355362
: Path) {
356363
if (I++ > 0)
@@ -364,16 +371,23 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
364371
if (LoopInner[Blk->getBlockID()].find(Adj->getBlockID()) !=
365372
LoopInner[Blk->getBlockID()].end())
366373
continue;
367-
Stack.push({Parent, Adj, Condition, Flag, true});
374+
outs() << "Stack push " << Adj->getBlockID() << "\n";
375+
vector<unsigned> Loop = {};
376+
for (const CFGBlock *Blk : Path) {
377+
Loop.push_back(Blk->getBlockID());
378+
}
379+
Stack.push({Parent, Adj, Condition, Flag, true, Loop});
368380
Traverse = true;
369381
}
370382
}
371383
}
384+
//FIXME: consider remove this
372385
if (!Traverse && InLoop) {
373386
unsigned PathSize = Path.size();
374387
for (unsigned I = PathSize - 1; I > 0; --I) {
375388
const CFGBlock *Succ = Path[I];
376389
const CFGBlock *Pred = Path[I - 1];
390+
outs() << "Clear Block " << Succ->getBlockID() << "\n";
377391
CondChainForBlk[Succ->getBlockID()] = {}; // clear
378392
bool IsSucc = isSucc(Pred, Succ);
379393
if (!IsSucc) {
@@ -398,7 +412,8 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
398412
if (Terminator) {
399413
switch (Terminator->getStmtClass()) {
400414
default:
401-
errs() << "Unhandled Terminator: " << Terminator->getStmtClassName() << "\n";
415+
errs() << "Unhandled Terminator: " << Terminator->getStmtClassName()
416+
<< "\n";
402417
break;
403418
case Stmt::ConditionalOperatorClass:
404419
case Stmt::BinaryOperatorClass:
@@ -411,16 +426,16 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
411426
const CFGBlock::AdjacentBlock *Adj = Blk->succ_begin();
412427
if (Cond) {
413428
if (Adj->isReachable()) {
414-
Stack.push({ID, *Adj, Cond, true, InLoop});
429+
Stack.push({ID, *Adj, Cond, true, InLoop, LoopBlks});
415430
}
416431
if (Blk->succ_size() == 2) {
417432
++Adj;
418433
if (Adj->isReachable()) {
419-
Stack.push({ID, *Adj, Cond, false, InLoop});
434+
Stack.push({ID, *Adj, Cond, false, InLoop, LoopBlks});
420435
}
421436
}
422437
} else if (Adj->isReachable()) {
423-
Stack.push({ID, *Adj, nullptr, false, InLoop});
438+
Stack.push({ID, *Adj, nullptr, false, InLoop, LoopBlks});
424439
}
425440
break;
426441
}
@@ -444,7 +459,7 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
444459
Cond = new CaseCond(cast<Expr>(InnerCond)->IgnoreParenImpCasts(),
445460
Case);
446461
}
447-
Stack.push({ID, Adj, Cond, true, InLoop});
462+
Stack.push({ID, Adj, Cond, true, InLoop, LoopBlks});
448463
} else {
449464
// Default case
450465
assert(Label->getStmtClass() == Stmt::DefaultStmtClass);
@@ -456,7 +471,7 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
456471
if (InnerCond) {
457472
Cond = new DefaultCond(InnerCond, Cases);
458473
}
459-
Stack.push({ID, DefaultBlk, Cond, false, InLoop});
474+
Stack.push({ID, DefaultBlk, Cond, false, InLoop, LoopBlks});
460475
}
461476
break;
462477
}
@@ -472,31 +487,35 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
472487
const CFGBlock::AdjacentBlock *Adj = Blk->succ_begin();
473488
if (InnerCond) {
474489
if (Adj->isReachable()) {
475-
Stack.push({ID, *Adj, Cond, true, InLoop});
490+
outs() << "Stack push " << (*Adj)->getBlockID() << "\n";
491+
Stack.push({ID, *Adj, Cond, true, InLoop, LoopBlks});
476492
}
477493
if (Blk->succ_size() == 2) {
478494
++Adj;
479495
if (Adj->isReachable()) {
480-
Stack.push({ID, *Adj, Cond, false, InLoop});
496+
outs() << "Stack push " << (*Adj)->getBlockID() << "\n";
497+
Stack.push({ID, *Adj, Cond, false, InLoop, LoopBlks});
481498
}
482499
}
483500
} else if (Adj->isReachable()) {
484-
Stack.push({ID, *Adj, nullptr, false, InLoop});
501+
outs() << "Stack push " << (*Adj)->getBlockID() << "\n";
502+
Stack.push({ID, *Adj, nullptr, false, InLoop, LoopBlks});
485503
}
486504
break;
487505
}
488506
case Stmt::BreakStmtClass:
489507
case Stmt::ContinueStmtClass:
490508
case Stmt::GotoStmtClass: {
491509
if (Blk->succ_begin()->isReachable()) {
492-
Stack.push({ID, *Blk->succ_begin(), nullptr, false, InLoop});
510+
Stack.push(
511+
{ID, *Blk->succ_begin(), nullptr, false, InLoop, LoopBlks});
493512
}
494513
break;
495514
}
496515
}
497516
} else if (Blk->succ_size() == 1) {
498517
if (Blk->succ_begin()->isReachable()) {
499-
Stack.push({ID, *Blk->succ_begin(), nullptr, false, InLoop});
518+
Stack.push({ID, *Blk->succ_begin(), nullptr, false, InLoop, LoopBlks});
500519
}
501520
} else if (Blk->getBlockID() == Cfg->getExit().getBlockID()) {
502521
// Exit Block

clang-tools-extra/brinfo/Analysis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct BlkCond {
1515
BaseCond *Condition = nullptr;
1616
bool Flag = false;
1717
bool InLoop = false;
18+
vector<unsigned> LoopBlks = {};
1819
};
1920

2021
class Analysis {

0 commit comments

Comments
 (0)