Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
4lDO2
acid
Commits
b5045b3c
Verified
Commit
b5045b3c
authored
Aug 15, 2019
by
jD91mZM2
Browse files
Add ptrace exit breakpoint
This will let you stop at process exit and inspect it right before the process dies.
parent
f49822d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
b5045b3c
...
...
@@ -426,13 +426,26 @@ pub fn ptrace() -> Result<(), String> {
let
mut
tracer
=
e
(
tracer
.blocking
())
?
;
println!
(
"Checking exit syscall..."
);
e
(
next
(
&
mut
tracer
,
Flags
::
STOP_PRE_SYSCALL
|
Flags
::
FLAG_IGNORE
))
?
;
e
(
next
(
&
mut
tracer
,
Flags
::
STOP_PRE_SYSCALL
|
Flags
::
STOP_EXIT
|
Flags
::
FLAG_IGNORE
))
?
;
let
regs
=
e
(
tracer
.regs
.get_int
())
?
;
assert_eq!
(
regs
.rax
,
syscall
::
SYS_EXIT
);
assert_eq!
(
regs
.rdi
,
123
);
assert_eq!
(
next
(
&
mut
tracer
,
Flags
::
STOP_POST_SYSCALL
)
.unwrap_err
()
.raw_os_error
(),
Some
(
syscall
::
ESRCH
));
println!
(
"Checking exit breakpoint..."
);
let
event
=
e
(
tracer
.next
(
Flags
::
STOP_POST_SYSCALL
|
Flags
::
STOP_EXIT
))
?
;
assert_eq!
(
event
.cause
,
Flags
::
STOP_EXIT
);
match
event
.data
{
EventData
::
StopExit
(
status
)
=>
{
assert
!
(
syscall
::
wifexited
(
status
));
assert_eq!
(
syscall
::
wexitstatus
(
status
),
123
);
},
ref
e
=>
return
Err
(
format!
(
"Wrong event type: {:?}"
,
e
))
}
println!
(
"Checking exit status (waitpid nohang)..."
);
assert_eq!
(
next
(
&
mut
tracer
,
Flags
::
STOP_POST_SYSCALL
|
Flags
::
STOP_EXIT
)
.unwrap_err
()
.raw_os_error
(),
Some
(
syscall
::
ESRCH
));
let
mut
status
=
0
;
e
(
syscall
::
waitpid
(
pid
,
&
mut
status
,
syscall
::
WNOHANG
))
?
;
assert
!
(
syscall
::
wifexited
(
status
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment