target: add debug_reason_name()
authorDavid Brownell <dbrownell@users.sourceforge.net>
Mon, 7 Dec 2009 22:55:08 +0000 (14:55 -0800)
committerDavid Brownell <dbrownell@users.sourceforge.net>
Mon, 7 Dec 2009 22:57:44 +0000 (14:57 -0800)
Provide and use debug_reason_name() instead of expecting targets
to call Jim_Nvp_value2name_simple().  Less dependency on Jim, and
the code becomes more clear too.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
src/target/armv4_5.c
src/target/armv7m.c
src/target/mips32.c
src/target/target.c
src/target/target.h

index dce6d6a638136721642997c3d893e2d0e488bc25..1c4923b9d20d5ee88650e519e61008ea81a7e498 100644 (file)
@@ -595,8 +595,7 @@ int arm_arch_state(struct target *target)
        LOG_USER("target halted in %s state due to %s, current mode: %s\n"
                        "cpsr: 0x%8.8" PRIx32 " pc: 0x%8.8" PRIx32 "%s",
                        arm_state_strings[armv4_5->core_state],
-                       Jim_Nvp_value2name_simple(nvp_target_debug_reason,
-                                       target->debug_reason)->name,
+                       debug_reason_name(target),
                        arm_mode_name(armv4_5->core_mode),
                        buf_get_u32(armv4_5->cpsr->value, 0, 32),
                        buf_get_u32(armv4_5->core_cache->reg_list[15].value,
index fc3f47ccdb46e6f58b95e9223198622b972ad29d..d4f6309ff6f021cbfe5a882583a95c21f78dc91b 100644 (file)
@@ -480,8 +480,7 @@ int armv7m_arch_state(struct target *target)
 
        LOG_USER("target halted due to %s, current mode: %s %s\n"
                "xPSR: %#8.8" PRIx32 " pc: %#8.8" PRIx32 " %csp: %#8.8" PRIx32,
-               Jim_Nvp_value2name_simple(nvp_target_debug_reason,
-                               target->debug_reason)->name,
+               debug_reason_name(target),
                armv7m_mode_strings[armv7m->core_mode],
                armv7m_exception_string(armv7m->exception_number),
                buf_get_u32(armv7m->core_cache->reg_list[ARMV7M_xPSR].value, 0, 32),
index 48d072021c3683b47710212b20cb014d2dc5ca41..e8ea541a5a918b91fe33721c38bf71018bbc2e14 100644 (file)
@@ -254,7 +254,7 @@ int mips32_arch_state(struct target *target)
        }
 
        LOG_USER("target halted due to %s, pc: 0x%8.8" PRIx32 "",
-               Jim_Nvp_value2name_simple(nvp_target_debug_reason, target->debug_reason)->name ,
+               debug_reason_name(target),
                buf_get_u32(mips32->core_cache->reg_list[MIPS32_PC].value, 0, 32));
 
        return ERROR_OK;
index 597046faa97b4cfc2fb8db9aaf543642924184d0..f249d380a7637312795f25d94ef48332d90b04e0 100644 (file)
@@ -187,7 +187,7 @@ const Jim_Nvp nvp_target_state[] = {
        { .name = NULL, .value = -1 },
 };
 
-const Jim_Nvp nvp_target_debug_reason [] = {
+static const Jim_Nvp nvp_target_debug_reason [] = {
        { .name = "debug-request"            , .value = DBG_REASON_DBGRQ },
        { .name = "breakpoint"               , .value = DBG_REASON_BREAKPOINT },
        { .name = "watchpoint"               , .value = DBG_REASON_WATCHPOINT },
@@ -214,6 +214,19 @@ const Jim_Nvp nvp_reset_modes[] = {
        { .name = NULL     , .value = -1 },
 };
 
+const char *debug_reason_name(struct target *t)
+{
+       const char *cp;
+
+       cp = Jim_Nvp_value2name_simple(nvp_target_debug_reason,
+                       t->debug_reason)->name;
+       if (!cp) {
+               LOG_ERROR("Invalid debug reason: %d", (int)(t->debug_reason));
+               cp = "(*BUG*unknown*BUG*)";
+       }
+       return cp;
+}
+
 const char *
 target_state_name( struct target *t )
 {
index 73190695427780d5fe38221e4ef23ad94cceb55d..dd3d4f7f5f2b0dcb9b74022ac2eb728dcdb3cecb 100644 (file)
@@ -91,8 +91,6 @@ enum target_debug_reason
        DBG_REASON_UNDEFINED = 6
 };
 
-extern const Jim_Nvp nvp_target_debug_reason[];
-
 enum target_endianess
 {
        TARGET_ENDIAN_UNKNOWN = 0,
@@ -165,6 +163,8 @@ static inline const char *target_name(struct target *target)
        return target->cmd_name;
 }
 
+const char *debug_reason_name(struct target *t);
+
 enum target_event
 {
        /* LD historical names