TCF Agent: moved CPU dependent code from framework/cpudefs.c to machine/cpudefs-ext.h to allow client extensions of the code.
diff --git a/agent.vcproj b/agent.vcproj
index b9f029d..5cafae5 100644
--- a/agent.vcproj
+++ b/agent.vcproj
@@ -954,6 +954,10 @@
 		<Filter

 			Name="machine"

 			>

+			<File

+				RelativePath=".\machine\cpudefs-ext.h"

+				>

+			</File>

 			<Filter

 				Name="x86_64"

 				>

diff --git a/framework/cpudefs.c b/framework/cpudefs.c
index a16ae08..2955f3a 100644
--- a/framework/cpudefs.c
+++ b/framework/cpudefs.c
@@ -29,125 +29,7 @@
 #include <framework/myalloc.h>
 #include <framework/exceptions.h>
 #include <services/symbols.h>
-
-#if ENABLE_ContextProxy
-
-/* Register definitions are provided by context proxy */
-
-#else
-
-#include <cpudefs-mdep.h>
-
-struct RegisterData {
-    REG_SET data;
-    REG_SET mask;
-};
-
-RegisterDefinition * get_reg_definitions(Context * ctx) {
-    return regs_index;
-}
-
-size_t get_break_size(void) {
-    return sizeof(BREAK_INST);
-}
-
-static RegisterDefinition * get_reg_by_dwarf_id(unsigned id) {
-    static RegisterDefinition ** map = NULL;
-    static unsigned map_length = 0;
-
-    if (map == NULL) {
-        RegisterDefinition * r;
-        for (r = get_reg_definitions(NULL); r->name != NULL; r++) {
-            if (r->dwarf_id >= (int)map_length) map_length = r->dwarf_id + 1;
-        }
-        map = (RegisterDefinition **)loc_alloc_zero(sizeof(RegisterDefinition *) * map_length);
-        for (r = get_reg_definitions(NULL); r->name != NULL; r++) {
-            if (r->dwarf_id >= 0) map[r->dwarf_id] = r;
-        }
-    }
-    return id < map_length ? map[id] : NULL;
-}
-
-static RegisterDefinition * get_reg_by_eh_frame_id(unsigned id) {
-    static RegisterDefinition ** map = NULL;
-    static unsigned map_length = 0;
-
-    if (map == NULL) {
-        RegisterDefinition * r;
-        for (r = get_reg_definitions(NULL); r->name != NULL; r++) {
-            if (r->eh_frame_id >= (int)map_length) map_length = r->eh_frame_id + 1;
-        }
-        map = (RegisterDefinition **)loc_alloc_zero(sizeof(RegisterDefinition *) * map_length);
-        for (r = get_reg_definitions(NULL); r->name != NULL; r++) {
-            if (r->eh_frame_id >= 0) map[r->eh_frame_id] = r;
-        }
-    }
-    return id < map_length ? map[id] : NULL;
-}
-
-RegisterDefinition * get_reg_by_id(Context * ctx, unsigned id, unsigned munbering_convention) {
-    switch (munbering_convention) {
-    case REGNUM_DWARF: return get_reg_by_dwarf_id(id);
-    case REGNUM_EH_FRAME: return get_reg_by_eh_frame_id(id);
-    }
-    return NULL;
-}
-
-int read_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
-    if (reg_def != NULL && frame != NULL) {
-        if (frame->is_top_frame) {
-            return context_read_reg(frame->ctx, reg_def, offs, size, buf);
-        }
-        if (frame->regs != NULL) {
-            size_t i;
-            uint8_t * r_addr = (uint8_t *)&frame->regs->data + reg_def->offset;
-            uint8_t * m_addr = (uint8_t *)&frame->regs->mask + reg_def->offset;
-            for (i = 0; i < size; i++) {
-                if (m_addr[offs + i] != 0xff) {
-                    errno = ERR_INV_CONTEXT;
-                    return -1;
-                }
-            }
-            assert(reg_def->offset + reg_def->size <= sizeof(REG_SET));
-            if (offs + size > reg_def->size) {
-                errno = ERR_INV_DATA_SIZE;
-                return -1;
-            }
-            memcpy(buf, r_addr + offs, size);
-            return 0;
-        }
-    }
-    errno = ERR_INV_CONTEXT;
-    return -1;
-}
-
-int write_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
-    if (reg_def != NULL && frame != NULL) {
-        if (frame->is_top_frame) {
-            return context_write_reg(frame->ctx, reg_def, offs, size, buf);
-        }
-        if (frame->regs == NULL && context_has_state(frame->ctx)) {
-            frame->regs = (RegisterData *)loc_alloc_zero(sizeof(RegisterData));
-        }
-        if (frame->regs != NULL) {
-            uint8_t * r_addr = (uint8_t *)&frame->regs->data + reg_def->offset;
-            uint8_t * m_addr = (uint8_t *)&frame->regs->mask + reg_def->offset;
-
-            assert(reg_def->offset + reg_def->size <= sizeof(REG_SET));
-            if (offs + size > reg_def->size) {
-                errno = ERR_INV_DATA_SIZE;
-                return -1;
-            }
-            memcpy(r_addr + offs, buf, size);
-            memset(m_addr + offs, 0xff, size);
-            return 0;
-        }
-    }
-    errno = ERR_INV_CONTEXT;
-    return -1;
-}
-
-#endif /* !ENABLE_ContextProxy */
+#include <machine/cpudefs-ext.h>
 
 int read_reg_value(StackFrame * frame, RegisterDefinition * reg_def, uint64_t * value) {
     uint8_t buf[8];
diff --git a/framework/cpudefs.h b/framework/cpudefs.h
index d59efb2..a006224 100644
--- a/framework/cpudefs.h
+++ b/framework/cpudefs.h
@@ -134,11 +134,8 @@
 /* Get register for TCF ID */
 extern int id2register(const char * id, Context ** ctx, int * frame, RegisterDefinition ** reg_def);
 
-#if !defined(_WRS_KERNEL)
-extern unsigned char BREAK_INST[];  /* breakpoint instruction */
-#define BREAK_SIZE get_break_size() /* breakpoint instruction size */
-extern size_t get_break_size(void);
-#endif
+/* Get breakpoint instruction code and size */
+extern uint8_t * get_break_instruction(Context * ctx, size_t * size);
 
 /*
  * Retrieve stack frame information by examining stack data in memory.
diff --git a/framework/mdep.h b/framework/mdep.h
index 7db4c21..1e419a5 100644
--- a/framework/mdep.h
+++ b/framework/mdep.h
@@ -454,7 +454,7 @@
 
 #endif
 
-#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__)
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(__VXWORKS__)
 extern size_t strlcpy(char * dst, const char * src, size_t size);
 extern size_t strlcat(char * dst, const char * src, size_t size);
 #endif
diff --git a/machine/cpudefs-ext.h b/machine/cpudefs-ext.h
new file mode 100644
index 0000000..cd33fbe
--- /dev/null
+++ b/machine/cpudefs-ext.h
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 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.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *     Wind River Systems - initial API and implementation
+ *******************************************************************************/
+
+/*
+ * This file provides debug context register definitions and lookup functions.
+ * It is included into cpudefs.c.
+ * The code assumes that all contexts share same register definitions.
+ * If it is not the case, this file needs to be substituted with alternative implementation.
+ */
+
+#include <cpudefs-mdep.h>
+
+struct RegisterData {
+    REG_SET data;
+    REG_SET mask;
+};
+
+RegisterDefinition * get_reg_definitions(Context * ctx) {
+    return regs_index;
+}
+
+uint8_t * get_break_instruction(Context * ctx, size_t * size) {
+    *size = sizeof(BREAK_INST);
+    return BREAK_INST;
+}
+
+static RegisterDefinition * get_reg_by_dwarf_id(unsigned id) {
+    static RegisterDefinition ** map = NULL;
+    static unsigned map_length = 0;
+
+    if (map == NULL) {
+        RegisterDefinition * r;
+        for (r = regs_index; r->name != NULL; r++) {
+            if (r->dwarf_id >= (int)map_length) map_length = r->dwarf_id + 1;
+        }
+        map = (RegisterDefinition **)loc_alloc_zero(sizeof(RegisterDefinition *) * map_length);
+        for (r = regs_index; r->name != NULL; r++) {
+            if (r->dwarf_id >= 0) map[r->dwarf_id] = r;
+        }
+    }
+    return id < map_length ? map[id] : NULL;
+}
+
+static RegisterDefinition * get_reg_by_eh_frame_id(unsigned id) {
+    static RegisterDefinition ** map = NULL;
+    static unsigned map_length = 0;
+
+    if (map == NULL) {
+        RegisterDefinition * r;
+        for (r = regs_index; r->name != NULL; r++) {
+            if (r->eh_frame_id >= (int)map_length) map_length = r->eh_frame_id + 1;
+        }
+        map = (RegisterDefinition **)loc_alloc_zero(sizeof(RegisterDefinition *) * map_length);
+        for (r = regs_index; r->name != NULL; r++) {
+            if (r->eh_frame_id >= 0) map[r->eh_frame_id] = r;
+        }
+    }
+    return id < map_length ? map[id] : NULL;
+}
+
+RegisterDefinition * get_reg_by_id(Context * ctx, unsigned id, unsigned munbering_convention) {
+    switch (munbering_convention) {
+    case REGNUM_DWARF: return get_reg_by_dwarf_id(id);
+    case REGNUM_EH_FRAME: return get_reg_by_eh_frame_id(id);
+    }
+    return NULL;
+}
+
+int read_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
+    if (reg_def != NULL && frame != NULL) {
+        if (frame->is_top_frame) {
+            return context_read_reg(frame->ctx, reg_def, offs, size, buf);
+        }
+        if (frame->regs != NULL) {
+            size_t i;
+            uint8_t * r_addr = (uint8_t *)&frame->regs->data + reg_def->offset;
+            uint8_t * m_addr = (uint8_t *)&frame->regs->mask + reg_def->offset;
+            for (i = 0; i < size; i++) {
+                if (m_addr[offs + i] != 0xff) {
+                    errno = ERR_INV_CONTEXT;
+                    return -1;
+                }
+            }
+            assert(reg_def->offset + reg_def->size <= sizeof(REG_SET));
+            if (offs + size > reg_def->size) {
+                errno = ERR_INV_DATA_SIZE;
+                return -1;
+            }
+            memcpy(buf, r_addr + offs, size);
+            return 0;
+        }
+    }
+    errno = ERR_INV_CONTEXT;
+    return -1;
+}
+
+int write_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
+    if (reg_def != NULL && frame != NULL) {
+        if (frame->is_top_frame) {
+            return context_write_reg(frame->ctx, reg_def, offs, size, buf);
+        }
+        if (frame->regs == NULL && context_has_state(frame->ctx)) {
+            frame->regs = (RegisterData *)loc_alloc_zero(sizeof(RegisterData));
+        }
+        if (frame->regs != NULL) {
+            uint8_t * r_addr = (uint8_t *)&frame->regs->data + reg_def->offset;
+            uint8_t * m_addr = (uint8_t *)&frame->regs->mask + reg_def->offset;
+
+            assert(reg_def->offset + reg_def->size <= sizeof(REG_SET));
+            if (offs + size > reg_def->size) {
+                errno = ERR_INV_DATA_SIZE;
+                return -1;
+            }
+            memcpy(r_addr + offs, buf, size);
+            memset(m_addr + offs, 0xff, size);
+            return 0;
+        }
+    }
+    errno = ERR_INV_CONTEXT;
+    return -1;
+}
diff --git a/server/machine/cpudefs-ext.h b/server/machine/cpudefs-ext.h
new file mode 100644
index 0000000..75aa2f0
--- /dev/null
+++ b/server/machine/cpudefs-ext.h
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 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.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *     Wind River Systems - initial API and implementation
+ *******************************************************************************/
+
+#include <services/context-proxy.h>
+
+RegisterDefinition * get_reg_by_id(Context * ctx, unsigned id, unsigned munbering_convention) {
+    RegisterDefinition * defs = get_reg_definitions(ctx);
+    while (defs != NULL && defs->name != NULL) {
+        switch (munbering_convention) {
+        case REGNUM_DWARF:
+            if (defs->dwarf_id == (int)id) return defs;
+            break;
+        case REGNUM_EH_FRAME:
+            if (defs->eh_frame_id == (int)id) return defs;
+            break;
+        }
+        defs++;
+    }
+    return NULL;
+}
+
+int read_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
+    if (reg_def == NULL || frame == NULL) {
+        errno = ERR_INV_CONTEXT;
+        return -1;
+    }
+    else {
+        size_t i;
+        uint8_t * r_addr = frame->regs->data + reg_def->offset;
+        uint8_t * m_addr = frame->regs->mask + reg_def->offset;
+        for (i = 0; i < size; i++) {
+            if (m_addr[offs + i] != 0xff) {
+                errno = ERR_INV_CONTEXT;
+                return -1;
+            }
+        }
+        if (offs + size > reg_def->size) {
+            errno = ERR_INV_DATA_SIZE;
+            return -1;
+        }
+        memcpy(buf, r_addr + offs, size);
+    }
+    return 0;
+}
+
+int write_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
+    if (reg_def == NULL || frame == NULL) {
+        errno = ERR_INV_CONTEXT;
+        return -1;
+    }
+    else {
+        uint8_t * r_addr = frame->regs->data + reg_def->offset;
+        uint8_t * m_addr = frame->regs->mask + reg_def->offset;
+
+        if (offs + size > reg_def->size) {
+            errno = ERR_INV_DATA_SIZE;
+            return -1;
+        }
+        memcpy(r_addr + offs, buf, size);
+        memset(m_addr + offs, 0xff, size);
+    }
+    return 0;
+}
+
diff --git a/server/server.vcproj b/server/server.vcproj
index 7385113..3cfcd84 100644
--- a/server/server.vcproj
+++ b/server/server.vcproj
@@ -279,14 +279,6 @@
 				>

 			</File>

 			<File

