|
@@ -16,6 +16,8 @@
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
#include <sys/types.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <sys/wait.h>
|
|
|
|
+#include <errno.h>
|
|
|
|
+#include <string.h>
|
|
|
|
|
|
#include "../kselftest.h"
|
|
#include "../kselftest.h"
|
|
|
|
|
|
@@ -43,7 +45,8 @@ static void set_breakpoint_addr(void *addr, int n)
|
|
ret = ptrace(PTRACE_POKEUSER, child_pid,
|
|
ret = ptrace(PTRACE_POKEUSER, child_pid,
|
|
offsetof(struct user, u_debugreg[n]), addr);
|
|
offsetof(struct user, u_debugreg[n]), addr);
|
|
if (ret)
|
|
if (ret)
|
|
- ksft_exit_fail_msg("Can't set breakpoint addr");
|
|
|
|
|
|
+ ksft_exit_fail_msg("Can't set breakpoint addr: %s\n",
|
|
|
|
+ strerror(errno));
|
|
}
|
|
}
|
|
|
|
|
|
static void toggle_breakpoint(int n, int type, int len,
|
|
static void toggle_breakpoint(int n, int type, int len,
|
|
@@ -103,8 +106,10 @@ static void toggle_breakpoint(int n, int type, int len,
|
|
|
|
|
|
ret = ptrace(PTRACE_POKEUSER, child_pid,
|
|
ret = ptrace(PTRACE_POKEUSER, child_pid,
|
|
offsetof(struct user, u_debugreg[7]), dr7);
|
|
offsetof(struct user, u_debugreg[7]), dr7);
|
|
- if (ret)
|
|
|
|
- ksft_exit_fail_msg("Can't set dr7");
|
|
|
|
|
|
+ if (ret) {
|
|
|
|
+ ksft_print_msg("Can't set dr7: %s\n", strerror(errno));
|
|
|
|
+ exit(-1);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/* Dummy variables to test read/write accesses */
|
|
/* Dummy variables to test read/write accesses */
|
|
@@ -202,7 +207,7 @@ static void trigger_tests(void)
|
|
|
|
|
|
ret = ptrace(PTRACE_TRACEME, 0, NULL, 0);
|
|
ret = ptrace(PTRACE_TRACEME, 0, NULL, 0);
|
|
if (ret) {
|
|
if (ret) {
|
|
- perror("Can't be traced?\n");
|
|
|
|
|
|
+ ksft_print_msg("Can't be traced? %s\n", strerror(errno));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -257,7 +262,6 @@ static void trigger_tests(void)
|
|
|
|
|
|
static void check_success(const char *msg)
|
|
static void check_success(const char *msg)
|
|
{
|
|
{
|
|
- const char *msg2;
|
|
|
|
int child_nr_tests;
|
|
int child_nr_tests;
|
|
int status;
|
|
int status;
|
|
int ret;
|
|
int ret;
|
|
@@ -265,7 +269,6 @@ static void check_success(const char *msg)
|
|
/* Wait for the child to SIGTRAP */
|
|
/* Wait for the child to SIGTRAP */
|
|
wait(&status);
|
|
wait(&status);
|
|
|
|
|
|
- msg2 = "Failed";
|
|
|
|
ret = 0;
|
|
ret = 0;
|
|
|
|
|
|
if (WSTOPSIG(status) == SIGTRAP) {
|
|
if (WSTOPSIG(status) == SIGTRAP) {
|
|
@@ -274,7 +277,7 @@ static void check_success(const char *msg)
|
|
if (child_nr_tests == nr_tests)
|
|
if (child_nr_tests == nr_tests)
|
|
ret = 1;
|
|
ret = 1;
|
|
if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1))
|
|
if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1))
|
|
- ksft_exit_fail_msg("Can't poke");
|
|
|
|
|
|
+ ksft_exit_fail_msg("Can't poke: %s\n", strerror(errno));
|
|
}
|
|
}
|
|
|
|
|
|
nr_tests++;
|
|
nr_tests++;
|
|
@@ -293,7 +296,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global)
|
|
set_breakpoint_addr(dummy_funcs[i], i);
|
|
set_breakpoint_addr(dummy_funcs[i], i);
|
|
toggle_breakpoint(i, BP_X, 1, local, global, 1);
|
|
toggle_breakpoint(i, BP_X, 1, local, global, 1);
|
|
ptrace(PTRACE_CONT, child_pid, NULL, 0);
|
|
ptrace(PTRACE_CONT, child_pid, NULL, 0);
|
|
- sprintf(buf, "Test breakpoint %d with local: %d global: %d",
|
|
|
|
|
|
+ sprintf(buf, "Test breakpoint %d with local: %d global: %d\n",
|
|
i, local, global);
|
|
i, local, global);
|
|
check_success(buf);
|
|
check_success(buf);
|
|
toggle_breakpoint(i, BP_X, 1, local, global, 0);
|
|
toggle_breakpoint(i, BP_X, 1, local, global, 0);
|
|
@@ -315,8 +318,9 @@ static void launch_watchpoints(char *buf, int mode, int len,
|
|
set_breakpoint_addr(&dummy_var[i], i);
|
|
set_breakpoint_addr(&dummy_var[i], i);
|
|
toggle_breakpoint(i, mode, len, local, global, 1);
|
|
toggle_breakpoint(i, mode, len, local, global, 1);
|
|
ptrace(PTRACE_CONT, child_pid, NULL, 0);
|
|
ptrace(PTRACE_CONT, child_pid, NULL, 0);
|
|
- sprintf(buf, "Test %s watchpoint %d with len: %d local: "
|
|
|
|
- "%d global: %d", mode_str, i, len, local, global);
|
|
|
|
|
|
+ sprintf(buf,
|
|
|
|
+ "Test %s watchpoint %d with len: %d local: %d global: %d\n",
|
|
|
|
+ mode_str, i, len, local, global);
|
|
check_success(buf);
|
|
check_success(buf);
|
|
toggle_breakpoint(i, mode, len, local, global, 0);
|
|
toggle_breakpoint(i, mode, len, local, global, 0);
|
|
}
|
|
}
|
|
@@ -382,7 +386,7 @@ int main(int argc, char **argv)
|
|
pid = fork();
|
|
pid = fork();
|
|
if (!pid) {
|
|
if (!pid) {
|
|
trigger_tests();
|
|
trigger_tests();
|
|
- return 0;
|
|
|
|
|
|
+ exit(0);
|
|
}
|
|
}
|
|
|
|
|
|
child_pid = pid;
|
|
child_pid = pid;
|
|
@@ -393,5 +397,5 @@ int main(int argc, char **argv)
|
|
|
|
|
|
wait(NULL);
|
|
wait(NULL);
|
|
|
|
|
|
- return ksft_exit_pass();
|
|
|
|
|
|
+ ksft_exit_pass();
|
|
}
|
|
}
|