@@ -58,46 +58,46 @@ int main(int argc, char** argv) {
58
58
InstructionDecoder decoder ((const void *)nullptr , 1 , sts->getArch ());
59
59
for (auto fit = all.begin (); fit != all.end (); ++fit) {
60
60
Function* f = *fit;
61
- // get address of entry point for current function
62
- Address crtAddr = f->addr ();
63
61
int instr_count = 0 ;
64
- auto fbl = f->blocks ().end ();
65
- fbl--;
66
- Block* b = *fbl;
67
- Address lastAddr = b->end ();
68
- // if current function has zero instructions, d o n t output it
69
- if (crtAddr == lastAddr)
62
+ // if current function has zero basic blocks, d o n t output it
63
+ if (f->blocks ().empty ())
70
64
continue ;
71
65
cout << " \n\n " << hex << setfill (' 0' ) << setw (2 * sts->getAddressWidth ()) << f->addr () << " <" << f->name () << " >:\n " ;
72
- while (crtAddr < lastAddr) {
73
- // decode current instruction
74
- const unsigned char *instr_ptr = (const unsigned char *)f->isrc ()->getPtrToInstruction (crtAddr);
75
- instr = decoder.decode (instr_ptr);
66
+ auto fbl = f->blocks ().end ();
67
+ fbl--;
68
+ for (Block *b : f->blocks ()) {
69
+ Address crtAddr = b->start ();
70
+ Address lastAddr = b->end ();
71
+ while (crtAddr < lastAddr) {
72
+ // decode current instruction
73
+ const unsigned char *instr_ptr = (const unsigned char *)f->isrc ()->getPtrToInstruction (crtAddr);
74
+ instr = decoder.decode (instr_ptr);
76
75
77
- // failed to decode the instruction
78
- if (instr.size () == 0 )
79
- break ;
76
+ // failed to decode the instruction
77
+ if (instr.size () == 0 )
78
+ break ;
80
79
81
- // pretty print it
82
- cout << hex << setfill (' ' ) << setw (8 ) << crtAddr << " : " ;
83
- for (size_t i = 0 ; i < instr.size () && i < l1_width; i++) {
84
- cout << hex << setfill (' 0' ) << setw (2 ) << (unsigned )instr_ptr[i] << " " ;
85
- }
86
- for (size_t i = min (instr.size (), (size_t )l1_width); i < 8 ; i++) {
87
- cout << " " ;
88
- }
89
- cout << instr.format () << " \n " ;
90
- if (instr.size () > l1_width) {
91
- cout << hex << setfill (' ' ) << setw (8 ) << crtAddr + l1_width << " : " ;
92
- for (size_t i = l1_width; i < instr.size (); i++) {
80
+ // pretty print it
81
+ cout << hex << setfill (' ' ) << setw (8 ) << crtAddr << " : " ;
82
+ for (size_t i = 0 ; i < instr.size () && i < l1_width; i++) {
93
83
cout << hex << setfill (' 0' ) << setw (2 ) << (unsigned )instr_ptr[i] << " " ;
94
84
}
95
- cout << " \n " ;
96
- }
85
+ for (size_t i = min (instr.size (), (size_t )l1_width); i < 8 ; i++) {
86
+ cout << " " ;
87
+ }
88
+ cout << instr.format () << " \n " ;
89
+ if (instr.size () > l1_width) {
90
+ cout << hex << setfill (' ' ) << setw (8 ) << crtAddr + l1_width << " : " ;
91
+ for (size_t i = l1_width; i < instr.size (); i++) {
92
+ cout << hex << setfill (' 0' ) << setw (2 ) << (unsigned )instr_ptr[i] << " " ;
93
+ }
94
+ cout << " \n " ;
95
+ }
97
96
98
- // go to the address of the next instruction
99
- crtAddr += instr.size ();
100
- instr_count++;
97
+ // go to the address of the next instruction
98
+ crtAddr += instr.size ();
99
+ instr_count++;
100
+ }
101
101
}
102
102
}
103
103
return 0 ;
0 commit comments