-				RelativePath="..\agent\services\stacktrace.c"

-				>

-			</File>

-			<File

-				RelativePath="..\agent\services\stacktrace.h"

-				>

-			</File>

-			<File

 				RelativePath="..\agent\services\symbols.c"

 				>

 			</File>

@@ -503,6 +495,14 @@
 				>

 			</File>

 		</Filter>

+		<Filter

+			Name="machine"

+			>

+			<File

+				RelativePath=".\machine\cpudefs-ext.h"

+				>

+			</File>

+		</Filter>

 		<File

 			RelativePath=".\config.h"

 			>

diff --git a/server/services/context-proxy.c b/server/services/context-proxy.c
index 8cac229..17ab135 100644
--- a/server/services/context-proxy.c
+++ b/server/services/context-proxy.c
@@ -43,11 +43,6 @@
 
 #define CTX_ID_HASH_SIZE 101
 
-struct RegisterData {
-    uint8_t * data;
-    uint8_t * mask;
-};
-
 struct ContextCache {
     char id[256];
     char parent_id[256];
@@ -1164,25 +1159,6 @@
     return cache->pc_def;
 }
 
-RegisterDefinition * get_reg_by_id(Context * ctx, unsigned id, unsigned munbering_convention) {
-    RegisterDefinition * defs;
-    ContextCache * cache = *EXT(ctx);
-    check_registers_cache(cache);
-    defs = cache->reg_defs;
-    while (defs != NULL && defs->name != NULL) {
-        switch (munbering_convention) {
-        case REGNUM_DWARF:
-            if (defs->dwarf_id == (int)id) return defs;
-            break;
-        case REGNUM_EH_FRAME:
-            if (defs->eh_frame_id == (int)id) return defs;
-            break;
-        }
-        defs++;
-    }
-    return NULL;
-}
-
 static void validate_reg_values_cache(Channel * c, void * args, int error) {
     StackFrameCache * s = (StackFrameCache *)args;
     Context * ctx = s->ctx->ctx;
@@ -1419,49 +1395,6 @@
     return STACK_TOP_FRAME;
 }
 
