@@ -71,21 +71,28 @@ impl<'c> Recorder<'c> {
71
71
options. remove ( Options :: PTRACE_O_TRACEFORK ) ;
72
72
options. remove ( Options :: PTRACE_O_TRACEVFORK ) ;
73
73
options. remove ( Options :: PTRACE_O_TRACEEXEC ) ;
74
- tracee. set_options ( options) ?;
74
+ tracee
75
+ . set_options ( options)
76
+ . context ( "setting tracee options" ) ?;
75
77
76
78
self . images = Some ( Images :: new ( tracee. pid . as_raw ( ) ) ) ;
77
- self . update_images ( & mut tracee) ?;
79
+ self . update_images ( & mut tracee)
80
+ . context ( "initial update of module images" ) ?;
78
81
79
- self . tracer . restart ( tracee, Restart :: Syscall ) ?;
82
+ self . tracer
83
+ . restart ( tracee, Restart :: Syscall )
84
+ . context ( "initial tracer restart" ) ?;
80
85
81
- while let Some ( mut tracee) = self . tracer . wait ( ) ? {
86
+ while let Some ( mut tracee) = self . tracer . wait ( ) . context ( "main tracing loop" ) ? {
82
87
match tracee. stop {
83
88
Stop :: SyscallEnterStop ( ..) => log:: trace!( "syscall-enter: {:?}" , tracee. stop) ,
84
89
Stop :: SyscallExitStop ( ..) => {
85
- self . update_images ( & mut tracee) ?;
90
+ self . update_images ( & mut tracee)
91
+ . context ( "updating module images after syscall-stop" ) ?;
86
92
}
87
93
Stop :: SignalDeliveryStop ( _pid, Signal :: SIGTRAP ) => {
88
- self . on_breakpoint ( & mut tracee) ?;
94
+ self . on_breakpoint ( & mut tracee)
95
+ . context ( "calling breakpoint handler" ) ?;
89
96
}
90
97
Stop :: Clone ( pid, tid) => {
91
98
// Only seen when the `VM_CLONE` flag is set, as of Linux 4.15.
@@ -113,7 +120,8 @@ impl<'c> Recorder<'c> {
113
120
114
121
for ( _base, image) in & events. loaded {
115
122
if self . filter . includes_module ( image. path ( ) ) {
116
- self . on_module_load ( tracee, image) ?;
123
+ self . on_module_load ( tracee, image)
124
+ . context ( "module load callback" ) ?;
117
125
}
118
126
}
119
127
@@ -137,12 +145,16 @@ impl<'c> Recorder<'c> {
137
145
. find_va_image ( pc)
138
146
. ok_or_else ( || format_err ! ( "unable to find image for va = {:x}" , pc) ) ?;
139
147
140
- let offset = image. va_to_offset ( pc) ?;
148
+ let offset = image
149
+ . va_to_offset ( pc)
150
+ . context ( "converting PC to module offset" ) ?;
141
151
self . coverage . increment ( image. path ( ) , offset) ;
142
152
143
153
// Execute clobbered instruction on restart.
144
154
regs. rip = pc;
145
- tracee. set_registers ( regs) ?;
155
+ tracee
156
+ . set_registers ( regs)
157
+ . context ( "resetting PC in breakpoint handler" ) ?;
146
158
} else {
147
159
// Assume the tracee concurrently executed an `int3` that we restored
148
160
// in another handler.
@@ -151,7 +163,9 @@ impl<'c> Recorder<'c> {
151
163
// clearing, but making their value a state.
152
164
log:: debug!( "no breakpoint at {:x}, assuming race" , pc) ;
153
165
regs. rip = pc;
154
- tracee. set_registers ( regs) ?;
166
+ tracee
167
+ . set_registers ( regs)
168
+ . context ( "resetting PC after ignoring spurious breakpoint" ) ?;
155
169
}
156
170
157
171
Ok ( ( ) )
@@ -233,11 +247,11 @@ impl Images {
233
247
}
234
248
235
249
pub fn update ( & mut self ) -> Result < LoadEvents > {
236
- let proc = Process :: new ( self . pid ) ?;
250
+ let proc = Process :: new ( self . pid ) . context ( "getting procinfo" ) ?;
237
251
238
252
let mut new = BTreeMap :: default ( ) ;
239
253
240
- for map in proc. maps ( ) ? {
254
+ for map in proc. maps ( ) . context ( "getting maps for process" ) ? {
241
255
if let Ok ( image) = ModuleImage :: new ( map) {
242
256
new. insert ( image. base ( ) , image) ;
243
257
}
@@ -374,7 +388,9 @@ impl Breakpoints {
374
388
let mut data = [ 0u8 ] ;
375
389
tracee. read_memory_mut ( va, & mut data) ?;
376
390
self . saved . insert ( va, data[ 0 ] ) ;
377
- tracee. write_memory ( va, & [ 0xcc ] ) ?;
391
+ tracee
392
+ . write_memory ( va, & [ 0xcc ] )
393
+ . context ( "setting breakpoint, writing int3" ) ?;
378
394
379
395
Ok ( ( ) )
380
396
}
@@ -383,7 +399,9 @@ impl Breakpoints {
383
399
let data = self . saved . remove ( & va) ;
384
400
385
401
let cleared = if let Some ( data) = data {
386
- tracee. write_memory ( va, & [ data] ) ?;
402
+ tracee
403
+ . write_memory ( va, & [ data] )
404
+ . context ( "clearing breakpoint, restoring byte" ) ?;
387
405
true
388
406
} else {
389
407
false
@@ -399,7 +417,9 @@ fn continue_to_init_execve(tracer: &mut Ptracer) -> Result<Tracee> {
399
417
return Ok ( tracee) ;
400
418
}
401
419
402
- tracer. restart ( tracee, Restart :: Continue ) ?;
420
+ tracer
421
+ . restart ( tracee, Restart :: Continue )
422
+ . context ( "restarting tracee pre-execve()" ) ?;
403
423
}
404
424
405
425
anyhow:: bail!( "did not see initial execve() in tracee while recording coverage" ) ;
0 commit comments