Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'agent/system')
-rw-r--r--agent/system/Darwin/tcf/context-darwin.c22
-rw-r--r--agent/system/FreeBSD/tcf/context-freebsd.c22
-rw-r--r--agent/system/GNU/Linux/tcf/context-linux.c25
3 files changed, 39 insertions, 30 deletions
diff --git a/agent/system/Darwin/tcf/context-darwin.c b/agent/system/Darwin/tcf/context-darwin.c
index a91b59cf..8f8ac9e7 100644
--- a/agent/system/Darwin/tcf/context-darwin.c
+++ b/agent/system/Darwin/tcf/context-darwin.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2017 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -623,23 +623,18 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
ctx->stopped_by_exception = stopped_by_exception;
ctx->stopped = 1;
+ get_PC(ctx, &pc0);
if (EXT(ctx)->regs_error) {
release_error_report(EXT(ctx)->regs_error);
EXT(ctx)->regs_error = NULL;
}
- else {
- pc0 = get_regs_PC(ctx);
- }
-
if (thread_get_state(EXT(ctx)->pid, x86_THREAD_STATE32, EXT(ctx)->regs, &state_count) != KERN_SUCCESS) {
assert(errno != 0);
EXT(ctx)->regs_error = get_error_report(errno);
trace(LOG_ALWAYS, "error: thread_get_state failed; id %s, error %d %s",
ctx->id, errno, errno_to_str(errno));
}
- else {
- pc1 = get_regs_PC(ctx);
- }
+ get_PC(ctx, &pc1);
if (!EXT(ctx)->syscall_enter || EXT(ctx)->regs_error || pc0 != pc1) {
EXT(ctx)->syscall_enter = 0;
@@ -650,11 +645,18 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
trace(LOG_EVENTS, "event: pid %d stopped at PC = %#lx", pid, pc1);
if (signal == SIGTRAP && event == 0 && !syscall) {
+#ifdef TRAP_OFFSET
+ offs = -(TRAP_OFFSET);
+#else
size_t break_size = 0;
get_break_instruction(ctx, &break_size);
- ctx->stopped_by_bp = !EXT(ctx)->regs_error && is_breakpoint_address(ctx, pc1 - break_size);
+ offs = break_size;
+#endif
+ ctx->stopped_by_bp = !EXT(ctx)->regs_error && is_breakpoint_address(ctx, pc1 - offs);
+ if (offs != 0 && ctx->stopped_by_bp && set_PC(ctx, pc1 - offs) < 0) {
+ trace(LOG_ALWAYS, "Cannot adjust PC after breakpoint: %s", errno_to_str(errno));
+ }
EXT(ctx)->end_of_step = !ctx->stopped_by_bp && EXT(ctx)->pending_step;
- if (ctx->stopped_by_bp) set_regs_PC(ctx, pc1 - break_size);
}
EXT(ctx)->pending_step = 0;
send_context_stopped_event(ctx);
diff --git a/agent/system/FreeBSD/tcf/context-freebsd.c b/agent/system/FreeBSD/tcf/context-freebsd.c
index ad20560d..f0858f28 100644
--- a/agent/system/FreeBSD/tcf/context-freebsd.c
+++ b/agent/system/FreeBSD/tcf/context-freebsd.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2017 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -613,14 +613,11 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
ctx->stopped_by_exception = stopped_by_exception;
ctx->stopped = 1;
+ get_PC(ctx, &pc0);
if (EXT(ctx)->regs_error) {
release_error_report(EXT(ctx)->regs_error);
EXT(ctx)->regs_error = NULL;
}
- else {
- pc0 = get_regs_PC(ctx);
- }
-
if (ptrace(PTRACE_GETREGS, EXT(ctx)->pid, 0, (int)EXT(ctx)->regs) < 0) {
assert(errno != 0);
if (errno == ESRCH) {
@@ -639,18 +636,23 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
trace(LOG_ALWAYS, "error: ptrace(PTRACE_GETREGS) failed; id %s, error %d %s",
ctx->id, errno, errno_to_str(errno));
}
- else {
- pc1 = get_regs_PC(ctx);
- }
+ get_PC(ctx, &pc1);
trace(LOG_EVENTS, "event: pid %d stopped at PC = %#lx", pid, pc1);
if (signal == SIGTRAP && event == 0 && !syscall) {
+#ifdef TRAP_OFFSET
+ offs = -(TRAP_OFFSET);
+#else
size_t break_size = 0;
get_break_instruction(ctx, &break_size);
- ctx->stopped_by_bp = !EXT(ctx)->regs_error && is_breakpoint_address(ctx, pc1 - break_size);
+ offs = break_size;
+#endif
+ ctx->stopped_by_bp = !EXT(ctx)->regs_error && is_breakpoint_address(ctx, pc1 - offs);
+ if (offs != 0 && ctx->stopped_by_bp && set_PC(ctx, pc1 - offs) < 0) {
+ trace(LOG_ALWAYS, "Cannot adjust PC after breakpoint: %s", errno_to_str(errno));
+ }
EXT(ctx)->end_of_step = !ctx->stopped_by_bp && EXT(ctx)->pending_step;
- if (ctx->stopped_by_bp) set_regs_PC(ctx, pc1 - break_size);
}
EXT(ctx)->pending_step = 0;
send_context_stopped_event(ctx);
diff --git a/agent/system/GNU/Linux/tcf/context-linux.c b/agent/system/GNU/Linux/tcf/context-linux.c
index 9fa76cca..786461fe 100644
--- a/agent/system/GNU/Linux/tcf/context-linux.c
+++ b/agent/system/GNU/Linux/tcf/context-linux.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2016 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2017 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -59,10 +59,6 @@
#include <tcf/framework/context-mux.h>
#endif
-#if !defined(TRAP_OFFSET)
-#define TRAP_OFFSET -1
-#endif
-
#if !defined(PTRACE_SETOPTIONS)
#define PTRACE_SETOPTIONS (enum __ptrace_request)0x4200
#define PTRACE_GETEVENTMSG (enum __ptrace_request)0x4201
@@ -1565,7 +1561,7 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
ctx->stopped_by_exception = stopped_by_exception;
ctx->stopped = 1;
- pc0 = get_regs_PC(ctx);
+ get_PC(ctx, &pc0);
#if defined(__powerpc__) || defined(__powerpc64__)
/* Don't retrieve registers from an exiting process,
@@ -1573,7 +1569,7 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
if (event != PTRACE_EVENT_EXIT)
#endif
memset(ext->regs_valid, 0, sizeof(REG_SET));
- pc1 = get_regs_PC(ctx);
+ get_PC(ctx, &pc1);
if (syscall) {
if (!ext->syscall_enter) {
@@ -1620,9 +1616,18 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
cpu_bp_on_suspend(ctx, &cb_found);
if (signal == SIGTRAP && event == 0 && !syscall) {
- ctx->stopped_by_bp = is_breakpoint_address(ctx, pc1 + TRAP_OFFSET);
- if (ctx->stopped_by_bp) set_regs_PC(ctx, pc1 + TRAP_OFFSET);
- else ctx->stopped_by_bp = is_breakpoint_address(ctx, pc1);
+ int offs = 0;
+#ifdef TRAP_OFFSET
+ offs = -(TRAP_OFFSET);
+#else
+ size_t break_size = 0;
+ get_break_instruction(ctx, &break_size);
+ offs = break_size;
+#endif
+ ctx->stopped_by_bp = is_breakpoint_address(ctx, pc1 - offs);
+ if (offs != 0 && ctx->stopped_by_bp && set_PC(ctx, pc1 - offs) < 0) {
+ trace(LOG_ALWAYS, "Cannot adjust PC after breakpoint: %s", errno_to_str(errno));
+ }
ext->end_of_step = !ctx->stopped_by_cb && !ctx->stopped_by_bp && ext->pending_step;
}
ext->pending_step = 0;

Back to the top