-int read_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
-    if (reg_def == NULL || frame == NULL) {
-        errno = ERR_INV_CONTEXT;
-        return -1;
-    }
-    else {
-        size_t i;
-        uint8_t * r_addr = frame->regs->data + reg_def->offset;
-        uint8_t * m_addr = frame->regs->mask + reg_def->offset;
-        for (i = 0; i < size; i++) {
-            if (m_addr[offs + i] != 0xff) {
-                errno = ERR_INV_CONTEXT;
-                return -1;
-            }
-        }
-        if (offs + size > reg_def->size) {
-            errno = ERR_INV_DATA_SIZE;
-            return -1;
-        }
-        memcpy(buf, r_addr + offs, size);
-    }
-    return 0;
-}
-
-int write_reg_bytes(StackFrame * frame, RegisterDefinition * reg_def, unsigned offs, unsigned size, uint8_t * buf) {
-    if (reg_def == NULL || frame == NULL) {
-        errno = ERR_INV_CONTEXT;
-        return -1;
-    }
-    else {
-        uint8_t * r_addr = frame->regs->data + reg_def->offset;
-        uint8_t * m_addr = frame->regs->mask + reg_def->offset;
-
-        if (offs + size > reg_def->size) {
-            errno = ERR_INV_DATA_SIZE;
-            return -1;
-        }
-        memcpy(r_addr + offs, buf, size);
-        memset(m_addr + offs, 0xff, size);
-    }
-    return 0;
-}
-
 static void channel_close_listener(Channel * c) {
     LINK * l = NULL;
 
diff --git a/server/services/context-proxy.h b/server/services/context-proxy.h
index fcd9f00..c1abfa5 100644
--- a/server/services/context-proxy.h
+++ b/server/services/context-proxy.h
@@ -22,6 +22,11 @@
 #include <config.h>
 #include <framework/channel.h>
 
+struct RegisterData {
+    uint8_t * data;
+    uint8_t * mask;
+};
+
 extern void create_context_proxy(Channel * host, Channel * target);
 
 #endif /* D_context_proxy */
diff --git a/services/breakpoints.c b/services/breakpoints.c
index 4c7bdcb..7fc8f23 100644
--- a/services/breakpoints.c
+++ b/services/breakpoints.c
@@ -110,6 +110,7 @@
     VXDBG_BP_ID vxdbg_id;
 #else
     char saved_code[16];
+    size_t saved_size;
 #endif
     ErrorReport * error;
     int stepping_over_bp;
@@ -240,16 +241,17 @@
         assert(bi->error != NULL);
     }
 #else
