adamgreen / mri

MRI - Monitor for Remote Inspection. The gdb compatible debug monitor for Cortex-M devices.
Apache License 2.0
151 stars 55 forks source link

Use macros to control whether hardware breakpoints are enforced #39

Closed anjiahao1 closed 1 year ago

anjiahao1 commented 1 year ago

Signed-off-by: anjiahao anjiahao@xiaomi.com

adamgreen commented 1 year ago

I have no idea what this is about.

anjiahao1 commented 1 year ago

In this way, we can use hardware breakpoints uniformly without marking which address is flash or ram. The problem I'm having is that I have many borads with different flash addresses and I don't want each borad to tag it's flash address.

adamgreen commented 1 year ago

Rather than placing an #ifdef in the middle of a switch could you do something like this instead?

diff --git a/Makefile b/Makefile
index efc52f5..06efe5e 100644
--- a/Makefile
+++ b/Makefile
@@ -71,15 +71,16 @@ endif
 # Flags to use when cross-compiling ARMv7-M binaries.
 ARMV7M_GCCFLAGS := -Os -g3 -mthumb -mthumb-interwork -Wall -Wextra -Werror -Wno-unused-parameter -MMD -MP
 ARMV7M_GCCFLAGS += -ffunction-sections -fdata-sections -fno-exceptions -fno-delete-null-pointer-checks -fomit-frame-pointer
-ARMV7M_GCCFLAGS += -DMRI_THREAD_MRI=0
+ARMV7M_GCCFLAGS += -DMRI_THREAD_MRI=0 -DMRI_ALWAYS_USE_HARDWARE_BREAKPOINT=0
 ARMV7M_GPPFLAGS := $(ARMV7M_GCCFLAGS) -fno-rtti
 ARMV7M_GCCFLAGS += -std=gnu90
 ARMV7M_ASFLAGS  := -mthumb -g3 -x assembler-with-cpp -MMD -MP

 # Flags to use when compiling binaries to run on this host system.
 HOST_GCCFLAGS := -O2 -g3 -Wall -Wextra -Werror -Wno-unused-parameter -MMD -MP
-HOST_GCCFLAGS += -ffunction-sections -fdata-sections -fno-common -DMRI_THREAD_MRI=0
+HOST_GCCFLAGS += -ffunction-sections -fdata-sections -fno-common
 HOST_GCCFLAGS += -include CppUTest/include/CppUTest/MemoryLeakDetectorMallocMacros.h
+HOST_GCCFLAGS += -DMRI_THREAD_MRI=0 -DMRI_ALWAYS_USE_HARDWARE_BREAKPOINT=0
 HOST_GPPFLAGS := $(HOST_GCCFLAGS) -include CppUTest/include/CppUTest/MemoryLeakDetectorNewMacros.h
 HOST_GCCFLAGS += -std=gnu90
 HOST_ASFLAGS  := -g -x assembler-with-cpp -MMD -MP
diff --git a/core/cmd_break_watch.c b/core/cmd_break_watch.c
index 2862e6a..6a6f783 100644
--- a/core/cmd_break_watch.c
+++ b/core/cmd_break_watch.c
@@ -91,6 +91,12 @@ static void parseBreakpointWatchpointCommandArguments(BreakpointWatchpointArgume
         __throwing_func( pArguments->address = ReadUIntegerArgument(pBuffer) );
         __throwing_func( ThrowIfNextCharIsNotEqualTo(pBuffer, ',') );
         __throwing_func( pArguments->kind = ReadUIntegerArgument(pBuffer) );
+        if (MRI_ALWAYS_USE_HARDWARE_BREAKPOINT && pArguments->type == '0')
+        {
+            /* Assume soft breakpoint is really for FLASH on platforms that don't describe memory layout in XML. */
+            pArguments->type = '1';
+        }
+
     }
     __catch
     {
adamgreen commented 1 year ago

I applied my alternative patch in commit b0287e6