File: pointers

package info (click to toggle)
bpftrace 0.24.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,496 kB
  • sloc: cpp: 60,982; ansic: 10,952; python: 953; yacc: 665; sh: 536; lex: 295; makefile: 22
file content (105 lines) | stat: -rw-r--r-- 2,755 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
NAME u8 pointer increment
PROG begin { @=(int8*) 0x32; @+=1;  }
EXPECT @: 0x33

NAME u16 pointer increment
PROG begin { @=(int16*) 0x32; @+=1;  }
EXPECT @: 0x34

NAME u32 pointer increment
PROG begin { @=(int32*) 0x32; @+=1;  }
EXPECT @: 0x36

NAME u64 pointer increment
PROG begin { @=(int64*) 0x32; @+=1;  }
EXPECT @: 0x3a

NAME u8 pointer unop post increment
PROG begin { @=(int8*) 0x32; @++;  }
EXPECT @: 0x33

NAME u16 pointer unop post increment
PROG begin { @=(int16*) 0x32; @++;  }
EXPECT @: 0x34

NAME u32 pointer unop post increment
PROG begin { @=(int32*) 0x32; @++;  }
EXPECT @: 0x36

NAME u64 pointer unop post increment
PROG begin { @=(int64*) 0x32; @++;  }
EXPECT @: 0x3a

NAME u8 pointer unop pre increment
PROG begin { @=(int8*) 0x32; @++;  }
EXPECT @: 0x33

NAME u16 pointer unop pre increment
PROG begin { @=(int16*) 0x32; @++;  }
EXPECT @: 0x34

NAME u32 pointer unop pre increment
PROG begin { @=(int32*) 0x32; @++;  }
EXPECT @: 0x36

NAME u64 pointer unop pre increment
PROG begin { @=(int64*) 0x32; @++;  }
EXPECT @: 0x3a

NAME Pointer decrement 1
PROG begin { @=(int32*) 0x32; @-=1;  }
EXPECT @: 0x2e

NAME Pointer decrement
PROG begin { @=(int32*) 0x32; @--;  }
EXPECT @: 0x2e

NAME Pointer increment 6
PROG begin { @=(int32*) 0x32; @+=6;  }
EXPECT @: 0x4a

NAME Pointer decrement 6
PROG begin { @=(int32*) 0x32; @-=6;  }
EXPECT @: 0x1a

NAME Struct pointer math
PROG struct A {int32_t a; int32_t b; char c[28] }; begin { $a=(struct A*) 1024; printf("%lu - 5 x %lu = %lu\n", $a, sizeof(struct A), $a-5);  }
EXPECT 1024 - 5 x 36 = 844

NAME Pointer decrement with map
PROG begin { @dec = 4; @=(int32*) 0x32; @-=@dec;  }
EXPECT @: 0x22

NAME Pointer walk through struct
RUN {{BPFTRACE}} runtime/scripts/struct_walk.bt -c ./testprogs/struct_walk
EXPECT a: 45 b: 1000

NAME Pointer arith with int32
PROG struct C { uint32_t a; }; uprobe:./testprogs/struct_walk:clear { $c = (struct C *)arg0; printf("ptr: %p\n", $c + $c->a); exit() }
AFTER ./testprogs/struct_walk
EXPECT_REGEX ^ptr: 0x[0-9a-z]+

NAME Pointer to pointer arithmetic and dereference
PROG uprobe:./testprogs/array_access:test_ptr_array { $p = (int32 **)arg0; @x = **($p + 1); exit(); }
EXPECT @x: 2
AFTER ./testprogs/array_access

NAME Pointer is truthy for if conditions
PROG begin { if (curtask) { @ = 1; }  }
EXPECT @: 1

NAME Pointer is truthy for tenary expressions
PROG begin { @ = curtask ? 1 : 2;  }
EXPECT @: 1

NAME Pointer is useable in logical and expressions
PROG begin { @ = (curtask && 0) ? 1 : 2;  }
EXPECT @: 2

NAME Pointer is useable in logical or expressions
PROG begin { @ = (curtask || 0) ? 1 : 2;  }
EXPECT @: 1

NAME pointer/int comparison
PROG begin { $a = (int64*) 0x32; $a++; if (0x32 < $a && $a > 0x32) { print("SUCCESS"); }  }
EXPECT SUCCESS