-    assert(sizeof(bi->saved_code) >= BREAK_SIZE);
     if (select_valid_context(&bi->ctx) < 0) {
         bi->error = get_error_report(errno);
     }
     else {
+        uint8_t * break_inst = get_break_instruction(bi->ctx, &bi->saved_size);
+        assert(sizeof(bi->saved_code) >= bi->saved_size);
         planting_instruction = 1;
-        if (context_read_mem(bi->ctx, bi->address, bi->saved_code, BREAK_SIZE) < 0) {
+        if (context_read_mem(bi->ctx, bi->address, bi->saved_code, bi->saved_size) < 0) {
             bi->error = get_error_report(errno);
         }
-        else if (context_write_mem(bi->ctx, bi->address, &BREAK_INST, BREAK_SIZE) < 0) {
+        else if (context_write_mem(bi->ctx, bi->address, break_inst, bi->saved_size) < 0) {
             bi->error = get_error_report(errno);
         }
         planting_instruction = 0;
@@ -288,7 +290,7 @@
 #else
     if (select_valid_context(&bi->ctx) == 0) {
         planting_instruction = 1;
-        if (context_write_mem(bi->ctx, bi->address, bi->saved_code, BREAK_SIZE) < 0) {
+        if (context_write_mem(bi->ctx, bi->address, bi->saved_code, bi->saved_size) < 0) {
             bi->error = get_error_report(errno);
         }
         planting_instruction = 0;
@@ -363,7 +365,7 @@
 void check_breakpoints_on_memory_read(Context * ctx, ContextAddress address, void * p, size_t size) {
 #if !defined(_WRS_KERNEL)
     if (!planting_instruction) {
-        int i;
+        size_t i;
         char * buf = (char *)p;
         LINK * l = instructions.next;
         while (l != &instructions) {
@@ -371,9 +373,9 @@
             l = l->next;
             if (!bi->planted) continue;
             if (bi->ctx->mem != ctx->mem) continue;
-            if (bi->address + BREAK_SIZE <= address) continue;
+            if (bi->address + bi->saved_size <= address) continue;
             if (bi->address >= address + size) continue;
-            for (i = 0; i < (int)BREAK_SIZE; i++) {
+            for (i = 0; i < bi->saved_size; i++) {
                 if (bi->address + i < address) continue;
                 if (bi->address + i >= address + size) continue;
                 buf[bi->address + i - address] = bi->saved_code[i];
@@ -386,7 +388,6 @@
 void check_breakpoints_on_memory_write(Context * ctx, ContextAddress address, void * p, size_t size) {
 #if !defined(_WRS_KERNEL)
     if (!planting_instruction) {
-        int i;
         char * buf = (char *)p;
         LINK * l = instructions.next;
         while (l != &instructions) {
@@ -394,13 +395,18 @@
             l = l->next;
             if (!bi->planted) continue;
             if (bi->ctx->mem != ctx->mem) continue;
-            if (bi->address + BREAK_SIZE <= address) continue;
+            if (bi->address + bi->saved_size <= address) continue;
             if (bi->address >= address + size) continue;
-            for (i = 0; i < (int)BREAK_SIZE; i++) {
-                if (bi->address + i < address) continue;
-                if (bi->address + i >= address + size) continue;
-                bi->saved_code[i] = buf[bi->address + i - address];
-                buf[bi->address + i - address] = BREAK_INST[i];
+            {
+                size_t i;
+                uint8_t * break_inst = get_break_instruction(bi->ctx, &i);
+                assert(i == bi->saved_size);
+                for (i = 0; i < bi->saved_size; i++) {
+                    if (bi->address + i < address) continue;
+                    if (bi->address + i >= address + size) continue;
+                    bi->saved_code[i] = buf[bi->address + i - address];
+                    buf[bi->address + i - address] = break_inst[i];
+                }
             }
         }
     }
diff --git a/services/diagnostics.c b/services/diagnostics.c
index 65a6365..9c967f7 100644
--- a/services/diagnostics.c
+++ b/services/diagnostics.c
@@ -29,7 +29,6 @@
 #include <framework/cache.h>
 #if ENABLE_Symbols
 #  include <services/symbols.h>
-#  include <services/stacktrace.h>
 #endif
 #if SERVICE_Streams
 #  include <services/streamsservice.h>
diff --git a/services/dwarfframe.h b/services/dwarfframe.h
index c8d75fb..206fe50 100644
--- a/services/dwarfframe.h
+++ b/services/dwarfframe.h
@@ -27,7 +27,6 @@
 
 #include <framework/context.h>
 #include <services/dwarfcache.h>
-#include <services/stacktrace.h>
 
 /*
  * Lookup stack tracing information in ELF file, in .debug_frame and .eh_frame sections.
diff --git a/system/Darwin/context-darwin.c b/system/Darwin/context-darwin.c
index d29aecf..04c21ac 100644
--- a/system/Darwin/context-darwin.c
+++ b/system/Darwin/context-darwin.c
@@ -554,15 +554,16 @@
         }
 
         if (signal == SIGTRAP && event == 0 && !syscall) {
-            ctx->stopped_by_bp = !EXT(ctx)->regs_error &&
-                is_breakpoint_address(ctx, pc1 - BREAK_SIZE);
+            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);
             EXT(ctx)->end_of_step = !ctx->stopped_by_bp && ctx->pending_step;
+            if (ctx->stopped_by_bp) {
+                set_regs_PC(ctx, pc1 - break_size);
+                EXT(ctx)->regs_dirty = 1;
+            }
         }
         ctx->pending_step = 0;
-        if (ctx->stopped_by_bp) {
-            set_regs_PC(ctx, pc1 - BREAK_SIZE);
-            EXT(ctx)->regs_dirty = 1;
-        }
         send_context_stopped_event(ctx);
     }
 }
diff --git a/system/FreeBSD/context-freebsd.c b/system/FreeBSD/context-freebsd.c
index 299375c..a53b66d 100644
--- a/system/FreeBSD/context-freebsd.c
+++ b/system/FreeBSD/context-freebsd.c
@@ -553,15 +553,16 @@
         }
 
         if (signal == SIGTRAP && event == 0 && !syscall) {
-            ctx->stopped_by_bp = !EXT(ctx)->regs_error &&
-                is_breakpoint_address(ctx, pc1 - BREAK_SIZE);
+            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);
             EXT(ctx)->end_of_step = !ctx->stopped_by_bp && ctx->pending_step;
+            if (ctx->stopped_by_bp) {
+                set_regs_PC(ctx, pc1 - break_size);
+                EXT(ctx)->regs_dirty = 1;
+            }
         }
         ctx->pending_step = 0;
-        if (ctx->stopped_by_bp) {
-            set_regs_PC(ctx, pc1 - BREAK_SIZE);
-            EXT(ctx)->regs_dirty = 1;
-        }
         send_context_stopped_event(ctx);
     }
 }
diff --git a/system/GNU/Linux/context-linux.c b/system/GNU/Linux/context-linux.c
index ecb6957..fc5ce8c 100644
--- a/system/GNU/Linux/context-linux.c
+++ b/system/GNU/Linux/context-linux.c
@@ -735,14 +735,16 @@
         }
 
         if (signal == SIGTRAP && event == 0 && !syscall) {
-            ctx->stopped_by_bp = !EXT(ctx)->regs_error && is_breakpoint_address(ctx, pc1 - BREAK_SIZE);
+            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);
             EXT(ctx)->end_of_step = !ctx->stopped_by_bp && ctx->pending_step;
+            if (ctx->stopped_by_bp) {
+                set_regs_PC(ctx, pc1 - break_size);
+                EXT(ctx)->regs_dirty = 1;
+            }
         }
         ctx->pending_step = 0;
-        if (ctx->stopped_by_bp) {
-            set_regs_PC(ctx, pc1 - BREAK_SIZE);
-            EXT(ctx)->regs_dirty = 1;
-        }
         send_context_stopped_event(ctx);
     }
 }
diff --git a/system/Windows/context-win32.c b/system/Windows/context-win32.c
index 5b80a89..a87067a 100644
--- a/system/Windows/context-win32.c
+++ b/system/Windows/context-win32.c
@@ -164,6 +164,7 @@
 static void event_win32_context_stopped(Context * ctx) {
     ContextExtensionWin32 * ext = EXT(ctx);
     DWORD exception_code = ext->pending_event.ExceptionRecord.ExceptionCode;
+    size_t break_size = 0;
 
     if (ctx->exited || ctx->stopped && exception_code == 0) return;
     memcpy(&ext->suspend_reason, &ext->pending_event, sizeof(EXCEPTION_DEBUG_INFO));
@@ -205,9 +206,10 @@
     case EXCEPTION_SINGLE_STEP:
         break;
     case EXCEPTION_BREAKPOINT:
+        get_break_instruction(ctx, &break_size);
         get_registers(ctx);
-        if (!ext->regs_error && is_breakpoint_address(ctx, ext->regs->Eip - BREAK_SIZE)) {
-            ext->regs->Eip -= BREAK_SIZE;
+        if (!ext->regs_error && is_breakpoint_address(ctx, ext->regs->Eip - break_size)) {
+            ext->regs->Eip -= break_size;
             ext->regs_dirty = 1;
             ctx->stopped_by_bp = 1;
         }